惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
博客园 - 司徒正美
美团技术团队
Vercel News
Vercel News
IT之家
IT之家
U
Unit 42
Y
Y Combinator Blog
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
V
Visual Studio Blog
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
博客园 - 叶小钗
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Why I Log response.model on Every Claude Call (and You Sh...
Pavel Espitia · 2026-06-22 · via DEV Community

Pavel Espitia

It is a one-line habit that has saved me more debugging time than any clever abstraction: I log which model actually answered every Claude request. Not which model I asked for. Which one responded. In 2026, with model fallbacks, fast-changing model strings, and routing logic, those are not always the same thing. Here is why the gap exists and what it has caught.

The request model and the response model can differ

You send model: "claude-fable-5". You assume Fable 5 answered. But the response object tells you what actually served the request:

const response = await client.messages.create({
  model: "claude-fable-5",
  max_tokens: 16000,
  thinking: { type: "adaptive" },
  messages: [{ role: "user", content: prompt }],
});

console.log("requested fable-5, served:", response.model);

Most of the time they match. The interesting cases are when they do not.

The Fable 5 safeguard fallback

The reason this matters most in 2026 is Fable 5's safeguards. Fable 5 has hard guardrails in cybersecurity, biology, chemistry, and health. If your prompt trips one, the request does not just refuse. It silently falls back to Opus 4.8 to produce a safe answer.

For my security work, this is a sharp edge. I run contract-analysis prompts that can look adversarial to a safeguard. If one trips, I am quietly getting Opus 4.8 output while believing I am getting Fable-tier reasoning. The quality difference on a hard audit is exactly the thing I paid double for, and it vanished without an error.

The only way to know is to read response.model:

if (!response.model.startsWith("claude-fable-5")) {
  logger.warn(
    { requested: "claude-fable-5", served: response.model },
    "Fable 5 request fell back, likely a safeguard trip",
  );
}

Without that log, a fallback is invisible until I notice the analysis got worse and have no idea why.

Routing logic and config drift

The other source of the gap is my own code. I have routing that picks a model based on task type and a config that sets defaults. It is easy for those to drift: a config change points "deep audit" at the wrong model, or a routing bug sends classification to Opus when it should hit Haiku. Logging the served model surfaces this immediately.

logger.info(
  { task: taskType, requested: chosenModel, served: response.model, tokens: response.usage },
  "llm call",
);

When my bill spiked one week, this log told me in thirty seconds that a routing change had sent a high-volume path to Opus 4.8 instead of Haiku 4.5. The five-times cost difference between those was the whole spike. Without the served-model log I would have spent an afternoon guessing.

It is also your migration safety net

When a new model ships and I bump a model string, the served-model log is how I verify the change took effect everywhere. The migration guidance even recommends asserting on it:

const r = await client.messages.create({
  model: "claude-opus-4-8",
  max_tokens: 64,
  messages: [{ role: "user", content: "ping" }],
});
console.assert(r.model.startsWith("claude-opus-4-8"), `got ${r.model}`);

A stray hardcoded model string in some helper I forgot about shows up the moment the served model does not match what I expect.

Log the usage while you are at it

Since you are already logging the model, log response.usage in the same line. It gives you input_tokens, output_tokens, and the cache fields. That single structured log line becomes your cost dashboard: which task type, which model, how many tokens, how much was served from cache. Three fields you will want eventually, captured for free now.

const { input_tokens, output_tokens, cache_read_input_tokens } = response.usage;
logger.info({ model: response.model, input_tokens, output_tokens, cache_read_input_tokens }, "llm");

The habit

It costs one line and a structured logger. It catches silent model fallbacks, config drift, routing bugs, cost spikes, and incomplete migrations. The unifying theme is that what you asked for and what you got are different facts, and only one of them is in your code. The other is in the response. Read it, log it, and you will know things about your LLM usage that would otherwise only surface as a confusing bill or a quality regression with no explanation.