Messages base (Anthropic-compatible)

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

Anthropic Messages API over x402 - point the Anthropic SDK (or Claude Code / the Agent SDK) at base_url https://agent402.tools/v1 and pay $0.02 per call in USDC, no API key, no signup. Send POST /v1/messages with the required fields max_tokens and messages and pay quoted per request from $0.02 over x402 or MPP (there is no free tier). It returns a JSON object with id, type, role, model, content and 2 more.

Same models, caps and price as this tier's /chat/completions route; any model here is served through the Messages wire (Claude natively, others translated). Depth: `effort` (low..max) on Claude 4.7+, thinking.budget_tokens on older Claude. Up to 32,000 input chars and 2048 output tokens; streaming supported. Omit "model" and the tier serves openai/gpt-4o-mini (named back in agent402_default_model); the price does not change.

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. 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/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-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-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-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/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 metered (Anthropic-compatible)

$0.001 · POST /v1/metered/messages

Anthropic Messages API billed per request from what the call costs: the 402 quotes exact-BPE input (system + messages + …

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…

Text-to-speech (OpenAI-compatible)

$0.060 · POST /v1/audio/speech

OpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url https://agent402.t…