Skip to content

Example: CrewAI pre-pay check of an x402 endpoint - #7

Open
TechCodinz wants to merge 2 commits into
agent402-dev:mainfrom
TechCodinz:crewai-prepay-check
Open

TechCodinz wants to merge 2 commits into
agent402-dev:mainfrom
TechCodinz:crewai-prepay-check

Conversation

@TechCodinz

Copy link
Copy Markdown

/claim #2

Add a runnable CrewAI example that checks an x402 paid endpoint before anything pays for it.

What it does

  • examples/crewai-prepay-check/tool.py — a CrewAI custom tool that runs npx -y @agent402-dev/pay-server check <url> --json and returns the JSON to the agent (fields fixes, findings, amounts). One request, no payment header, nothing signed or paid, no key read.
  • examples/crewai-prepay-check/main.py — a CrewAI agent whose instructions say: do not pay when fixes > 0. Refuses non-https URLs before running the check (loopback http allowed only so the local demo server can be checked).
  • examples/crewai-prepay-check/broken_server.py — a ~20-line local server answering a broken 402, for the will-not-pay demo.
  • examples/crewai-prepay-check/requirements.txt — pinned crewai[google-genai]==1.15.50; README.md — install, run, what the tool returns, "nothing is paid" line.

Verified (real runs, no keys spent)

  • python main.py https://api.xynaptic.io/v1/crypto-price → fixes: 0, price 0.02 USDC, signedOrPaid: false, exit 0.
  • Against the local broken 402 → fixes: 1 (header_missing), agent will not pay.
  • python main.py http://example.com/... → refused before any check runs (verified no npx invocation).
  • LLM: OPENAI_API_KEY (default) or GEMINI_API_KEY (gemini/gemini-2.5-flash, wired via llm=). No wallet, key, RPC or paid API key needed otherwise. Note: the full agent kickoff was verified by code review + model-resolution probe only — no real LLM key was available in the build environment, so the agent's spoken answer was not exercised end to end; the check-tool paths above were run for real.

Notes

  • /try could not be posted on the issue from the API (the token used returns 403 on issue comments for this repo); work started 2026-12-05 ~09:50 UTC.
  • Nothing outside examples/crewai-prepay-check/ is touched — no payment code, rules, keys, wallets or signing.

run_with_agent never passed llm=, so a Gemini-only user got CrewAI's
OpenAI default despite the README promising Gemini support. Select
LLM(model="gemini/gemini-2.5-flash") when GEMINI_API_KEY is set and
OPENAI_API_KEY is not; otherwise leave CrewAI's default untouched.
Also pins the google-genai extra (crewai[google-genai]) so the native
Gemini provider is installed, and names the model in the README.
@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