Skip to content

examples: CrewAI agent checks an x402 endpoint before paying - #12

Open
riccardocens-code wants to merge 1 commit into
agent402-dev:mainfrom
riccardocens-code:examples/crewai-prepay-check-2
Open

riccardocens-code wants to merge 1 commit into
agent402-dev:mainfrom
riccardocens-code:examples/crewai-prepay-check-2

Conversation

@riccardocens-code

Copy link
Copy Markdown

/claim #2

Adds examples/crewai-prepay-check/, a runnable CrewAI example that checks an x402 endpoint before anything pays it.

What it does

  • tool.py: Check402Tool, a CrewAI BaseTool that runs npx -y @agent402-dev/pay-server@0.15.0 check <url> --json and returns the CLI's JSON (url, fixes, findings with the price findings, signedOrPaid) to the agent. One request without a payment header; nothing signed or paid, no key read.
  • Non-https URLs are refused before the CLI is started. As in the CLI, plain http is accepted only on localhost / 127.0.0.1 so the local test server can be checked.
  • npx runs from the temp dir, not the example dir, so inside this repo it doesn't resolve the unbuilt workspace @agent402-dev/pay-server (that fails with agent402-pay-server: not found).
  • main.py: the agent and task. The instructions say: do not pay when fixes > 0. The model is set with MODEL (default gemini/gemini-3.5-flash-lite).
  • broken_402_server.py: a 20-line stdlib server that answers 402 with a PAYMENT-REQUIRED header that is not base64 JSON.
  • test_tool.py: unit test (no LLM key, no npx) showing refused URLs never start the CLI.
  • requirements.txt pins crewai[google-genai]==1.15.50 and google-genai==1.65.0.

Run by me (crewai 1.15.50, google-genai 1.65.0, model gemini/gemini-3.5-flash-lite, Python 3.12.16, Node 24.22.1, npm 11.21.1, pay-server 0.15.0):

Live endpoint: python main.py "https://agent402-check402.agent402-ebc.workers.dev/x402/check402?url=https://example.com"

price: Solana mainnet, 0.01 USDC (amount "10000"); Base, 0.01 USDC (amount "10000")
fixes: 0
fix findings: none
decision: will pay. The endpoint has 0 fixes and can be successfully paid by a paying client.

Local broken 402: python broken_402_server.py & python main.py http://127.0.0.1:4021/paid

ERROR:root:Google Gemini API error: 503 - This model is currently experiencing high demand. Spikes in demand are usually temporary. Please try again later.
ERROR:crewai.flow.runtime:Error executing listener call_llm_native_tools: 503 UNAVAILABLE. {'error': {'code': 503, 'message': 'This model is currently experiencing high demand. Spikes in demand are usually temporary. Please try again later.', 'status': 'UNAVAILABLE'}}
price: none found (endpoint returned header_undecodable error)
fixes: 1
fix findings: [
  {
    "code": "header_undecodable",
    "level": "fix",
    "message": "PAYMENT-REQUIRED is not base64 JSON that @x402/core can decode."
  }
]
decision: will not pay because fixes > 0 (specifically, the endpoint has configuration/header decoding issues).

Non-https: python main.py http://example.com/paid → the tool refuses without starting the CLI, and the agent answers "decision: will not pay".

python -m unittest test_tool.py → 2 tests OK.

No payment code, rules, keys, wallets or signing are touched; the change is only the new example folder.

@opirebot

opirebot Bot commented Dec 5, 2026

Copy link
Copy Markdown

👀 We've notified the reward creators here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant