{"slug":"what-is-the-anthropic-messages-api","title":"The Anthropic Messages API is one endpoint with a strict block grammar","body":"The Anthropic Messages API is a single HTTP endpoint. `POST https://api.anthropic.com/v1/messages` takes one JSON object and returns either one JSON object or a stream of named server-sent events. Tools, images, reasoning, caching and token counting are all fields inside that one body or variants of that one response. The contract below includes the real error strings and caching arithmetic worked on a measured prompt.\n\n## Evidence status\n\n**Observed** marks first-party measurements or runtime receipts from the named environment.\n**Derived** marks arithmetic calculated from cited inputs. **Specified** marks vendor or standards\ndocumentation. **Implemented** and **deployed** name code and live-state evidence, respectively.\n**Reproduced** means the stated procedure was rerun. **Externally attested** marks operator reports;\nthose reports show that an experience occurred, not that it is universal.\n\n## One command proves the request envelope\n\nSet the key in an environment variable. Do not put it in the JSON body, a URL, source control or a log.\n\n```bash\nexport ANTHROPIC_API_KEY=\"<your Anthropic API key>\"\n\ncurl -sS https://api.anthropic.com/v1/messages \\\n  -H \"x-api-key: $ANTHROPIC_API_KEY\" \\\n  -H \"anthropic-version: 2023-06-01\" \\\n  -H \"content-type: application/json\" \\\n  --data '{\n    \"model\":\"claude-sonnet-4-5\",\n    \"max_tokens\":32,\n    \"system\":\"Answer with digits only.\",\n    \"messages\":[{\"role\":\"user\",\"content\":\"What is 7 times 6?\"}]\n  }' | jq '{type,role,content,stop_reason,usage}'\n```\n\nExpected shape:\n\n```json\n{\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"42\"}],\n \"stop_reason\":\"end_turn\",\n \"usage\":{\"input_tokens\":\"<integer>\",\"cache_creation_input_tokens\":\"<integer>\",\n          \"cache_read_input_tokens\":\"<integer>\",\"output_tokens\":\"<integer>\"}}\n```\n\nThe token values vary with model and prompt. The invariant is the envelope: one assistant `message`, an array of typed content blocks, a non-null `stop_reason`, and one `usage` object.\n\n## Your key is checked before your version header, so a version mistake hides behind a 401\n\nThree headers are mandatory: `x-api-key`, `anthropic-version`, `content-type: application/json`. The versioning reference: \"When making API requests, you must send an `anthropic-version` request header. For example, `anthropic-version: 2023-06-01`.\" What it does not say is the order of checks. Three calls to `api.anthropic.com` on 2026-07-26, varying only headers:\n\n| Call | `x-api-key` | `anthropic-version` | HTTP | `error.message` |\n| --- | --- | --- | --- | --- |\n| A | absent | absent | 401 | `x-api-key header is required` |\n| B | `sk-ant-invalid` | absent | 401 | `invalid x-api-key` |\n| C | `sk-ant-invalid` | `2024-99-99` | 401 | `invalid x-api-key` |\n\nCall C sends a version that does not exist and still gets the key error. Authentication runs first, so a missing `anthropic-version` is unreachable until the key is valid. Every response, including these, carried a `request-id` header — `req_011CdQ3SLNGpKNvrJeV1DuDb` on call A — which is the value Anthropic support asks for. The 401s also carried `x-should-retry: false`, which appears in none of the reference pages cited here; treat it as observed, not contracted.\n\n## Three required fields, and one field that looks like a message but is not\n\n| Field | Required | What it does |\n| --- | --- | --- |\n| `model` | yes | The model id. An id the endpoint does not serve is rejected. |\n| `max_tokens` | yes | \"The maximum number of tokens to generate before stopping.\" `0` writes the prompt cache without generating. Maximums are per model. |\n| `messages` | yes | Ordered `{role, content}` turns. Consecutive same-role turns \"will be combined into a single turn\". A trailing `assistant` message is continued from. |\n| `system` | no | The system prompt, at the top level of the body, outside `messages`. String or array of text blocks. |\n| `temperature` | no | \"Defaults to `1.0`. Ranges from `0.0` to `1.0`.\" Not deterministic even at `0.0`. |\n| `stop_sequences` | no | Strings that halt generation. A match sets `stop_reason` to `stop_sequence` and fills the top-level `stop_sequence` field. |\n| `stream` | no | `true` switches the response to server-sent events. |\n| `tools` | no | `{name, description, input_schema}` each, where `input_schema` is JSON Schema. |\n| `tool_choice` | no | `{\"type\":\"auto\"}`, `{\"type\":\"any\"}`, `{\"type\":\"tool\",\"name\":\"x\"}`, `{\"type\":\"none\"}`. The first three take `disable_parallel_tool_use`, default `false`. |\n| `metadata` | no | Only `user_id` is read: \"a uuid, hash value, or other opaque identifier\". Names, emails and phone numbers are warned against. |\n| `thinking` | no | Reasoning configuration. The accepted shape is model-dependent; mismatches are 400s listed in the error table. |\n\nThe system prompt is the field people get wrong, because every other major chat API carries it as a message. The reference states it in one sentence: \"there is no `\"system\"` role for input messages in the Messages API.\"\n\n```json\n{\"model\": \"claude-sonnet-4-5\", \"max_tokens\": 1024,\n \"system\": [{\"type\": \"text\", \"text\": \"You are terse.\"}],\n \"messages\": [{\"role\": \"user\", \"content\": \"What is 7 times 6?\"}]}\n```\n\n`{\"role\": \"system\", \"content\": \"...\"}` inside `messages` is not a system prompt.\n\nThe same page nonetheless lists `\"system\"` among the accepted `role` values, and flattening that contradiction would be a lie. On Claude Fable 5, Mythos 5, Opus 4.8 and Opus 5 you may \"append a `{\"role\": \"system\"}` message to `messages` instead of editing the top-level `system` field, so the cached prefix stays unchanged\" — a narrow way to add an instruction mid-conversation without invalidating the cache. It is not how you set the system prompt, it is unavailable on Claude Sonnet 5, and instructions placed there on an unsupported model are treated as conversation.\n\n## Five content-block types carry everything in both directions\n\n```json\n{\"type\": \"text\", \"text\": \"What is 7 times 6?\"}\n{\"type\": \"image\", \"source\": {\"type\": \"base64\", \"media_type\": \"image/png\", \"data\": \"iVBORw0KGgo...\"}}\n{\"type\": \"tool_use\", \"id\": \"toolu_01A\", \"name\": \"get_weather\", \"input\": {\"city\": \"Dallas\"}}\n{\"type\": \"tool_result\", \"tool_use_id\": \"toolu_01A\", \"content\": \"41C and clear\"}\n{\"type\": \"thinking\", \"thinking\": \"...\", \"signature\": \"EqQBCgIYAhIM1gbcDa9GJwZA2b3hGgxBdjrkzLoky3dl1pki...\"}\n```\n\n| Block | Sent by | What bites |\n| --- | --- | --- |\n| `text` | user, assistant | Empty text blocks cannot be cached. |\n| `image` | user | `source` is `{\"type\":\"base64\",...}` or `{\"type\":\"url\",\"url\":...}`. `media_type` limited to `image/jpeg`, `image/png`, `image/gif`, `image/webp`. Adding or removing one anywhere invalidates the message cache. |\n| `tool_use` | assistant | `input` is a parsed object, not a JSON string. |\n| `tool_result` | **user** | `content` is a string or block array; optional `is_error` marks a failed run. |\n| `thinking` | assistant | Carries a `signature`. Editing, reordering or filtering these before resending returns a 400 whose message starts with the block position, e.g. `messages.1.content.0`. |\n\nThe `tool_result` row is what catches people migrating from other APIs: a tool's answer goes back inside a **user** turn, not a message with a dedicated tool role.\n\n## An unpaired tool_use does not fail one request, it kills every request after it\n\nThree rules, all enforced:\n\n1. Every `tool_use` in an assistant message is answered by a `tool_result` **in the immediately following message**.\n2. That message has `role: \"user\"`.\n3. Each `tool_result.tool_use_id` matches a `tool_use.id` from that turn, and those ids are unique within it.\n\nBreak rule 1 and the 400 names the message index and the id. The real string, from an agent whose auto-compaction cut a turn in half:\n\n> messages.8: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01GJ.... Each `tool_use` block must have a corresponding `tool_result` block in the next message.\n\nThis is worse than an ordinary validation error because the endpoint is stateless: the client resends the whole history every turn. Once a broken pair is in the transcript, every later request — including a bare \"continue\" — replays it and gets the identical 400. The session is dead until the client edits its own history.\n\n[[embed:source:s13]]\n\nRule 3 fails more quietly. A layer that invents missing ids from the tool name produces duplicates the moment the model calls one tool twice in a turn:\n\n[[embed:source:s16]]\n\nA duplicate id is sometimes a 400 and sometimes a silent mispairing, where one tool's output is handed back as another's. Generate ids per call, never per tool name.\n\nThe round trip working, captured live on 2026-07-26 — assistant `tool_use`, user `tool_result`, finished answer:\n\n```json\n{\"content\": [{\"type\": \"text\", \"text\": \"The weather in Dallas is currently 41°C and clear. It's quite warm with clear skies!\"}],\n \"stop_reason\": \"end_turn\",\n \"usage\": {\"input_tokens\": 195, \"output_tokens\": 48, \"cache_read_input_tokens\": 0, \"cache_creation_input_tokens\": 0}}\n```\n\n## Streaming is a nested event grammar, and tool arguments arrive as string fragments\n\nWith `\"stream\": true` the response is `text/event-stream`. Each event has an SSE name and a JSON payload repeating that name in `type`. The published flow: `message_start`, then per content block a `content_block_start`, one or more `content_block_delta`, and a `content_block_stop`, then one or more `message_delta`, then a final `message_stop`.\n\n| Event | Carries | Client action |\n| --- | --- | --- |\n| `message_start` | Message shell: `id`, `model`, empty `content`, `usage.input_tokens` and cache counts | Record input usage; it is not repeated |\n| `content_block_start` | `index` plus the opening block | Allocate a buffer at that index |\n| `content_block_delta` / `text_delta` | `delta.text` | Append |\n| `content_block_delta` / `input_json_delta` | `delta.partial_json`, a raw fragment | Append to a string buffer; do not parse yet |\n| `content_block_delta` / `thinking_delta` | `delta.thinking` | Append |\n| `content_block_delta` / `signature_delta` | `delta.signature`, just before the block stops | Store verbatim; it makes the block replayable |\n| `content_block_stop` | `index` | Close the buffer; for a tool block, parse now |\n| `message_delta` | `delta.stop_reason`, `delta.stop_sequence`, `usage.output_tokens` | These usage counts are cumulative, not per-event |\n| `message_stop` | Nothing | End of stream |\n| `ping` | Nothing | Ignore. \"Event streams may also include any number of `ping` events.\" |\n| `error` | An error object mid-stream, after a 200 | Abort. Example: `{\"type\":\"error\",\"error\":{\"type\":\"overloaded_error\",\"message\":\"Overloaded\"}}` |\n\nOne rule has no event of its own: unknown types must be ignored, not treated as failures. The versioning policy reserves the right to \"add new variants to enum-like output values (for example, streaming event types)\".\n\nAssembling a tool call is what third-party implementations get wrong. The argument object arrives as raw string pieces that are individually invalid JSON:\n\n```text\n{\"delta\":{\"type\":\"input_json_delta\",\"partial_json\":\"{\\\"location\\\":\"}}\n{\"delta\":{\"type\":\"input_json_delta\",\"partial_json\":\" \\\"San\"}}\n{\"delta\":{\"type\":\"input_json_delta\",\"partial_json\":\" Francisc\"}}\n{\"delta\":{\"type\":\"input_json_delta\",\"partial_json\":\"o, CA\\\"}\"}}\n```\n\nConcatenate every `partial_json` for one `index` in arrival order and parse once at `content_block_stop`, giving `{\"location\": \"San Francisco, CA\"}`. Parsing early throws. Keying the buffer on anything but `index` corrupts parallel calls.\n\nA complete stream captured on 2026-07-26 from an endpoint answering this format. The argument object arrives in a single fragment here, which is legal — a client must handle both one and many:\n\n```text\nevent: message_start\ndata: {\"type\":\"message_start\",\"message\":{\"id\":\"msg_aig\",\"type\":\"message\",\"role\":\"assistant\",\"model\":\"@cf/zai-org/glm-4.7-flash\",\"content\":[],\"stop_reason\":null,\"stop_sequence\":null,\"usage\":{\"input_tokens\":0,\"output_tokens\":0}}}\n\nevent: content_block_start\ndata: {\"type\":\"content_block_start\",\"index\":0,\"content_block\":{\"type\":\"tool_use\",\"id\":\"chatcmpl-tool-b8d5b5cf4b01d725\",\"name\":\"get_weather\",\"input\":{}}}\n\nevent: content_block_delta\ndata: {\"type\":\"content_block_delta\",\"index\":0,\"delta\":{\"type\":\"input_json_delta\",\"partial_json\":\"{\\\"city\\\": \\\"Dallas\\\"}\"}}\n\nevent: content_block_stop\ndata: {\"type\":\"content_block_stop\",\"index\":0}\n\nevent: message_delta\ndata: {\"type\":\"message_delta\",\"delta\":{\"stop_reason\":\"tool_use\",\"stop_sequence\":null},\"usage\":{\"output_tokens\":64}}\n\nevent: message_stop\ndata: {\"type\":\"message_stop\"}\n```\n\nStreaming is a distinct transport and fails on its own. One report isolates exactly that: ordinary requests complete while the SSE call to `/v1/messages` is refused.\n\n[[embed:source:s17]]\n\n## stop_reason is an instruction to the caller, not a status label\n\nIt is `null` in `message_start` and non-null everywhere else. Seven values, each implying a different next move.\n\n| Value | Meaning | Next move |\n| --- | --- | --- |\n| `end_turn` | \"a natural stopping point\" | Render. Nothing pending. |\n| `max_tokens` | \"we exceeded the requested `max_tokens` or the model's maximum\" | Text is truncated mid-thought. Raise the cap or continue from the partial assistant turn. |\n| `stop_sequence` | \"one of your provided custom `stop_sequences` was generated\" | Read the top-level `stop_sequence` for which one matched. |\n| `tool_use` | \"the model invoked one or more tools\" | Run every `tool_use` block, return all results in one user turn. |\n| `pause_turn` | \"we paused a long-running turn\" | Send the response back as-is to continue. |\n| `refusal` | \"streaming classifiers intervene to handle potential policy violations\" | Read `stop_details.category` — `cyber`, `bio`, `frontier_llm`, `reasoning_extraction`, `general_harms` — and `stop_details.explanation`. |\n| `model_context_window_exceeded` | Context window exceeded | Compact or drop history. Retrying unchanged fails again. |\n\nRow two, captured live on 2026-07-26 with `max_tokens` set to 64:\n\n```json\n{\"content\": [{\"type\": \"text\", \"text\": \"1.  **Analyze the user's request:** The user is asking \\\"What is 7 times 6?\\\". The constraint is \\\"Answer with digits only\\\".\\n\\n2.  **Perform the calculation:** $7 \\\\times 6$.\\n    $7 \\\\times 6 = 42$.\\n\\n3.\"}],\n \"stop_reason\": \"max_tokens\", \"usage\": {\"input_tokens\": 19, \"output_tokens\": 64}}\n```\n\nThe answer is in there and the turn was cut at token 64. A client that renders only on `end_turn` shows nothing.\n\n## input_tokens counts what comes after your last cache breakpoint, not what you sent\n\n| Field | Counts |\n| --- | --- |\n| `input_tokens` | Only tokens after the last cache breakpoint — \"not all the input tokens you sent\" |\n| `cache_creation_input_tokens` | Tokens written to cache on this request |\n| `cache_read_input_tokens` | Tokens served from cache on this request |\n| `output_tokens` | Tokens generated |\n\nThe identity that always holds: `total_input_tokens = cache_read_input_tokens + cache_creation_input_tokens + input_tokens`.\n\nThe committed outputs of Anthropic's prompt-caching notebook make it concrete — the same 187,364-token prompt, three times:\n\n| Run | `input_tokens` | Cache write | Cache read | Wall time |\n| --- | --- | --- | --- | --- |\n| No caching | 187,364 | — | — | 4.89s |\n| First call with a breakpoint | 3 | 187,361 | — | 4.28s |\n| Second call, cache warm | 3 | — | 187,361 | 1.48s |\n\n`input_tokens` collapses from 187,364 to 3 once a breakpoint exists, because 187,361 tokens moved into the cache columns. A dashboard summing `input_tokens` alone reports a cached workload as nearly free and is wrong by the entire prefix.\n\nBoth cache fields at 0 means nothing was cached, most often because the prompt was under the model's minimum — and no error is returned. With a 1-hour breakpoint in play, `usage` gains a `cache_creation` object whose `ephemeral_5m_input_tokens` and `ephemeral_1h_input_tokens` members sum to `cache_creation_input_tokens`.\n\n## Caching is a field you have to send, and it pays back on the second request\n\nNothing caches by default. A breakpoint is one field on one block:\n\n```json\n{\"type\": \"text\", \"text\": \"<20,000 tokens of instructions>\", \"cache_control\": {\"type\": \"ephemeral\"}}\n```\n\n`ephemeral` is the only type. Default lifetime is five minutes, refreshed free on every hit. The cache covers the full prefix in the fixed order `tools` → `system` → `messages`, up to and including the marked block. Four explicit breakpoints are allowed; an automatic mode — a single `cache_control` at the top level of the body, placing the breakpoint on the last cacheable block and moving it forward as the conversation grows — consumes one of the four.\n\nBelow the model minimum the marker does nothing and says nothing: 512 tokens on Claude Opus 5 and Fable 5; 1,024 on Opus 4.8, Sonnet 5, Sonnet 4.6 and Sonnet 4.5; 2,048 on Opus 4.7; 4,096 on Opus 4.6, Opus 4.5 and Haiku 4.5.\n\nThe multipliers, quoted: \"5-minute cache write tokens are 1.25 times the base input tokens price\"; \"1-hour cache write tokens are 2 times the base input tokens price\"; \"Cache read tokens are 0.1 times the base input tokens price.\"\n\nWorked on a real prompt: a 20,000-token static prefix of tool definitions plus a long system prompt, on Claude Sonnet 4.5 at $3.00/MTok input, $3.75/MTok 5-minute writes, $6.00/MTok 1-hour writes and $0.30/MTok reads, sent fifty times inside one five-minute window:\n\n| Strategy | Write | Read | Total |\n| --- | --- | --- | --- |\n| No `cache_control` | — | 50 × 20,000 = 1,000,000 tok × $3.00/MTok = $3.0000 | **$3.0000** |\n| 5-minute breakpoint | 20,000 tok × $3.75/MTok = $0.0750 | 49 × 20,000 = 980,000 tok × $0.30/MTok = $0.2940 | **$0.3690** |\n| 1-hour breakpoint | 20,000 tok × $6.00/MTok = $0.1200 | $0.2940 | **$0.4140** |\n\nThe five-minute cache removes $2.6310 of $3.0000, or 87.7 percent. Break-even is the second request: two uncached requests cost 2.00 units of base price, a write plus one read costs 1.25 + 0.10 = 1.35.\n\nThe one-hour cache looks worse there and wins the moment the gap between requests exceeds five minutes. Same prefix, one request every six minutes for an hour — eleven requests, five-minute entry expired between every pair:\n\n| Strategy | Cost |\n| --- | --- |\n| 5-minute breakpoint, expiring each time | 11 writes × $0.0750 = **$0.8250**, zero reads |\n| 1-hour breakpoint | 1 write × $0.1200 + 10 reads × 20,000 = 200,000 tok × $0.30/MTok = $0.0600 → **$0.1800** |\n\nAsking for the longer lifetime is one more key: `\"cache_control\": {\"type\": \"ephemeral\", \"ttl\": \"1h\"}`. Mixing lifetimes is allowed with one ordering rule — a 1-hour entry must appear before any 5-minute entries.\n\n### Three ways caching silently does nothing\n\n**The field is never sent.** An agent whose Anthropic path omits `cache_control` pays full input price every turn and nothing says so; the only tell is both cache counters at zero.\n\n[[embed:source:s20]]\n\n**A proxy strips it.** Anything in the path can drop unrecognised keys. One gateway was caught doing it, proven by A/B: direct calls returned `cache_read_input_tokens > 0` on the second request, the same request through the gateway never did.\n\n[[embed:source:s14]]\n\nThe same failure shows up as a routing bug when markers are injected on only one code path:\n\n[[embed:source:s15]]\n\n**Something in the prefix moves per request.** The breakpoint hash covers everything up to the marked block, so a timestamp, a request id or a per-call attribution line anywhere in the prefix mints a new hash every time — a permanent 1.25x write and never a read. The published checklist adds a subtler one: \"verify that the keys in your `tool_use` content blocks have stable ordering as some languages (for example, Swift, Go) randomize key order during JSON conversion, breaking caches.\" One reference implementation strips an incoming per-request billing line off the head of the system prompt for exactly this reason (`functions/api/aig/[[path]].js`, lines 116–130).\n\nThe one-hour lifetime is also not reachable from every client. One operator reading the wire found the marker present and the lifetime absent:\n\n[[embed:source:s19]]\n\nBecause placement is manual, proxies exist purely to insert breakpoints for integrations that never expose the request body:\n\n[[embed:source:s21]]\n\nThe shape teams converge on afterwards is worth copying: one tool for structured output, parsed `tool_use`, `cache_control: ephemeral` on system and context, exponential backoff on 429.\n\n[[embed:source:s18]]\n\n## count_tokens is free, and the estimators that replace it drift\n\n`POST /v1/messages/count_tokens` takes the same body minus `max_tokens` and returns one integer:\n\n```bash\ncurl -s https://api.anthropic.com/v1/messages/count_tokens \\\n  -H \"x-api-key: $ANTHROPIC_API_KEY\" -H \"anthropic-version: 2023-06-01\" \\\n  -H \"content-type: application/json\" \\\n  -d '{\"model\":\"claude-sonnet-4-5\",\"system\":[{\"type\":\"text\",\"text\":\"Answer with digits only.\"}],\n       \"messages\":[{\"role\":\"user\",\"content\":\"What is 7 times 6?\"}]}'   # -> {\"input_tokens\": 18}\n```\n\nIt is \"free to use but subject to requests per minute rate limits based on your usage tier\", and those limits are independent: \"Token counting and message creation have separate and independent rate limits. Usage of one does not count against the limits of the other.\" Use it for routing, for fitting a prompt under a context window, and for checking that a prefix clears a cache minimum before relying on caching.\n\nBecause it is optional, gateways often substitute a character estimate. Two measurements on 2026-07-26 against an implementation that divides an accumulated character count by 3.7 (`functions/api/aig/[[path]].js`, lines 445–457). The body above returned 18; sent to `/v1/messages`, it reported `usage.input_tokens` of 19 — low by one, 5.3 percent.\n\nThe second shows the error is not stable. A 100-character system prompt with a one-character user message returned `{\"input_tokens\": 55}`. Counting the system prompt once gives ceil((100 + 1) / 3.7) = 28. Fifty-five is ceil((100 + 100 + 1) / 3.7): the system prompt is measured once on its own and again inside the translated message list, so it is counted twice. Where the system prompt dominates — the normal case for a coding agent — that estimator reports roughly double, and a client using it to decide when to compact compacts far too early.\n\n## The error catalogue, by symptom\n\n| Symptom | HTTP / `error.type` | Cause | Fix |\n| --- | --- | --- | --- |\n| `x-api-key header is required` | 401 `authentication_error` | No key header | Send `x-api-key`. A bearer token is a different header. |\n| `invalid x-api-key` | 401 `authentication_error` | Malformed, revoked or expired key | Replace it. A missing version header stays invisible until this passes. |\n| Key works elsewhere, fails here | 403 `permission_error` | \"Your API key does not have permission to use the specified resource\" | Check organisation and workspace settings. |\n| `The requested resource could not be found.` | 404 `not_found_error` | Wrong path or id | Check the endpoint path and any ids in the URL. |\n| Large request rejected before the model sees it | 413 `request_too_large` | Over 32 MB on Messages or Token Counting; 256 MB Batch; 500 MB Files | Move bulk content to the Files API. |\n| Sudden throttling | 429 `rate_limit_error` | RPM, ITPM or OTPM exceeded | Read `retry-after` and the `anthropic-ratelimit-*` headers. Cache hits are not deducted from rate limits. |\n| Every call after one bad turn returns the same 400 | 400 `invalid_request_error` | A `tool_use` with no `tool_result` in the next message | Repair the stored history; the endpoint holds no state to reset. |\n| Parallel calls to one tool break | 400 `invalid_request_error` | Duplicate `tool_use` ids | Generate ids per call. |\n| `This model does not support assistant message prefill. The conversation must end with a user message.` | 400 `invalid_request_error` | Prefilled trailing assistant turn on Claude 4.6+ | Use structured outputs or `output_config.format`. |\n| `` `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. `` | 400 `invalid_request_error` | Thinking blocks edited, reordered or filtered before resend | Pass them back byte for byte, including empty ones and `redacted_thinking`. |\n| `\"thinking.type.enabled\" is not supported for this model.` or `adaptive thinking is not supported on this model` | 400 `invalid_request_error` | Wrong thinking shape for the model | `{\"type\":\"adaptive\"}` with `output_config.effort` on Claude 4.7+; `{\"type\":\"enabled\",\"budget_tokens\":N}` on 4.5 and earlier. |\n| `Overloaded` | 529 `overloaded_error`, or an `error` event mid-stream after a 200 | Capacity | Retry with backoff. In streaming this arrives after headers, so HTTP status alone will not catch it. |\n\nEvery error body is JSON with a top-level `error` carrying `type` and `message`, plus a `request_id`:\n\n```json\n{\"type\": \"error\",\n \"error\": {\"type\": \"not_found_error\", \"message\": \"The requested resource could not be found.\"},\n \"request_id\": \"req_011CSHoEeqs5C35K2UUqR7Fy\"}\n```\n\nMatch on the SDK's typed exception classes, not on message text — the reference is explicit that \"the values within these objects may expand\".\n\n## Three other vendors answer this exact shape, and each drops different fields\n\nThe same credential-free request body reached all three Anthropic-shaped routes on 2026-07-26 and all returned HTTP 401: DeepSeek returned `Authentication Fails (governor)`; Z.ai returned `Authentication parameter not received in Header, unable to authenticate`; Moonshot returned `Incorrect API key provided` with type `incorrect_api_key_error`. These are route-existence receipts, not compatibility claims.\n\nBecause the format is one endpoint with a documented body, other providers implement it and inherit any client that speaks it. DeepSeek documents `https://api.deepseek.com/anthropic` — \"our API has added support for the Anthropic API format\" — and Z.ai documents `https://api.z.ai/api/anthropic`. Moonshot's former agent-support documentation now redirects to its generic Kimi API overview, which documents OpenAI compatibility instead. The Anthropic-shaped route still exists: a credential-free probe of `POST https://api.moonshot.ai/anthropic/v1/messages` returned 401 with an `incorrect_api_key_error` on 2026-07-26. That proves the route answers; it does not restore the missing field-by-field vendor contract.\n\nCompatible is a range, not a boolean. DeepSeek publishes a field-by-field support matrix, and reading it is the fastest way to see which parts of the format are load-bearing:\n\n| Field | DeepSeek status |\n| --- | --- |\n| `anthropic-version`, `anthropic-beta` headers | Ignored |\n| `max_tokens`, `stop_sequences`, `stream`, `system`, `temperature`, `top_p`, `x-api-key` | Fully Supported |\n| `top_k`, `container`, `mcp_servers`, `service_tier` | Ignored |\n| `metadata` | `user_id` supported, others ignored |\n| `cache_control` on tools, text, `tool_use`, `tool_result` | Ignored |\n| Image, document and `search_result` blocks | Not Supported |\n\nTwo rows carry the whole caching story from the other side. `anthropic-version` ignored means the version header buys nothing. `cache_control` ignored means every breakpoint is discarded — silently, exactly as the gateway bug above did by accident — and `cache_read_input_tokens` in the response is the only way to tell. DeepSeek also maps ids by prefix: `claude-opus*` becomes `deepseek-v4-pro`, `claude-haiku*` and `claude-sonnet*` become `deepseek-v4-flash`, and an unrecognised name falls through to `deepseek-v4-flash` rather than erroring.\n\nA working configuration that routes an Anthropic-format client to a non-Anthropic model, with a test suite over these behaviours, is in [Claude Code on Kimi, GLM or Grok through your own Cloudflare account](/a/claude-code-on-cloudflare-ai-gateway). The account setup behind it is in [the AI Gateway setup page](/a/cloudflare-ai-gateway-setup) and the credit accounting in [Cloudflare Unified Billing](/a/cloudflare-unified-billing).\n\n## Fresh wire checks reproduce the contract\n\nThe complete harness is the same sequence printed below, run at 05:15–05:16 UTC on 2026-07-26. It reads credentials from local settings and writes only redacted results.\n\n| Check | Fresh result |\n| --- | --- |\n| Non-streaming `POST /v1/messages`, `max_tokens: 64` | HTTP 200; 507 response bytes in 1.649598 s; `stop_reason: \"max_tokens\"`; 19 input and 64 output tokens |\n| `POST /v1/messages/count_tokens` on the same prompt | HTTP 200; 19 response bytes in 0.041256 s; 18 input tokens — one below message usage |\n| Forced streamed `get_weather` call | HTTP 200; 1,491 response bytes in 1.201516 s; 11 SSE frames; compacting six `input_json_delta` fragments produced `{\"city\":\"Dallas\"}` |\n| No key and no version | HTTP 401; `x-api-key header is required`; `request-id` present; `x-should-retry: false` |\n| Invalid key with no version | HTTP 401; `invalid x-api-key` |\n| Invalid key with an invalid version | HTTP 401; `invalid x-api-key` — authentication still won the check order |\n\nThe exact local commands were `node /private/tmp/codex-messages-api/measure.mjs` and `node /private/tmp/codex-messages-api/measure-headers.mjs`. Neither prints a credential.\n\n## Method for the six measurements above\n\nAll six were captured on 2026-07-26. The header-order table and the `request-id` / `x-should-retry` observation came from `api.anthropic.com/v1/messages` with no valid key — all three calls fail, and which way they fail is the finding, so no credential is needed to reproduce them. The truncated response, the SSE sequence, the tool round trip and the `count_tokens` comparison came from a Messages-API server implemented as a Cloudflare Pages function: `functions/api/aig/[[path]].js`, 531 lines, translating the Anthropic body to and from a chat-completions upstream, cited above by line number.\n\nTo rerun any of them, point `BASE` at `https://api.anthropic.com` or at any gateway answering this format, put a key in `TOKEN`, save the body from the relevant section to `body.json`, and send `curl -s -N -X POST \"$BASE/v1/messages\" -H \"x-api-key: $TOKEN\" -H 'anthropic-version: 2023-06-01' -H 'content-type: application/json' -d @body.json`.","register":"essay","tags":["tooling","api","anthropic-messages","streaming","prompt-caching","tool-use"],"style":{},"claims":[{"id":"c1","text":"The Messages API is POST /v1/messages with x-api-key, anthropic-version and content-type headers; one JSON body produces one message or an SSE stream.","section":"One command proves the request envelope","tier":"system","source_ids":["r3","s1","s2"],"why_material":"This is the executable wire contract."},{"id":"c2","text":"Authentication is checked before version validity: an invalid key plus an impossible version still returns invalid x-api-key.","section":"Your key is checked before your version header, so a version mistake hides behind a 401","tier":"system","source_ids":["r3","s2"],"why_material":"It fixes the order in which a caller diagnoses headers."},{"id":"c3","text":"The main system prompt belongs in the top-level system field, not a system-role input message.","section":"Three required fields, and one field that looks like a message but is not","tier":"system","source_ids":["s1","s4"],"why_material":"Putting it in the wrong place changes semantics or fails by model."},{"id":"c4","text":"Messages carry text, image, tool_use, tool_result and thinking as typed content blocks rather than dedicated message roles.","section":"Five content-block types carry everything in both directions","tier":"system","source_ids":["s1","s5"],"why_material":"A client cannot serialize or replay the API without the block union."},{"id":"c5","text":"Every assistant tool_use must be paired by id with a tool_result in the immediately following user message or later turns replay the same 400.","section":"An unpaired tool_use does not fail one request, it kills every request after it","tier":"system","source_ids":["s13","s5"],"why_material":"It is the transcript invariant that most often bricks an agent session."},{"id":"c6","text":"Synthesizing tool ids from tool names collides on parallel calls to the same function and can produce either a 400 or mispaired results.","section":"An unpaired tool_use does not fail one request, it kills every request after it","tier":"anecdotal","source_ids":["s16"],"why_material":"Unique ids are required per call, not per tool."},{"id":"c7","text":"A streamed tool argument is a sequence of partial_json strings keyed by content-block index and must be parsed only after concatenation.","section":"Streaming is a nested event grammar, and tool arguments arrive as string fragments","tier":"system","source_ids":["r2","s17","s3"],"why_material":"Parsing each delta independently corrupts valid tool calls."},{"id":"c8","text":"stop_reason tells the caller whether to render, continue, execute tools, retry or fall back; it is not a decorative status.","section":"stop_reason is an instruction to the caller, not a status label","tier":"system","source_ids":["r1","s6"],"why_material":"Each value requires a different state transition."},{"id":"c9","text":"Total input is input_tokens plus cache_creation_input_tokens plus cache_read_input_tokens; input_tokens alone can fall to 3 on a 187,364-token cached prompt.","section":"input_tokens counts what comes after your last cache breakpoint, not what you sent","tier":"system","source_ids":["s12","s4"],"why_material":"Billing and dashboards are wrong if they sum one field."},{"id":"c10","text":"Prompt caching is opt-in: five-minute writes cost 1.25x base input, one-hour writes cost 2x and reads cost 0.1x.","section":"Caching is a field you have to send, and it pays back on the second request","tier":"system","source_ids":["s21","s4"],"why_material":"The cache decision needs its full arithmetic."},{"id":"c11","text":"On a 20,000-token prefix repeated fifty times inside five minutes, the worked cache cost is $0.3690 instead of $3.0000, an 87.7 percent saving.","section":"Caching is a field you have to send, and it pays back on the second request","tier":"system","source_ids":["s12","s4"],"why_material":"The page must state the economics, not only the mechanism."},{"id":"c12","text":"Caching can fail silently when cache_control is omitted, stripped by a proxy, injected only on one route or emitted without the requested one-hour ttl.","section":"Three ways caching silently does nothing","tier":"anecdotal","source_ids":["s14","s15","s19","s20","s23"],"why_material":"Zero error does not mean the cache is active."},{"id":"c13","text":"count_tokens is free and separately rate-limited, but a compatibility estimator measured 18 tokens against 19 in message usage on the same prompt.","section":"count_tokens is free, and the estimators that replace it drift","tier":"system","source_ids":["r1","s7"],"why_material":"Routing and compaction thresholds depend on the estimate."},{"id":"c14","text":"Messages errors are typed JSON objects with request ids, but types may expand, so callers should match typed classes rather than prose.","section":"The error catalogue, by symptom","tier":"system","source_ids":["r3","s8"],"why_material":"Stable error handling must not depend on mutable message text."},{"id":"c15","text":"DeepSeek, Z.ai and Moonshot currently answer Anthropic-shaped message routes, but compatibility differs by field and Moonshot's current public docs no longer state the Anthropic contract.","section":"Three other vendors answer this exact shape, and each drops different fields","tier":"system","source_ids":["r4","s10","s11","s9"],"why_material":"A base URL returning 401 proves a route, not complete compatibility."},{"id":"c16","text":"A production translation layer must preserve streaming, tool ids and results, images, usage, stop reasons and error envelopes while mapping the upstream request format.","section":"Method for the six measurements above","tier":"system","source_ids":["r1","r2","s22"],"why_material":"These are the behaviors that make a compatible endpoint usable by a real client."},{"id":"c17","text":"An independent direct-versus-proxy A/B test found cache reads on the second direct Bedrock request and none through agentgateway because cache_control was dropped.","section":"Three ways caching silently does nothing","tier":"anecdotal","source_ids":["s14","s23"],"why_material":"It isolates the proxy as the cache failure."},{"id":"c18","text":"A positive implementation report converged on one structured-output tool, parsed tool_use, cache_control on system and context, and exponential backoff on 429.","section":"Three ways caching silently does nothing","tier":"anecdotal","source_ids":["s18"],"why_material":"The page carries a working operator pattern as well as failures."}],"sources":[{"id":"s1","type":"specification","url":"https://platform.claude.com/docs/en/api/messages","title":"Messages API reference","quote":"Create a Message","summary":"Normative request and response fields for POST /v1/messages, including the top-level system field and content-block unions.","publisher":"Anthropic","claim_ids":["c1","c3","c4"]},{"id":"s2","type":"specification","url":"https://platform.claude.com/docs/en/api/versioning","title":"API versioning","quote":"When making API requests, you must send an `anthropic-version` request header. For example, `anthropic-version: 2023-06-01`.","summary":"The required version header and Anthropic's compatibility policy.","publisher":"Anthropic","claim_ids":["c1","c2"]},{"id":"s3","type":"specification","url":"https://platform.claude.com/docs/en/build-with-claude/streaming","title":"Streaming Messages","quote":"Event streams may also include any number of `ping` events.","summary":"The SSE event grammar, incremental JSON deltas, pings, mid-stream errors and unknown-event rule.","publisher":"Anthropic","claim_ids":["c7"]},{"id":"s4","type":"publisher_documentation","url":"https://platform.claude.com/docs/en/build-with-claude/prompt-caching","title":"Prompt caching","quote":"Cache prompt prefixes with `cache_control` to cut costs and latency, using automatic caching or explicit breakpoints with 5-minute or 1-hour TTLs.","summary":"Cache placement, expiry, minimum prompt lengths, invalidators and the 1.25x/2x/0.1x prices.","publisher":"Anthropic","claim_ids":["c10","c11","c3","c9"]},{"id":"s5","type":"publisher_documentation","url":"https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview","title":"Tool use overview","quote":"Tool use lets Claude call functions that you define or that Anthropic provides.","summary":"The complete client-tool round trip: tool definition, tool_use response, execution and user-role tool_result.","publisher":"Anthropic","claim_ids":["c4","c5"]},{"id":"s6","type":"publisher_documentation","url":"https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons","title":"Stop reasons and fallback","quote":"Every Messages API response includes a `stop_reason` field that tells you why Claude stopped generating.","summary":"Every stop_reason value and the action a caller takes next.","publisher":"Anthropic","claim_ids":["c8"]},{"id":"s7","type":"publisher_documentation","url":"https://platform.claude.com/docs/en/build-with-claude/token-counting","title":"Token counting","quote":"Token counting is **free to use** but subject to requests per minute rate limits based on your usage tier.","summary":"The count_tokens request shape, supported inputs, price and independent rate limit.","publisher":"Anthropic","claim_ids":["c13"]},{"id":"s8","type":"publisher_documentation","url":"https://platform.claude.com/docs/en/api/errors","title":"Errors","quote":"the values within these objects may expand, and it is possible that the `type` values will grow over time.","summary":"HTTP codes, typed error envelopes, request ids, request-size limits and retry behavior.","publisher":"Anthropic","claim_ids":["c14"]},{"id":"s9","type":"publisher_documentation","url":"https://api-docs.deepseek.com/guides/anthropic_api/","title":"DeepSeek Anthropic API compatibility","quote":"our API has added support for the Anthropic API format","summary":"DeepSeek's field-by-field support matrix and model-id mapping for its Anthropic-compatible base URL.","publisher":"DeepSeek","claim_ids":["c15"]},{"id":"s10","type":"publisher_documentation","url":"https://docs.z.ai/scenario-example/develop-tools/claude","title":"Use Claude Code with Z.ai models","quote":"ANTHROPIC_BASE_URL","summary":"Z.ai's official configuration publishes https://api.z.ai/api/anthropic as the Anthropic base URL.","publisher":"Z.ai","claim_ids":["c15"]},{"id":"s11","type":"publisher_documentation","url":"https://platform.kimi.ai/docs/api/overview","title":"Kimi API overview","quote":"Kimi Open Platform provides OpenAI-compatible HTTP APIs.","summary":"Current Kimi documentation now states OpenAI compatibility and no longer documents the older Anthropic agent-support route; the live route probe is therefore labelled first-party rather than vendor contract.","publisher":"Moonshot AI","claim_ids":["c15"]},{"id":"s12","type":"repository","url":"https://github.com/anthropics/claude-cookbooks/blob/main/misc/prompt_caching.ipynb","title":"Anthropic prompt-caching notebook","quote":"Speedup:        3.3x","summary":"Executable notebook and committed outputs for the 187,364-token no-cache/write/read comparison.","publisher":"Anthropic","claim_ids":["c11","c9"]},{"id":"s13","type":"github","url":"https://github.com/valkyriweb/pi-mono/issues/406","title":"Compaction can emit an unpaired tool_use, bricking the session with a permanent Anthropic 400","quote":"messages.8: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_01GJ.... Each `tool_use` block must have a corresponding `tool_result` block in the next message.","summary":"Auto-compaction from 184,072 tokens cut a turn mid-tool-call, leaving a tool_use block with no following tool_result. Every subsequent request, including a bare 'continue', replays the invalid history and gets the same Anthropic 400 — deterministic and unrecoverable in-session. Negative: the tool_use/tool_result pairing invariant is unforgiving.","author":"valkyriweb","publisher":"GitHub","date":"2026-07-25","claim_ids":["c5"]},{"id":"s14","type":"github","url":"https://github.com/agentgateway/agentgateway/issues/2628","title":"feature: cache_control stripped when proxying to AWS Bedrock (Anthropic prompt caching broken)","quote":"When sending a request through agentgateway with Anthropic `cache_control` markers in the system prompt, the field is silently dropped before the request reaches Bedrock. As a result, prompt caching never activates","summary":"Proved it by A/B: direct Bedrock calls return cache_read_input_tokens > 0 on the second request, the same request through the gateway never does. Every call is billed at full input-token cost with no error surfaced. Negative — a proxy in the path silently deleting cache_control is invisible until the bill arrives.","author":"guenhter","publisher":"GitHub","date":"2026-07-22","claim_ids":["c12","c17"]},{"id":"s15","type":"github","url":"https://github.com/bobmatnyc/trusty-tools/issues/3388","title":"Prompt caching may be silently inert for OpenRouter-routed agents (cache_control only injected on native-Anthropic path)","quote":"Net effect: the caching flag is honored for *routing* but not for *the actual cache markers*, so no prompt caching happens on the wire.","summary":"While writing a caching regression test, found cache_control injection gated behind route_native_anthropic, so any agent configured with enable_prompt_caching but routed through OpenRouter got the raw-request path without the markers. Describes it as \"a silent, recurring token-cost increase with no error, no warning, and no failing test.\" Negative.","author":"bobmatnyc","publisher":"GitHub","date":"2026-07-20","claim_ids":["c12"]},{"id":"s16","type":"github","url":"https://github.com/go-steer/core-agent/issues/367","title":"Anthropic: synthesized tool_use IDs collide on parallel calls to the same tool","quote":"Two parallel calls to the same function in one turn (or a replayed Gemini-origin history, which frequently omits IDs) produce duplicate `tool_use`/`tool_result` IDs → Anthropic 400 (IDs must be unique) or mispaired results.","summary":"Code review of pkg/models/anthropic/convert.go found missing IDs patched with \"call_\"+name, which collides whenever the model issues parallel calls to the same tool or when replaying a Gemini-origin history. Result is either a hard 400 or, worse, silently mispaired tool results. Negative.","author":"mastersingh24","publisher":"GitHub","date":"2026-07-25","claim_ids":["c6"]},{"id":"s17","type":"github","url":"https://github.com/anthropics/claude-code/issues/76802","title":"[BUG] ConnectionRefused on /v1/messages streaming while simple API requests succeed (Windows, Bun)","quote":"[BUG] ConnectionRefused on /v1/messages streaming while simple API requests succeed (Windows, Bun)","summary":"Filed against Claude Code itself: plain non-streaming API requests complete but the streaming SSE call to /v1/messages gets ConnectionRefused, on Windows 11 under PowerShell and the VS Code integrated terminal. Negative — isolates streaming as the failing transport rather than auth or connectivity.","author":"tushar1210","publisher":"GitHub","date":"2026-07-12","claim_ids":["c7"]},{"id":"s18","type":"github","url":"https://github.com/amadoug2g/Sweep/issues/4","title":"ClaudeClient: /v1/messages with tool_use","quote":"Implement prompt caching (system + context marked `cache_control: ephemeral`)","summary":"An operator's own build spec for a Messages API client: POST /v1/messages with a propose_actions tool for structured output, parse tool_use into strongly-typed values, mark system and context blocks cache_control: ephemeral, and handle 429 with exponential backoff. Positive — shows the shape people actually settle on.","author":"amadoug2g","publisher":"GitHub","date":"2026-05-17","claim_ids":["c18"]},{"id":"s19","type":"hn","url":"https://news.ycombinator.com/item?id=47745409","title":"Comment on \"Pro Max 5x quota exhausted in 1.5 hours\" — 1h cache TTL","quote":"but how to make claude-code send that when paying by API-key? or when using a custom ANTHROPIC_BASE_URL? (requests will contain cache_control, but no ttl!)","summary":"Wants the documented \"ttl\": \"1h\" prompt-caching option but finds only ENABLE_PROMPT_CACHING_1H_BEDROCK exists as an env switch. Observes on the wire that requests carry cache_control but never a ttl field, so extended-TTL caching is unreachable on API-key or custom-base-URL paths. Negative.","author":"g4cg54g54","publisher":"Hacker News","date":"2026-04-12","claim_ids":["c12"]},{"id":"s20","type":"hn","url":"https://news.ycombinator.com/item?id=48167243","title":"Comment on \"Zerostack – a coding agent in pure Rust\" — missing cache_control","quote":"In the Anthropic implementation it doesn't seem to be using 'cache_control' in the body. Assuming my understanding is current, without that the Anthropic API won't do any caching at all","summary":"Read an agent's source and found its Anthropic path never sets cache_control, meaning full input price on every turn, unlike providers that cache automatically. Also notes /prompt rebuilds the preamble and forces a full cache miss on the next turn. Negative — the cache_control-is-opt-in gotcha caught in the wild.","author":"post_below","publisher":"Hacker News","date":"2026-05-17","claim_ids":["c12"]},{"id":"s21","type":"hn","url":"https://news.ycombinator.com/item?id=45518040","title":"Show HN: Autocache – Cut Claude API costs 90% (for n8n, Flowise, etc.)","quote":"For a 1000-token system prompt reused across requests, you pay 1.25× once to cache it, then 0.1× on every   subsequent request.","summary":"Built a transparent proxy that analyses each Messages API request and places cache breakpoints automatically, because Anthropic requires manual placement and integrations like n8n and Flowise never expose the request structure. States the underlying economics as 1.25x write, 0.1x read. Positive — a first-hand read of why cache_control being manual is a real product gap.","author":"jmrobles","publisher":"Hacker News","date":"2025-10-08","claim_ids":["c10"]},{"id":"s22","type":"repository","url":"https://github.com/massoumicyrus/claude-code-cloudflare-gateway","title":"A Messages-to-Chat-Completions translation layer","quote":"Claude Code speaks the Anthropic Messages API (`POST /v1/messages`) and every other model in the Cloudflare catalogue is Chat Completions.","summary":"Public one-file implementation and contract suite showing which Messages fields a compatibility translator must preserve.","publisher":"GitHub","claim_ids":["c16"]},{"id":"s23","type":"independent_measurement","url":"https://github.com/agentgateway/agentgateway/issues/2628","title":"Independent A/B measurement: cache_control direct to Bedrock versus through a proxy","quote":"When sending a request through agentgateway with Anthropic `cache_control` markers in the system prompt, the field is silently dropped before the request reaches Bedrock. As a result, prompt caching never activates","summary":"Named A/B harness: the same request produced cache_read_input_tokens on its second direct Bedrock call and zero cache reads through agentgateway.","author":"guenhter","publisher":"GitHub","date":"2026-07-22","claim_ids":["c12","c17"]},{"id":"r1","type":"runtime_receipt","url":"https://miscsubjects.com/api/articles/what-is-the-anthropic-messages-api","title":"First-party wire receipt: message creation and count_tokens, 2026-07-26","quote":"HTTP 200; 507 response bytes in 1.649598 s; `stop_reason: \"max_tokens\"`; 19 input and 64 output tokens","summary":"Method: run the same system and user prompt through the live Messages translator and its count_tokens endpoint; compare usage without exposing the path credential.","publisher":"miscsubjects.com","date":"2026-07-26","claim_ids":["c13","c16","c8"]},{"id":"r2","type":"runtime_receipt","url":"https://miscsubjects.com/api/articles/what-is-the-anthropic-messages-api","title":"First-party wire receipt: streamed forced tool call, 2026-07-26","quote":"HTTP 200; 1,491 response bytes in 1.201516 s; 11 SSE frames; compacting six `input_json_delta` fragments produced `{\"city\":\"Dallas\"}`","summary":"Method: force get_weather through tool_choice, buffer partial_json by content-block index, and parse only after the block stops.","publisher":"miscsubjects.com","date":"2026-07-26","claim_ids":["c16","c7"]},{"id":"r3","type":"runtime_receipt","url":"https://miscsubjects.com/api/articles/what-is-the-anthropic-messages-api","title":"First-party wire receipt: authentication precedes version validation, 2026-07-26","quote":"No key and no version | HTTP 401; `x-api-key header is required`; `request-id` present; `x-should-retry: false`","summary":"Method: POST the same harmless one-token body three times to api.anthropic.com, varying only x-api-key and anthropic-version. Every response included request-id and x-should-retry:false.","publisher":"Anthropic API","date":"2026-07-26","claim_ids":["c1","c14","c2"]},{"id":"r4","type":"runtime_receipt","url":"https://miscsubjects.com/api/articles/what-is-the-anthropic-messages-api","title":"First-party compatibility probes for DeepSeek, Z.ai and Moonshot, 2026-07-26","quote":"The same credential-free request body reached all three Anthropic-shaped routes on 2026-07-26 and all returned HTTP 401","summary":"Method: send the same harmless Anthropic-shaped body with no credential to each published base URL. Authentication errors prove all three routes answer without claiming unsupported fields are compatible.","publisher":"miscsubjects.com","date":"2026-07-26","claim_ids":["c15"]}],"prov":{"model":"Opus 5 (Claude Code)","action":"write"}}