Skip to content

Messages metered (Messages wire format)

quoted per request from $0.001USDC via x402POST /v1/metered/messages

Anthropic 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.

Category: LLM gatewayTags: llm ai inference anthropic-compatible messages-api claude gateway metered

Try in playground →

Parameters

NameTypeRequiredDescription
modelstringnoModel 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_tokensintegeryesRequired by the Messages API; clamped to the tier's output cap The example sends 256.
messagesarrayyesAnthropic messages: {role: user|assistant, content: string | [text|image|tool_use|tool_result blocks]}
systemstringnoOptional system prompt (string or text blocks)
toolsarraynoOptional client tools {name, description, input_schema}; server/built-in tools are not served
thinkingobjectnoOptional {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
effortstringnoOptional 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)
streambooleannoAnthropic SSE (message_start … message_stop)
zdrbooleannoOptional - 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

RequestPOST /v1/metered/messages
402from $0.001 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example 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
  }
}
FieldTypeAlways presentIn the example
idstringyesmsg_…
typestringyesmessage
rolestringyesassistant
modelstringyesanthropic/claude-sonnet-5
contentarray of objectsyes1 item in the example
stop_reasonstringyesend_turn
usageobjectyes2 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

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 units

Related tools

Messages auto (Messages wire format)

$0.01POST /v1/auto/messages

Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.

Messages base (Messages wire format)

from $0.02POST /v1/messages

Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.

Messages nano (Messages wire format)

from $0.003POST /v1/nano/messages

Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.

Messages premium (Messages wire format)

$0.50POST /v1/premium/messages

Messages-format chat over x402, compatible with the Anthropic Messages wire format: point the Anthropic SDK (or Claude.

Messages pro (Messages wire format)

from $0.10POST /v1/pro/messages

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)

from $0.001POST /v1/metered/chat/completions

OpenAI-compatible chat completions priced per request from the request itself.