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.py

See 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.

ModelUse Case
claude-sonnet-4-5-20250929Balanced speed and intelligence
claude-opus-4-5Complex agentic coding and enterprise work
claude-haiku-4-5-20251001Fast, cost-sensitive workloads
claude-sonnet-4-6Long-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

InputAgno Support
TextText input and text output
ImagesJPEG, PNG, GIF, and WebP from a URL, local path, or bytes. Anthropic analyzes only the first frame of an animated GIF.
PDFsPDF documents from a URL, local path, bytes, or Anthropic file ID
Text documentsUTF-8 content, including .txt, .csv, and .md, from a URL, local path, bytes, or Anthropic file ID
Audio and videoUnsupported. 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

ParameterTypeDefaultDescription
idstr"claude-sonnet-4-5-20250929"Anthropic Claude model ID
namestr"Claude"Model name
providerstr"Anthropic"Model provider
max_tokensOptional[int]8192Maximum output tokens. Agno sends only truthy values, so Anthropic's 0-token cache pre-warming is unavailable through this adapter.
thinkingOptional[Dict[str, Any]]NoneModel-specific thinking configuration
output_configOptional[Dict[str, Any]]NoneAnthropic output configuration, such as {"effort": "medium"}. Structured outputs merge the generated schema into format while preserving other settings.
temperatureOptional[float]NoneSampling temperature when supported by the selected model
stop_sequencesOptional[List[str]]NoneStrings that stop generation
top_pOptional[float]NoneNucleus-sampling value when supported by the selected model
top_kOptional[int]NoneTop-k sampling value when supported by the selected model
cache_system_promptOptional[bool]FalseAdd cache control to the agent-built system prompt
extended_cache_timeOptional[bool]FalseUse a one-hour cache TTL instead of the default five minutes
cache_toolsboolFalseAdd cache control to the last tool definition
system_prompt_blocksOptional[Union[List[SystemPromptBlock], Callable[[], List[SystemPromptBlock]]]]NoneSystem-prompt blocks with per-block cache controls. A callable is evaluated for each request.
request_paramsOptional[Dict[str, Any]]NoneAdditional Anthropic request parameters. These are applied after the dedicated fields above.
betasOptional[List[str]]NoneExact Anthropic beta names sent through the SDK's beta Messages API
context_managementOptional[Dict[str, Any]]NoneAnthropic context-management request body. Add the beta required by the selected strategy to betas.
mcp_serversOptional[List[MCPServerConfiguration]]NoneRemote 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.
skillsOptional[List[Dict[str, str]]]NoneAgent 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.
citationsboolTrueAttach 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_messageOptional[bool]NoneAppend 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_contentstr"continue"Content of the appended user message
api_keyOptional[str]NoneAnthropic API key. Falls back to ANTHROPIC_API_KEY.
auth_tokenOptional[str]NoneAnthropic auth token. Falls back to ANTHROPIC_AUTH_TOKEN.
default_headersOptional[Dict[str, Any]]NoneDefault headers for every request
timeoutOptional[float]NoneRequest timeout in seconds
http_clientOptional[Union[httpx.Client, httpx.AsyncClient]]NoneCustom synchronous or asynchronous HTTPX client
client_paramsOptional[Dict[str, Any]]NoneAdditional Anthropic client constructor parameters
clientOptional[AnthropicClient]NonePreconfigured synchronous Anthropic client
async_clientOptional[AsyncAnthropicClient]NonePreconfigured asynchronous Anthropic client

Claude is a subclass of the Model class and supports the inherited model parameters.