x402 icon indicating copy to clipboard operation
x402 copied to clipboard

feat(ecosystem): add x402-anthropic (TypeScript + Python)

Open kinance opened this issue 6 months ago • 3 comments

Summary

Adds two ecosystem entries for x402-anthropic — client-side payment transports for the Anthropic SDK.

Both wrap the standard Anthropic client so HTTP 402 responses are automatically paid with USDC on EVM (Base, Ethereum) or SVM (Solana). Zero code changes needed beyond swapping the client class.

Category: Client-Side Integrations

kinance avatar May 27 '26 13:05 kinance

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

cb-heimdall avatar May 27 '26 13:05 cb-heimdall

Did a quick public/code-only readiness pass on the two linked packages before this is listed as a client-side integration. I did not run wallet signing, payment headers, paid calls, or private endpoints.

What looks good:

  • Both packages keep the integration narrow: Anthropic SDK wrapper + x402 transport.
  • The Python transport has a useful single-retry behavior for repeated 402s, so it does not loop indefinitely.
  • The TypeScript wrapper lazily initializes the x402 client, which is a good shape for normal SDK usage.

Patch notes I would address before/around listing:

  • P1: TypeScript maxAmount() looks like it fails open. In src/policies.ts, if all payment requirements are above the cap, affordable.length is 0 and the policy returns the original reqs, so the later client can still pay above the documented cap. The README says maxAmount(1_000_000n) is "max $1 USDC" / skip above cap, so this should return [] or otherwise block when nothing is affordable.
  • P1: Python README documents policies=[preferNetwork(...), maxAmount(...)], but x402_anthropic/_client.py does not accept or register policies; policies would be forwarded as a normal Anthropic kwarg instead of enforced by x402. For an auto-paying Anthropic wrapper, the cap example needs to be implemented or removed before users rely on it.
  • P2: The ecosystem description says "automatically paid with USDC" and "zero code changes". For a wallet-spending SDK, I would add one explicit safety sentence to the package READMEs and/or ecosystem copy: use a restricted wallet and a real max-amount policy before pointing this at an arbitrary gateway.

I tried local tests but the cloned repos did not have dev deps installed in this environment (vitest / pytest missing), so the above is static source/readme review only.

TateLyman avatar May 27 '26 16:05 TateLyman

Thanks for the detailed review @TateLyman — all three items addressed:

P1: TypeScript maxAmount fails open — fixed. maxAmount() now returns affordable directly (empty array when nothing is affordable), so payments above the cap are blocked rather than allowed through. commit

P1: Python policies param not wired — fixed. Both X402Anthropic and AsyncX402Anthropic now accept policies: list | None = None and pass them to wallet.build_sync() / build_async(), which calls x402ClientSync.register_policy() for each. Also corrected the README examples from preferNetwork/maxAmount (JS names) to prefer_network/max_amount (Python x402 library names). commit

P2: Safety note — added to both READMEs: "use a dedicated wallet with limited funds and always set a maxAmount/max_amount policy before pointing this at an untrusted gateway."

kinance avatar May 28 '26 00:05 kinance