Skip to main content

Anthropic Plugin

The @genkit-ai/anthropic plugin provides access to Anthropic’s Claude models, including the latest Claude 4.5 series (Haiku, Sonnet, Opus). This plugin is now officially maintained by Google and supersedes the earlier community package genkitx-anthropic.

Installation

Or with other package managers:

Supported Models

The plugin supports the most recent Anthropic models:
  • Claude Haiku 4.5 (claude-haiku-4-5) - Fast, cost-effective
  • Claude Sonnet 4.5 (claude-sonnet-4-5) - Balanced performance
  • Claude Opus 4.5 (claude-opus-4-5) - Most capable
Plus all non-retired older models including Claude 3.5 and 3.0 series.

Basic Setup

Initialize the Plugin

Simple Text Generation

Features

Multi-modal Prompts

Claude supports text and image inputs:

Extended Thinking

Claude 4.5 models can expose their internal reasoning process:
When thinking is enabled:
  • Request bodies include the thinking payload
  • Streamed responses deliver reasoning parts incrementally
  • You can render the chain-of-thought as it arrives

Document Citations

Claude can cite specific parts of documents, making it easy to trace information sources. Use the anthropicDocument() helper:
Important: Citations must be enabled on all documents in a request, or on none. You cannot mix cited and non-cited documents. Supported document source types:
  • text - Plain text (returns char_location citations)
  • base64 - Base64-encoded PDFs (returns page_location citations)
  • url - PDFs via URL (returns page_location citations)
  • content - Custom content blocks (returns content_block_location citations)
  • file - Anthropic Files API references, beta only (returns page_location citations)

Prompt Caching

Cache prompts to reduce costs and latency for repeated requests:
Cache control options:
Note: Caching only activates when prompts exceed a minimum token length. See Anthropic API documentation for details.

Using in Flows

Direct Model Usage (Plugin API v2)

The plugin supports using models directly without initializing the full Genkit framework:
Multiple model references:
This approach is useful for:
  • Framework developers needing raw model access
  • Testing models in isolation
  • Using Genkit models in non-Genkit applications

Beta API Limitations

The beta API provides access to experimental features, but some server-managed tool blocks are not yet supported: Not supported:
  • web_fetch_tool_result
  • code_execution_tool_result
  • bash_code_execution_tool_result
  • text_editor_code_execution_tool_result
  • mcp_tool_result
  • mcp_tool_use
  • container_upload
Supported:
  • server_tool_use
  • web_search_tool_result
These work with both stable and beta APIs.

Configuration Options

Plugin Options

Model Config

Best Practices

Model Selection

  • Claude Haiku 4.5 - Use for fast, cost-effective tasks
  • Claude Sonnet 4.5 - Best for most production use cases
  • Claude Opus 4.5 - Use for complex reasoning and research

Error Handling

Streaming Responses

Acknowledgements

This plugin builds on community work published as genkitx-anthropic by Bloom Labs Inc. Their Apache 2.0-licensed implementation provided the foundation for this maintained package.