Skip to main content

Anthropic LLM

AnthropicLLM plugs Anthropic’s Claude models into Patter’s pipeline mode. It speaks the Messages API natively (streaming + tool_use blocks) and normalises every event into Patter’s unified {type: "text" | "tool_call" | "done"} chunk protocol, so tools defined once run across every LLM provider. Prompt caching is enabled by default. The system prompt and the last tool block are tagged with cache_control: { type: "ephemeral" }, which cuts time-to-first-token by ~100-400 ms and ~90% of input-token cost on every cached turn.

Install

Usage

The namespaced import (import * as anthropic from "getpatter/llm/anthropic" / from getpatter.llm import anthropic) auto-resolves the API key from ANTHROPIC_API_KEY and exposes a uniform LLM class — the same pattern Patter uses for STT and TTS namespaces.
Plug it into an agent:

Supported models

Pricing in USD per 1M tokens. cache_read is billed at ~10% of full input; cache_write at ~125%. Versioned snapshots (e.g. claude-haiku-4-5-20251001) resolve against the base entry via longest-prefix match in pricing.ts. Aliases that route to the latest snapshot: claude-haiku-4-5, claude-sonnet-4-6, claude-opus-4-7, claude-3-5-sonnet-latest, claude-3-5-haiku-latest. Pinned snapshots include claude-haiku-4-5-20251001, claude-3-5-sonnet-20241022, claude-3-5-haiku-20241022.

Environment variables

Options

Prompt caching

For voice agents with long instruction-dense system prompts and large tool catalogs, prompt caching is the single biggest TTFT win Anthropic ships. Patter applies the recommended pattern automatically:
  • The system prompt becomes a single text block tagged cache_control: ephemeral.
  • The last tool definition is tagged cache_control: ephemeral, which caches the entire tool array (Anthropic caches everything up to and including a marked block).
  • The anthropic-beta: prompt-caching-2024-07-31 header is sent on every request for consistent behaviour across model snapshots.
The cache lives ~5 minutes — the first request writes it, subsequent requests within that window hit it for ~90% input-token savings on the cached portion.