Anthropic
The Messages API with adaptive thinking, tool use, vision, and prompt caching.
let model = AnthropicModel("claude-fable-5") // or claude-sonnet-5Key from ANTHROPIC_API_KEY; base URL https://api.anthropic.com/v1.
Features
- Tools, vision, and PDF documents as message parts.
- Structured output rides a forced tool call — Claude has no JSON mode,
so
generateObjectdefines a tool whose arguments are your schema and forces the model to call it. - Thinking streams as
.reasoningDelta; thereasoningparameter translates per model tier (below). usage.cachedInputTokensis populated on prompt-cache hits;result.providerMetadata["anthropic"]["cacheCreationInputTokens"]reports tokens written to the cache.- Anthropic-native fields (
thinking, cache-control blocks) go throughproviderOptionsand win over anything the library sets.
Server-side tools
Anthropic's built-in tools have typed builders under
AnthropicModel.Tools — webSearch, webFetch, codeExecution,
bash, textEditor, computer(displayWidthPx:displayHeightPx:), and
memory. Pass them in tools:; the required anthropic-beta flags are
added to the request for you:
let result = try await generateText(
model: AnthropicModel("claude-sonnet-5"),
prompt: "Search the web and summarize what's new.",
tools: [AnthropicModel.Tools.webSearch(maxUses: 3)]
)Each builder takes a version: for the dated tool variants
(web_search_20250305, computer_20250124, ...); the defaults track
the current stable release. Newer versions are wired too, with their beta
headers: web_search_20260318, web_fetch_20260318 / 20260309,
code_execution_20260521 / 20260120 / 20250825, computer_20251124,
plus advisor, toolSearchBm25 / toolSearchRegex, and mcpToolset for
the MCP connector. The three current code-execution versions are GA and need
no beta header; code_execution_20250522 is the legacy Python-only build and
is no longer the default.
Tool definition properties
Anthropic accepts optional properties on any tool — built-in or your own.
Tool.loading(_:) carries them:
let deleteFile = Tool(name: "deleteFile", description: …, parameters: …) { … }
.loading(ToolLoading(
strict: true, // validate names and inputs
deferLoading: true, // keep out of the cached prompt
allowedCallers: ["code_execution_20260120"], // sandbox-only
eagerInputStreaming: true // fine-grained input streaming
)).ephemeralCache() sets a cache_control breakpoint at the tool definition,
and .codeExecutionOnly() is shorthand for the sandbox-only caller list. It
defaults to code_execution_20260120, the caller Anthropic documents for
programmatic tool calling — the same value web_search_20260209 and later
default to. That is deliberately not the version Tools.codeExecution()
sends by default (code_execution_20260521): if you want the model to call
your tool from inside the sandbox, declare
Tools.codeExecution(version: "code_execution_20260120") so the caller
matches. Pass codeExecutionOnly(version:) to pin a different one.
defer_loading keeps a tool out of the cached system-prompt prefix until
tool search surfaces it, so adding deferred tools does not invalidate an
existing prompt cache.
A tool's inputExamples are sent natively as input_examples here, so the
description stays clean — the
addToolInputExamples middleware is only needed for
providers with no native field.
Platform APIs
AnthropicBatchClient— Message Batches:create,list,get,results(streamed JSONL, decoded per line),cancel,delete.AnthropicModelsClient—listandgetfor the model catalog.AnthropicModel.countTokens(_:tools:system:)— pre-flight sizing against/v1/messages/count_tokens, with the same beta headers your tools require.
Models
| Models | Output ceiling | reasoning becomes |
|---|---|---|
| Sonnet 5, Fable 5, Opus 4.7 / 4.8 | 128k | Adaptive thinking + output_config.effort, up to xhigh |
| Sonnet 4.6, Opus 4.6 | 128k | Adaptive thinking (xhigh coerces to max) |
| Sonnet 4.5, Opus 4.5, Haiku 4.5, Sonnet 4.x | 64k | thinking.budget_tokens from the ceiling |
| Opus 4.1, Opus 4.x | 32k | thinking.budget_tokens from the ceiling |
| Anything else | 4,096 | thinking.budget_tokens, conservative ceiling |
.none sends thinking.type: "disabled" explicitly, and max_tokens
is raised automatically when a budget would not fit.
Current lineup
Snapshot from July 2026, newest first. Anthropic's native ids use
dashes (claude-opus-4-8); date-stamped variants
(claude-sonnet-4-5-20250929) work too.
| Model | Released |
|---|---|
claude-fable-5 | July 2026 |
claude-sonnet-5 | June 2026 |
claude-opus-4-8 | May 2026 |
claude-opus-4-7 | April 2026 |
claude-sonnet-4-6, claude-opus-4-6 | February 2026 |
claude-opus-4-5 | November 2025 |
claude-haiku-4-5 | October 2025 |
claude-sonnet-4-5 | September 2025 |
claude-opus-4-1, claude-sonnet-4 | 2025 |
claude-3-5-haiku | Budget tier |
Files and skills
These resource clients are documented in Files and skills.
let upload = try await AnthropicFiles().upload(
data: pdf, filename: "report.pdf", mediaType: "application/pdf"
)
let skill = try await AnthropicSkills().upload(
files: [SkillFile(path: "brand-guide/SKILL.md", data: skillMD)],
displayTitle: "Brand guide"
)Beta headers are handled for you on both.