Anthropic Claude
Use Anthropic Claude models with Agno agents.
Install the Anthropic model extra, set an API key, and pass Claude to an Agent.
Installation
uv pip install -U "agno[anthropic]"Authentication
Set the ANTHROPIC_API_KEY environment variable. Create a key in the Claude Console.
export ANTHROPIC_API_KEY="your_anthropic_api_key"Example
from agno.agent import Agent
from agno.models.anthropic import Claude
agent = Agent(
model=Claude(id="claude-sonnet-4-5-20250929"),
markdown=True,
)
if __name__ == "__main__":
agent.print_response("Write a two-sentence horror story.")Save the example as agent.py, then run:
python agent.pySee the basic usage guide for the complete environment setup.
Model Selection
Claude defaults to claude-sonnet-4-5-20250929. Pass another model ID with Claude(id=...) when a different capability or latency profile fits the use case.
| Model | Use Case |
|---|---|
claude-sonnet-4-5-20250929 | Balanced speed and intelligence |
claude-opus-4-5 | Complex agentic coding and enterprise work |
claude-haiku-4-5-20251001 | Fast, cost-sensitive workloads |
claude-sonnet-4-6 | Long-running agent workflows |
See Anthropic's current model comparison and model lifecycle table before deploying a pinned model.
Claude 4.5 model IDs use dated snapshots. Shorter names such as
claude-sonnet-4-5 are aliases. Starting with Claude 4.6, dateless IDs such
as claude-sonnet-4-6 are canonical pinned versions, not rolling aliases.
Supported Input
| Input | Agno Support |
|---|---|
| Text | Text input and text output |
| Images | JPEG, PNG, GIF, and WebP from a URL, local path, or bytes. Anthropic analyzes only the first frame of an animated GIF. |
| PDFs | PDF documents from a URL, local path, bytes, or Anthropic file ID |
| Text documents | UTF-8 content, including .txt, .csv, and .md, from a URL, local path, bytes, or Anthropic file ID |
| Audio and video | Unsupported. The adapter omits these inputs and logs a warning. |
Agno sends image URLs to Anthropic as base64 data after downloading them. Anthropic's request-size, image-size, page-count, and model limits still apply. See the vision limits and PDF limits.
Request Limits
The Messages API requires max_tokens. Agno sends 8192 unless max_tokens is set on Claude. Anthropic also accepts 0 for prompt-cache pre-warming, but Agno omits that falsy value; use a positive value with this adapter. See the Messages API reference.
Anthropic also applies organization and workspace rate limits. See the rate-limit documentation.
Beta Features
Pass exact Anthropic beta names with betas. Features that add request fields also need their matching Agno parameters. This context-editing configuration sends both the required beta and request body:
from agno.agent import Agent
from agno.models.anthropic import Claude
agent = Agent(
model=Claude(
id="claude-sonnet-4-5-20250929",
betas=["context-management-2025-06-27"],
context_management={
"edits": [{"type": "clear_tool_uses_20250919"}],
},
),
)See beta features with Claude and context editing.
Prompt Caching
Set cache_system_prompt=True to add a prompt-cache breakpoint to the agent's system prompt:
from agno.agent import Agent
from agno.models.anthropic import Claude
agent = Agent(
model=Claude(
id="claude-sonnet-4-5-20250929",
cache_system_prompt=True,
),
)See prompt caching with Claude.
Structured Outputs
Pass a Pydantic model as output_schema to use Claude's native structured outputs. Select a supported model from the Claude 4.5 families or later, checking Anthropic's current compatibility and lifecycle tables below.
Agno merges the generated JSON schema into output_config.format, preserving
other output settings such as effort. It also adds the
structured-outputs-2025-11-13 beta header automatically.
from agno.agent import Agent
from agno.models.anthropic import Claude
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
email: str
agent = Agent(
model=Claude(id="claude-sonnet-4-5-20250929"),
description="Extract user information.",
output_schema=User,
)See Anthropic's structured-output compatibility and the Agno guides:
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "claude-sonnet-4-5-20250929" | Anthropic Claude model ID |
name | str | "Claude" | Model name |
provider | str | "Anthropic" | Model provider |
max_tokens | Optional[int] | 8192 | Maximum output tokens. Agno sends only truthy values, so Anthropic's 0-token cache pre-warming is unavailable through this adapter. |
thinking | Optional[Dict[str, Any]] | None | Model-specific thinking configuration |
output_config | Optional[Dict[str, Any]] | None | Anthropic output configuration, such as {"effort": "medium"}. Structured outputs merge the generated schema into format while preserving other settings. |
temperature | Optional[float] | None | Sampling temperature when supported by the selected model |
stop_sequences | Optional[List[str]] | None | Strings that stop generation |
top_p | Optional[float] | None | Nucleus-sampling value when supported by the selected model |
top_k | Optional[int] | None | Top-k sampling value when supported by the selected model |
cache_system_prompt | Optional[bool] | False | Add cache control to the agent-built system prompt |
extended_cache_time | Optional[bool] | False | Use a one-hour cache TTL instead of the default five minutes |
cache_tools | bool | False | Add cache control to the last tool definition |
system_prompt_blocks | Optional[Union[List[SystemPromptBlock], Callable[[], List[SystemPromptBlock]]]] | None | System-prompt blocks with per-block cache controls. A callable is evaluated for each request. |
request_params | Optional[Dict[str, Any]] | None | Additional Anthropic request parameters. These are applied after the dedicated fields above. |
betas | Optional[List[str]] | None | Exact Anthropic beta names sent through the SDK's beta Messages API |
context_management | Optional[Dict[str, Any]] | None | Anthropic context-management request body. Add the beta required by the selected strategy to betas. |
mcp_servers | Optional[List[MCPServerConfiguration]] | None | Remote MCP server configurations. The legacy connector uses mcp-client-2025-04-04; the current mcp-client-2025-11-20 contract also requires MCP toolsets in tools. Follow the connector migration instead of changing only the header. |
skills | Optional[List[Dict[str, str]]] | None | Agent Skills to load, such as [{"type": "anthropic", "skill_id": "pptx", "version": "latest"}]. Agno adds the Skills beta, the legacy code-execution beta, and the code_execution_20250825 tool. |
citations | bool | True | Attach citations to URL, local, and bytes document blocks. Agno omits citations from Anthropic file-ID blocks and suppresses them when structured output is active. |
append_trailing_user_message | Optional[bool] | None | Append a user turn when a conversation ends with an assistant message. When unset, Agno enables this if the model does not support assistant prefill or effective thinking is enabled. request_params["thinking"] overrides the dedicated thinking field; an explicit value for this option is respected. |
trailing_user_message_content | str | "continue" | Content of the appended user message |
api_key | Optional[str] | None | Anthropic API key. Falls back to ANTHROPIC_API_KEY. |
auth_token | Optional[str] | None | Anthropic auth token. Falls back to ANTHROPIC_AUTH_TOKEN. |
default_headers | Optional[Dict[str, Any]] | None | Default headers for every request |
timeout | Optional[float] | None | Request timeout in seconds |
http_client | Optional[Union[httpx.Client, httpx.AsyncClient]] | None | Custom synchronous or asynchronous HTTPX client |
client_params | Optional[Dict[str, Any]] | None | Additional Anthropic client constructor parameters |
client | Optional[AnthropicClient] | None | Preconfigured synchronous Anthropic client |
async_client | Optional[AsyncAnthropicClient] | None | Preconfigured asynchronous Anthropic client |
Claude is a subclass of the Model class and supports the inherited model parameters.