What metadata.user_id in the Claude API Is Actually For — Designing the Abuse-Detection vs. Privacy Trade-off
The metadata.user_id field in the Messages API exists to sharpen abuse detection, but sending raw email addresses creates a privacy problem. Here is the HMAC-based stable pseudo-ID pattern I use, plus a clear set of rules for when to send it and when not to.
Bulletproof JSON Output with Claude API Prefill: A Four-Layer Defense Pattern from Indie SaaS
How I went from late-night JSON parse failures to a 100% parse success rate across thousands of monthly Claude API requests. Working code in TypeScript and Python, plus production numbers from an indie SaaS.
A Five-Layer Preflight Design for Claude API — How I Cut Hundreds of 400/422/529 Errors to Zero
A production-tested five-layer preflight design that catches Claude API failures before the network call — schema, token budget, model capability, content policy, and spend cap — with full TypeScript implementation and one month of operational numbers.
Type-Safe Claude API Tool Calling with Zod: Patterns for TypeScript Developers
How to implement Claude API tool calling with TypeScript and Zod for full type safety. Covers schema-to-API conversion, runtime validation, and three common pitfalls with practical code examples.
Maximizing Profit Margins with Claude Haiku / Sonnet / Opus Model Switching
A complete implementation guide for dynamically routing Claude API requests to the right model based on task complexity. Includes cost calculation formulas, routing engine code, quality fallback logic, and real-world margin impact data.
Claude API × Python in Practice: Building an AI Assistant with Tool Calling and Streaming
A practical guide to combining Claude API's Tool Use and Streaming in Python. Build a working AI assistant with real tool execution, complete source code included, plus a breakdown of the tricky parts that trip up most developers.
Let Claude Diagnose Its Own Tool Errors — Building a Self-Correction Loop with the Anthropic API
Learn how to handle Tool Use failures gracefully by feeding error details back to Claude using the is_error flag, enabling self-diagnosis and automatic retry. Includes working Python code and production antipatterns to avoid.
The Real Cost of Claude API Extended Thinking in Production — ROI Data by Task Type
Three months of measured cost, quality, and speed data for Extended Thinking across five task categories. Learn exactly when extended thinking is worth it—and when it's not.
Building a 'Think-and-Search' AI Agent — Claude API Extended Thinking × Tool Use
A deep dive into combining Claude API Extended Thinking and Tool Use. Covers frequent errors, a complete research agent implementation in Python, plus cost estimation, timeout design, and error recovery for production use.
Implementing Usage-Based Billing with Claude API + Stripe: A Minimal Setup for Indie Developers
Learn how to measure Claude API token consumption and implement usage-based billing with Stripe Meter Events. A minimal Node.js setup that indie developers can ship in a weekend, with real gotchas from production.
Building an Offline-Capable AI Notes App with Claude API and Local-First Sync — A Production Design with Replicache and IndexedDB
A production design guide for combining Claude API with a local-first sync engine. Walks through Replicache, IndexedDB, mutation queues, and idempotency keys with full TypeScript code.
Cancelling Claude API Streams the Right Way: AbortController, Token Billing, and Connection Hygiene
I measured 100 cancelled Claude API streams to find out what actually gets billed. The drift numbers, the $18.70/month a missing close handler costs you, the proxy buffering trap, and a ledger that never loses a usage event — Node.js and Python.