Phase Router
One endpoint connects AI agents to leading AI models, routing each request to the best balance of quality, speed and cost. No separate subscriptions, accounts, API keys or lock-in.
What x402 is, in five lines
You call the OpenAI-compatible API without any key.
For a paid model the gateway answers 402 Payment Required with a quote: the price ceiling for this request, the price per 1M tokens and a task id.
Your wallet signs a one-time USDT authorization for that ceiling (EIP-712 typed data — no transaction, no gas on your side).
The request is retried with the signature in PAYMENT-SIGNATURE; the gateway runs it and streams the answer.
After the answer the gateway settles the actual amount (tokens used + the per-call fee, never above the ceiling); the phase object in the response carries the price, payment status and tx hash.
Call a model
The examples call a paid model through the Phase SDKs.
# A paid model answers 402 with the quote (ceiling, price per 1M, task id);
# sign it with an SDK below — or look at the quote first:
curl -s -i -X POST https://<gateway>/v1/chat/completions -H 'content-type: application/json' \
-d '{"model":"gpt-oss-120b","messages":[{"role":"user","content":"hello world"}]}'
# The catalog with prices (no payment):
curl -s https://<gateway>/v1/models
import os
from openai import OpenAI
from phase_x402 import paying_http_client
client = OpenAI(
base_url="https://<gateway>/v1",
api_key="x402", # ignored by the gateway; the wallet is the identity
http_client=paying_http_client(private_key=os.environ["PHASE_WALLET_KEY"], max_amount=50_000), # ≤ $0.05 per request
)
r = client.chat.completions.create(
model="gpt-oss-120b",
messages=[{"role": "system", "content": "Be brief."}, {"role": "user", "content": "hello"}],
max_tokens=400, # also caps the price ceiling you sign
)
print(r.choices[0].message.content)
print(r.model_extra["phase"]) # {'task_id', 'provider', 'price_micro_usd', 'payment': 'settled', 'tx_hash', ...}
SDKs
phase-x402
Python, transport for the official openai SDK and httpx.
@phase/x402-fetch
TypeScript, a paying fetch for the OpenAI Node SDK, LangChain or plain fetch.
phasex402
Go: Client is an http.RoundTripper
MCP server
phase-mcp is a single Go binary that exposes the catalog to agents (Claude Code, Cursor, any MCP client) as tools and pays for each call from a wallet key. Tools: list_models, quote (the 402 ceiling without paying), chat, embed, session (create, read, list and delete saved sessions) and receipt (the public receipt of a paid request and its Merkle proof).
PHASE_WALLET_KEYwithout it only free models workPHASE_MAX_USD_PER_CALLlargest quote it will sign, default 0.05PHASE_MAX_USD_PER_SESSIONsum of ceilings signed by one process, default 5{
"mcpServers": {
"phase-ai": {
"command": "/path/to/phase-mcp",
"env": { "PHASE_GATEWAY_URL": "https://<gateway>", "PHASE_WALLET_KEY": "0x…", "PHASE_MAX_USD_PER_CALL": "0.05" }
}
}
}