Skip to main content

Installation

The SDK is published on PyPI as cred-protocol and needs Python 3.10 or later.
Quote the package name when it has an extra in brackets: zsh, the default shell on macOS, otherwise treats [...] 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

The require_trust() dependency gates endpoints with a single line:

FastAPI Configuration

Wallet Extraction

The FastAPI dependency checks (in order):
  1. X-Wallet-Address request header
  2. ?wallet= query parameter
Override with a custom extractor:

Failure Responses

Screen x402 payers (Know Your Agent)

If you sell over x402 with the Python x402 package (v2), one call screens every paying agent with Know Your Agent before its payment settles:
It works with both 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 402 whose error is payer_sanctioned, payer_needs_review, payer_not_registered_agent or payer_screening_unavailable. The TypeScript page explains when each is sent.
  • Every payment flow. The default authorization flow is screened after verify. The upfront and escrow flows, which settle without a verify step, are screened just before that early settle.

Where the check runs

The hooks register_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 timeout keeps going in the background, so the payer’s next payment gets the full answer.
  • Sync server. timeout bounds 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 core CredClient works with any async Python code: