← Back to all entries
2025-12-28 ✅ Best Practices

Claude API Patterns That Defined 2025

Claude API Patterns That Defined 2025 — visual for 2025-12-28

Prompt Caching — The Single Biggest Cost Reduction Available in 2025

If there is one API feature that changed how serious Claude applications are built in 2025, it is prompt caching. By marking large, stable portions of your prompt with cache_control: {"type": "ephemeral"}, you instruct Anthropic's infrastructure to retain the computed key-value (KV) state for that section. Subsequent requests that hit the same cached prefix are served at roughly 10% of the normal input token cost and with lower latency. For applications with large system prompts, document corpora, or few-shot example libraries, the savings compound quickly.

Where caching has the most impact

messages.create(
    model="claude-sonnet-4-6",
    system=[
        {
            "type": "text",
            "text": "You are a code review assistant...",
            "cache_control": {"type": "ephemeral"}  # cache this
        }
    ],
    messages=[{"role": "user", "content": user_query}]
)
Cache lifetime

The ephemeral cache lives for approximately 5 minutes of inactivity. For chatbots with sporadic users, you may not capture the savings — caching shines most in high-throughput, batch-style, or session-based applications.

prompt caching cost optimisation API best practices retrospective

Structured Outputs & Tool Use — The Pattern That Unlocked Production Reliability

2025 was the year developers stopped fighting Claude's tendency to produce free-form text and started channelling it. The combination of tool use (forcing Claude to return a structured JSON payload by invoking a defined function) and JSON mode (constraining the output to a schema) has become the de-facto standard for any Claude integration that feeds downstream code. Applications built on this pattern are fundamentally more reliable than those that parse natural-language responses — and they are far easier to test.

The canonical pattern

Anti-pattern to avoid

Don't ask Claude to "respond only in JSON" via the system prompt without defining a tool. Claude will usually comply, but the output is not guaranteed to be valid JSON, and you lose the type safety that tool definitions provide. Always prefer explicit tool definitions over system-prompt constraints for machine-readable output.

tool use structured outputs reliability best practices retrospective