Messages metered (Anthropic-compatible)

quoted per request from $0.001 · USDC via x402 · POST /v1/metered/messages

Anthropic Messages API billed per request from what the call costs: the 402 quotes exact-BPE input (system + messages + tools) plus your max_tokens, from $0.001 up to a $2 per-call cap. 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.

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, credits or card and settle actual usage. Up to 200,000 input chars and 8192 output tokens; streaming supported.

Category: LLM gateway · Tags: llm ai inference anthropic-compatible messages-api claude gateway openrouter

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
max_tokensintegeryesRequired by the Messages API; clamped to the tier's output cap
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
effortstringnoOptional depth control for Claude 4.7+ (Opus 5, Sonnet 5, Fable 5.1): 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
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.

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, output_tokens

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 AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.

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?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(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."
      }
    ]
  }),
});

Related tools

Messages auto (Anthropic-compatible)

$0.01 · POST /v1/auto/messages

Anthropic Messages API over x402 - point the Anthropic SDK (or Claude Code / the Agent SDK) at base_url https://agent402…

Messages base (Anthropic-compatible)

$0.02 · POST /v1/messages

Anthropic Messages API over x402 - point the Anthropic SDK (or Claude Code / the Agent SDK) at base_url https://agent402…

Messages nano (Anthropic-compatible)

$0.003 · POST /v1/nano/messages

Anthropic Messages API over x402 - point the Anthropic SDK (or Claude Code / the Agent SDK) at base_url https://agent402…

Messages premium (Anthropic-compatible)

$0.50 · POST /v1/premium/messages

Anthropic Messages API over x402 - point the Anthropic SDK (or Claude Code / the Agent SDK) at base_url https://agent402…

Messages pro (Anthropic-compatible)

$0.10 · POST /v1/pro/messages

Anthropic Messages API over x402 - point the Anthropic SDK (or Claude Code / the Agent SDK) at base_url https://agent402…

Chat completions - metered (pay what the call costs)

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

OpenAI-compatible chat completions billed per request from what the call costs: the 402 quotes exact-BPE input plus your…