Messages metered (Messages wire format)
POST /v1/metered/messagesAnthropic Messages API priced per request from the request itself. Send POST /v1/metered/messages with the required fields max_tokens and messages and pay quoted per request from $0.001 over x402 or MPP (there is no free tier). It returns a JSON object with id, type, role, model, content and 2 more.
The 402 quotes the input (system, messages and tools), estimated from its tokens with headroom, plus your max_tokens, from $0.001 up to a $2 per-call cap. Point the Anthropic SDK (or any Messages-format client) at base_url https://agent402.tools/v1/metered. Any model from the flat tiers (GET /v1/models). Pay the quote over x402 exact, or authorize it as a ceiling over upto or credits and settle actual usage; a card payment is charged the quote plus the processor fee. Up to 200,000 input chars and 8192 output tokens; streaming supported. The default is anthropic/claude-haiku-5.5; a call that names no model and carries a parameter anthropic/claude-haiku-5.5 does not take (temperature, top_p, top_k, an assistant prefill or a fixed reasoning budget) is served by anthropic/claude-haiku-4.5.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
model | string | no | Model id (OpenRouter naming, e.g. anthropic/claude-sonnet-5) - allowlisted per tier; omit (or "auto") on the auto tier The example sends anthropic/claude-haiku-4.5. |
max_tokens | integer | yes | Required by the Messages API; clamped to the tier's output cap The example sends 256. |
messages | array | yes | Anthropic messages: {role: user|assistant, content: string | [text|image|tool_use|tool_result blocks]} |
system | string | no | Optional system prompt (string or text blocks) |
tools | array | no | Optional client tools {name, description, input_schema}; server/built-in tools are not served |
thinking | object | no | Optional {type:"enabled", budget_tokens} | {type:"adaptive"} | {type:"disabled"} - thinking tokens are output tokens; a budget is clamped along with max_tokens to fit the tier output cap. On Claude 4.7+ (Opus 5, Sonnet 5, Fable 5.1) thinking is adaptive and `effort` is the depth control; a budget_tokens value is advisory there. Claude Haiku 5.5 refuses {type:"enabled", budget_tokens} with a 400 (send effort instead). A budget above three quarters of max_tokens is lowered to leave a quarter for the answer (not under 1024), and an answer that still comes back empty is retried once with thinking off where the model runs without it, when the call's price and time allow; either change is named in agent402_reasoning_adjusted |
effort | string | no | Optional depth control for Claude 4.7+ (Opus 5, Sonnet 5, Fable 5.1) and Claude Haiku 5.5: low | medium | high | xhigh | max, validated against the model's own list (GET /v1/models). Not accepted on Haiku 4.5 and older, which take thinking.budget_tokens instead. An effort above low that leaves no room for an answer inside a small max_tokens is sent as low, and an answer that still comes back empty is retried once at the model's lowest effort when the call's price and time allow; either change is named in agent402_reasoning_adjusted {field, requested, used, reason} (the X-Agent402-Reasoning-Adjusted header on a stream) |
stream | boolean | no | Anthropic SSE (message_start … message_stop) |
zdr | boolean | no | Optional - zero-data-retention providers only |
Example request
curl -i -X POST https://agent402.tools/v1/metered/messages \
-H "Content-Type: application/json" \
-d '{"model":"anthropic/claude-haiku-4.5","max_tokens":256,"messages":[{"role":"user","content":"Summarize x402 in one sentence."}]}'Without payment this returns HTTP 402 Payment Required with the exact price for v1-chat-metered-messages; any x402 v2 or MPP client pays it and retries.
Watch a call get paid
POST /v1/metered/messagesfrom $0.001 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example response
{
"id": "msg_…",
"type": "message",
"role": "assistant",
"model": "anthropic/claude-sonnet-5",
"content": [
{
"type": "text",
"text": "x402 is an HTTP-native way for agents to pay per request with USDC."
}
],
"stop_reason": "end_turn",
"usage": {
"input_tokens": 14,
"output_tokens": 18
}
}| Field | Type | Always present | In the example |
|---|---|---|---|
id | string | yes | msg_… |
type | string | yes | message |
role | string | yes | assistant |
model | string | yes | anthropic/claude-sonnet-5 |
content | array of objects | yes | 1 item in the example |
stop_reason | string | yes | end_turn |
usage | object | yes | 2 fields: input_tokens and 1 more |
From an MCP client
catalog.call {
"slug": "v1-chat-metered-messages",
"params": {
"model": "anthropic/claude-haiku-4.5",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": "Summarize x402 in one sentence."
}
]
}
}The hosted connector at https://agent402.tools/mcp needs a payment for v1-chat-metered-messages; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y agent402-mcp@0.17.1.
Errors and behavior
max_tokensandmessagesare required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool runs a model, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Model-backed: the answer is generated by a model, so the same input can produce a different result.
- Priced per request: the 402 quotes this body, between $0.001 and $2.
- Set a client timeout of at least 120 s: the answer is generated and the payment settled before the response is sent, which takes a few seconds on most calls and longer for long answers, and a client that disconnects after the payment settles is charged without the answer (the charge is recorded as owed and reviewed for a refund).
- A
GETorHEADto /v1/metered/messages returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB and a streamed response are not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$2.00" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/v1/metered/messages", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"model": "anthropic/claude-haiku-4.5",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": "Summarize x402 in one sentence."
}
]
}),
});No wallet yet? Fund a first one with USDC on Base, no ETH needed, or run npx -y agent402-mcp@0.17.1 wallet new to make one on this computer: it stores the key and prints the address and the config, never the key.
The quote (Python)
Standard library only: the 402 and the price its PAYMENT-REQUIRED header quotes on each chain. To pay from Python, sign it with any x402 client.
import base64, json, urllib.error, urllib.request
req = urllib.request.Request("https://agent402.tools/v1/metered/messages", method="POST", data="{\"model\":\"anthropic/claude-haiku-4.5\",\"max_tokens\":256,\"messages\":[{\"role\":\"user\",\"content\":\"Summarize x402 in one sentence.\"}]}".encode(), headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]]) # the price, per chain, in base unitsRelated tools
Messages auto (Messages wire format)
Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.
Messages base (Messages wire format)
Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.
Messages nano (Messages wire format)
Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.
Messages premium (Messages wire format)
Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.
Messages pro (Messages wire format)
Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.
Chat completions - metered (pay what the call costs)
OpenAI-compatible chat completions priced per request from the request itself.