Skip to main content

tryx402 — the OpenRouter for agent payments

A safe, provider-agnostic wrapper over AgentCash / x402. Not limited to prospecting — it drives any endpoint, and adds what AgentCash itself lacks and we learned we need the hard way:

  • hard budget caps — stop before overspending
  • idempotency — never pay twice for the same call (the $0.83 double-charge lesson)
  • cost ledger — USD spent, reconciled, grouped by origin / account

Open core, closed engine

This repo is the open-source SDK: the safe caller, budget guard, idempotency, ledger, CLI and MCP server. MIT licensed.

The hosted service (https://www.tryx402.app) is the commercial engine: multi-currency fiat billing, margins, FX, Stripe funding, the verified-tools catalogue and the provider portal. Pricing is decided server-side via /v1/quote — a client-side margin is a margin nobody pays.

Face Who Where
Power-tool you / an agent drive paid endpoints safely this SDK (gateway.cli, gateway.client)
Fiat gateway end users pay in their currency, you resell x402 with margin hosted service (closed)

Embed it (for agents)

Python — one import:

from gateway import Gateway
gw = Gateway(max_budget_usd=1.0)               # safe by default
data = gw.call("https://stable-deepline.dev/api/email/validate",
               body={"email": "x@y.com"}, price=0.03)
print(gw.spent_usd)                            # 0.03

Terminal — one command (like agentcash), after pip install tryx402:

gateway call https://stable-deepline.dev/api/email/validate \
  --body '{"email":"x@y.com"}' --price 0.03 --max-budget 0.10

MCP — the agent-native form (like AgentCash's own MCP, zero dependencies):

{
  "command": "python3",
  "args": ["-m", "gateway.mcp_server"],
  "env": { "GATEWAY_MAX_BUDGET_USD": "1.00" }
}

The agent gets four tools — gateway_search, gateway_discover, gateway_call (budget-capped, idempotent), gateway_spent — sharing one session-wide budget and cost ledger across every call.

Layout

gateway/
├── client.py    # SafeClient: any endpoint + budget + idempotency + timeout + ledger
├── ledger.py    # cost events, USD/EUR totals, by-origin
├── catalog.py   # search(intent) / discover(origin) over the AgentCash catalogue
├── api.py       # Gateway facade: one-import embed + quote() for server pricing
├── cli.py       # search / discover / call / quote
└── tests/       # offline: budget, idempotency, on_paid hook, quote client

Use

Discover (free — no payment):

python3 -m gateway.cli search "find work email"
python3 -m gateway.cli discover https://stable-deepline.dev

Call any endpoint safely (spends USDC — budget-capped, idempotent):

python3 -m gateway.cli call https://stable-deepline.dev/api/email/validate \
  --body '{"email":"foo@bar.com"}' --price 0.03 --max-budget 0.10

Ask the hosted service what a call costs your account (server-side FX + margin):

export TRYX402_API_KEY="gw_..."        # from https://www.tryx402.app
gateway quote 0.04
#  -> {"account":"acme","currency":"EUR","charge_minor":5,"charge":"0.05 EUR"}

What's real vs hosted

  • Real (this SDK): the safe caller, budget cap, idempotency, cost ledger, catalogue search/discover.
  • Hosted: accounts, balances, fiat funding (Stripe), FX conversion, margins — all decided by the server; the SDK only asks with quote().
  • Deliberately off: auto-retry of paid calls (default max_retries=0) — retrying a possibly-paid call is what double-charged us; opt in only if the server honors the Idempotency-Key header.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tryx402-0.2.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tryx402-0.2.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

Details for the file tryx402-0.2.0.tar.gz.

File metadata

  • Download URL: tryx402-0.2.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tryx402-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4ecab64a4cc5b0c8cc52435de56996e181442f9f2f65937ab2c3461452b6c13c
MD5 233d7914d2a08bf62f35051f00ab24e7
BLAKE2b-256 b634aca30d237fc45dbcb5eda2ef902f02827ecf676c0b6b0768abfd2b081c2c

See more details on using hashes here.

File details

Details for the file tryx402-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tryx402-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tryx402-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a80620f5364f54de8f455c6f7fe2c2891e61a468695b6fe1c502729f01c76938
MD5 f350cd4396be44b8621bd248cc556567
BLAKE2b-256 c875d54721fe73590b46b3e9a4d5d82bd0ac2e2b75ce2086569d199fec2d583c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.1

1 file

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page