◉CLAUDE LABJP
●CC 2.1.327 — Claude Code 2.1.327 (11/18) adds claude mcp add-json, which reads a server's JSON from stdin●MCP.JSON — The same release stops project-scope mcp add and remove from wiping other keys in .mcp.json●SONNET 4.5 — Retires on the Claude API on 11/30, 11 days left. Sweep model IDs in code and saved settings in one pass●GATEWAY — Users report that behind a gateway, 1M-context models compact so late that each reply takes tens of seconds●NEON — Gemini 4 Neon went GA on 11/18. If you run it next to Claude Code, keep each tool's MCP config separate●NEW — Linked Billing 402 or 403? Find Whose Wallet Is Empty First●CC 2.1.327 — Claude Code 2.1.327 (11/18) adds claude mcp add-json, which reads a server's JSON from stdin●MCP.JSON — The same release stops project-scope mcp add and remove from wiping other keys in .mcp.json●SONNET 4.5 — Retires on the Claude API on 11/30, 11 days left. Sweep model IDs in code and saved settings in one pass●GATEWAY — Users report that behind a gateway, 1M-context models compact so late that each reply takes tens of seconds●NEON — Gemini 4 Neon went GA on 11/18. If you run it next to Claude Code, keep each tool's MCP config separate●NEW — Linked Billing 402 or 403? Find Whose Wallet Is Empty First
Articles/API & SDK
⬡ API & SDK/2026-06-14Advanced

Record Which Model Actually Answered — Attestation Logging for Headless Pipelines

Persist the model field and usage from every API response so you can detect when the served model differs from the one you requested, and reconcile per-model cost ahead of the usage credits change.

Claude API148headless15cost management8loggingFable 53

✦ Premium Article

Last month I reconciled my automated content pipeline's API bill against my estimate and found a few hundred yen I couldn't account for. The call count matched my logs. The token counts matched. Only the total was off. When I dug in, the culprit was that the model I had requested and the model that actually answered diverged on a small slice of requests. I was logging the output text and the token counts, but not which model produced the response — so pinpointing where the gap came from took me half a day.

If you run Claude headless, you may have hit something similar. I had assumed that because I pin model on every call, the response naturally comes from that pinned model. In reality, the model field inside the response is the one that gets billed, and it is not guaranteed to match the string you sent. This article walks through recording the served model on every call and reconciling it against both cost and quality, using the code I shipped into my own pipeline.

When the bill didn't match the estimate

My pipeline generates content for four sites and fires roughly 480 requests a day — about 14,000 calls a month. I was already storing each call's prompt, output, and input/output token counts as JSON Lines. Estimating "sum of input tokens × price + sum of output tokens × price" should have landed close to the invoice.

For June 2026 it didn't. The total ran higher than my estimate. Dividing back down to individual calls, a small fraction looked like they were billed at a higher rate than the model I thought I was using. My logs only held the requested model name, so I had no way to prove, after the fact, which model's rate each charge belonged to. That was the starting point.

The lesson is blunt: the model the response declares — not the one you requested — is the truth about cost. And starting June 15, the move to usage credits makes per-model rate differences flow straight into the bill. Being able to explain drift after the fact matters more now than it ever did.

The response already tells you which model answered

The Messages API response body has always included a model field and a usage object. This is not an echo of your request; it is the server declaring which model produced this response. Most implementations pull out the text and throw the rest away — but that is exactly where cost reconciliation lives.

import Anthropic from "@anthropic-ai/sdk";
 
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
 
const res = await client.messages.create({
  model: "claude-fable-5",          // the model I requested
  max_tokens: 4096,
  messages: [{ role: "user", content: "Draft an article for me" }],
});
 
console.log(res.model);             // the model that actually answered (billing basis)
console.log(res.usage);             // { input_tokens, output_tokens, ... }
console.log(res.id);                // a unique ID per request

res.model does not always equal the "claude-fable-5" I asked for. That is the point. When it matches, you're fine; when it differs, it becomes the entry point for asking why. Keep res.id too — it's the correlation key for support tickets and reproduction work.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦An implementation that persists the response model field and usage on every call to catch drift between requested and served model
✦A reconciliation function that compares cost by actual served model after the move to usage credits
✦A monitoring gate that surfaces request-versus-reality drift early instead of at month end
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ API & SDK2026-05-02
Designing a Claude API Monthly Budget That Doesn't Blow Up — Cost Management for Solo Developers
When you embed Claude API into a side-project app, the first thing you hit is the end-of-month invoice. Here are the budgeting math, logging, caps, and retry rules I use to keep costs predictable, including the places where I tripped.
⬡ API & SDK2026-11-18
Before Your Customers Pay Through Linked Billing: Reading a 402 or 403 to Find Whose Wallet Is Empty
Linked billing, released in beta on November 17, lets you choose who pays on every Claude API request through billing_policy. When a request billed to a customer comes back as a 402 or 403, here is how I work out which wallet is the cause, when to pay for it myself, and a small Python wrapper that keeps that decision in one place.
⬡ API & SDK2026-11-17
If You Rely on Claude's Text Watermark, Check temperature in the Request Body, Not Your Code
Since November 16, text from Opus 4.6, Opus 4.5, Sonnet 4.5, and Haiku 4.5 carries Anthropic's text watermark, but non-default temperature, top_p, or top_k may drop it. Here is how I log the request body once and decide.