Installation
The SDK is published on PyPI ascred-protocol and needs Python 3.10 or later.
[...] as a filename pattern and fails with no matches found. The same commands work with uv (uv add "cred-protocol[x402]") and Poetry (poetry add "cred-protocol[x402]").
Quick Start
Evaluate Options
Using a Policy Template
Using Custom Gates
With Dynamic Pricing
TrustResult Fields
Error Handling
FastAPI Integration
Therequire_trust() dependency gates endpoints with a single line:
FastAPI Configuration
Wallet Extraction
The FastAPI dependency checks (in order):X-Wallet-Addressrequest header?wallet=query parameter
Failure Responses
Screen x402 payers (Know Your Agent)
If you sell over x402 with the Pythonx402 package (v2), one call screens every paying agent with Know Your Agent before its payment settles:
x402ResourceServer (async hooks) and x402ResourceServerSync (blocking hooks), and picks the right one for the server it is given.
- Verify, then screen. The facilitator verifies the payment first, so only a payer who really signed it is looked up.
- Refusal. If your policy refuses the payer, the payment is aborted before settlement and no funds move. The payer gets a
402whoseerrorispayer_sanctioned,payer_needs_review,payer_not_registered_agentorpayer_screening_unavailable. The TypeScript page explains when each is sent. - Every payment flow. The default
authorizationflow is screened after verify. Theupfrontandescrowflows, which settle without a verify step, are screened just before that early settle.
Where the check runs
The hooksregister_cred_kya installs run between the facilitator’s verify and settle. Refusals never settle, so no funds move.
Policy
- Cost. A KYA lookup costs 10 Cred Units; a wallet with no agent is a free 404, then a 1 CU screen.
- Caching. Decisions are cached per payer: 15 minutes, or 1 hour for a sanctions refusal. An incomplete check (K13) is never cached.
- Fail open, but not past sanctions. With
on_error="accept"the hook still runs the fast OFAC screen and refuses a sanctioned payer. It accepts unchecked only if that screen fails too. - Never raises. x402 re-raises a hook’s exception and fails the request, so the hooks turn every failure into an explicit accept or refuse.
- Async server. Concurrent payments from one payer share a lookup. A lookup that runs past
timeoutkeeps going in the background, so the payer’s next payment gets the full answer. - Sync server.
timeoutbounds the HTTP call itself, and a timed-out payer is looked up again on their next payment.
CredKyaClient (async) and CredKyaClientSync expose the same calls directly: kya_by_wallet, kya_by_agent_id and sanctions_screen.
Choosing a policy
Using Without FastAPI
The coreCredClient works with any async Python code: