anthropic
A Claude model through the Messages API.
anthropic("claude-sonnet-5") needs no limits: they come from spec/models/anthropic.v1.json, verified against the Anthropic Models API. Pass it as agent({model: anthropic("claude-sonnet-5")}). Prompt caching is on (5 minutes) unless prompt_cache is false; its info.cache declares the cache lifetime: {ttl_ms: 300000} for "5m", {ttl_ms: 3600000} for "1h", "none" for false.
Import from @threads/anthropic (TypeScript) or threads.anthropic (Python).
function anthropic(model: string, options?: {
maxInputTokens?: number;
maxOutputTokens?: number;
maxTokens?: number;
params?: JsonObject;
price?: Price;
hostedTools?: readonly JsonObject[];
promptCache?: "5m" | "1h" | false;
citations?: boolean;
apiKey?: string | Secret;
baseUrl?: string;
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
}): ModelParameters
modelstringrequiredThe provider's exact model id. Matched against spec/models/anthropic.v1.json by string equality only; a snapshot id keeps a long-lived thread on one model.
maxInputTokens / max_input_tokensnumberThe most input tokens one request may carry; compaction and the input billing bound use it. Pinned as policy.models[].context_window. Omitted: the catalog entry's value; a model id the catalog doesn't list needs it.
maxOutputTokens / max_output_tokensnumberThe most output tokens the model can produce in one response. Pinned in policy.models. Omitted: the catalog entry's value; a model id the catalog doesn't list needs it.
maxTokens / max_tokensnumberThe per-request output cap, pinned as params.max_tokens (the pinned prompt prefix) and sent as max_tokens. Output-token budgets read it. Omitted: min(8192, max_output_tokens); a long answer continues in a new request. Above max_output_tokens is invalid_config.
paramsJsonObjectOther Messages API request fields (temperature, reasoning and the like), pinned in the system prompt. A field the adapter derives from the render, or the cap, is invalid_config, and so is cache_control anywhere in it: prompt_cache is the one source of cache controls. Omitted: none.
pricePriceNano-currency units per token, pinned in policy.models; a cost budget needs it. With prompt caching on, a missing cache_write is derived from input (1.25 x for "5m", 2 x for "1h") and a missing cache_read as 0.1 x input, the highest documented read rate, both rounded up, so cost is never understated. Omitted: cost is unknown.
hostedTools / hosted_toolsreadonly JsonObject[]Provider-executed tools, sent as given and pinned in the system prompt: web search and web fetch (web_search_YYYYMMDD, web_fetch_YYYYMMDD) only; any other is hosted_tool_unsupported. cache_control inside one is invalid_config, and so is any hosted tool with prompt_cache "1h": Anthropic caches hosted tool results for 5 minutes, so writes would be billed at two rates. Omitted: none.
promptCache / prompt_cache"5m" | "1h" | falsedefault 5mPrompt caching, pinned in the system prompt as adapter setting prompt_cache: a breakpoint at the end of the system prompt (the system prompt, else the last tool) and automatic caching of the history, both with this lifetime. "1h" costs 2 x input per written token instead of 1.25 x. false sends no cache controls; it is also what continues a thread started before prompt caching existed. Omitted: "5m".
citationsbooleandefault falseEnables citations on every document in the request (an adapter setting, pinned in the system prompt). With a native structured-output field in params (output_format or output_config.format) it is invalid_config, as the provider refuses the pair; agent output (tool mode) is unaffected. Omitted: off.
apiKey / api_keystring | SecretThe API key: a secret() or a string. Omitted: secret("ANTHROPIC_API_KEY"). Resolved on the host at setup (check() or the first run); unset is missing_secret naming the option and the variable. Never pinned or logged.
baseUrl / base_urlstringThe API base URL. Omitted: the SDK's default endpoint.
fetch(input: string | URL | Request, init?: RequestInit) => Promise<Response>TypeScript only. Seam: the fetch the SDK sends through (a proxy, a test server); the run's fence wraps it either way. Omitted: globalThis.fetch.
Returns
Throws ConfigError with one of these codes: hosted_tool_unsupported, invalid_config, missing_secret.