Skip to main content

Genkit Anthropic Plugin

Anthropic Claude model provider for Genkit.

Building with a coding agent? Install the Genkit Python skill first.

npx skills add genkit-ai/skills --skill developing-genkit-python

It teaches your agent the current Genkit Python APIs and common gotchas. Source, manual install and skills for other languages: genkit-ai/skills.

Installation

uv add genkit-anthropic

Usage

from genkit import Genkit
from genkit_anthropic import Anthropic

ai = Genkit(plugins=[Anthropic()])

res = await ai.generate(
    model=Anthropic.claude('claude-sonnet-4-6'),
    prompt='Explain recursion in 10 words.',
)
print(res.text)

Set ANTHROPIC_API_KEY in the environment, or pass api_key= to Anthropic(). base_url= points the plugin at another server. Pass the origin with no /v1 suffix; the SDK appends /v1/messages. Any other AsyncAnthropic setting goes in client_options:

Anthropic(
    api_key=key,
    base_url='https://claude-proxy.example.com',
    client_options={'timeout': 30, 'max_retries': 5, 'default_headers': {'X-Team': 'search'}},
)

Typed config

AnthropicConfig is flat. Choices are exported Literals (ThinkingMode, ThinkingDisplay, Effort), so pyright, pyrefly and ty check every key and value. The plugin builds Anthropic's nested request objects from the flat fields:

  • thinking, thinking_budget, thinking_display → thinking
  • effort, task_budget → output_config
  • user_id → metadata
from genkit_anthropic import AnthropicConfig

# 1. Build the config from flat fields
config = AnthropicConfig(
    max_output_tokens=4096,
    thinking='adaptive',
    thinking_display='summarized',
    effort='high',
    task_budget=20000,
    user_id='diner-42',
)

# 2. Generate with it
res = await ai.generate(model='anthropic/claude-opus-4-6', prompt='Plan a tasting menu.', config=config)
# Sent as:
#   thinking={'display': 'summarized', 'type': 'adaptive'}
#   output_config={'effort': 'high', 'task_budget': {'type': 'tokens', 'total': 20000}}
#   metadata={'user_id': 'diner-42'}
  • A thinking_budget alone means thinking='enabled'. 'enabled' needs a budget from some config layer; 'adaptive' doesn't send one, and 'disabled' sends neither the budget nor the display.
  • task_budget is a beta field, so it sends the call to the beta API.
  • To send a shape the flat fields don't cover, put Anthropic's object in extra, e.g. extra={'thinking': {...}}. It replaces the built object.

Defaults and overrides

Config merges key by key: the Anthropic.claude(config=...) default, then the prompt's config, then the call's. Rules that span fields are checked once, on the merged config. thinking is the switch, so a call can turn thinking off or back on without restating the budget:

# 1. Model default with extended thinking on
claude = Anthropic.claude('claude-sonnet-4-6', config=AnthropicConfig(thinking='enabled', thinking_budget=4096))

# 2. Turn it off for one call; the inherited budget isn't sent
await ai.generate(model=claude, prompt='Is shellfish safe for this guest?', config={'thinking': 'disabled'})
# => thinking={'type': 'disabled'}

# 3. Raise the budget for another; the mode is inherited
await ai.generate(model=claude, prompt='Plan a nut-free tasting menu.', config={'thinking_budget': 8192})
# => thinking={'type': 'enabled', 'budget_tokens': 8192}

A budget over an inherited thinking='disabled' stays disabled. Pass thinking='enabled' to turn it on, or thinking=None to clear the inherited mode. None clears any inherited value the same way.

Tool choice

Tool choice is Genkit's tool_choice option, not a config field. The plugin sends it as Anthropic's tool_choice object: 'auto' → {'type': 'auto'}, 'required' → {'type': 'any'}, 'none' → {'type': 'none'}. Anthropic carries disable_parallel_tool_use inside that object, so the config takes it as a flat flag:

# 1. Require one tool call, and only one
res = await ai.generate(
    model='anthropic/claude-sonnet-4-6',
    prompt='Is the pho in stock?',
    tools=['lookup_menu'],
    tool_choice='required',
    config=AnthropicConfig(disable_parallel_tool_use=True),
    return_tool_requests=True,
)
# Sent as: tool_choice={'type': 'any', 'disable_parallel_tool_use': True}

To pin one named tool, send Anthropic's object as extra={'tool_choice': {'type': 'tool', 'name': 'lookup_menu'}}; it replaces the translated value.

With thinking='enabled' or 'adaptive', Anthropic accepts only 'auto' and 'none', so tool_choice='required' raises INVALID_ARGUMENT before the request goes out. On a request with no tools, tool_choice (option or extra) is dropped, since the API rejects it there.

Per-request API key

To bill a call to someone else's Anthropic account, pass their key in context.secrets. It's used for that call only:

res = await ai.generate(
    model='anthropic/claude-sonnet-4-6',
    prompt='hi',
    context={'secrets': {'api_key': tenant_key}},
)
  • apiKey works as well as api_key. Other entries in context.secrets are left alone, so a call whose secrets hold no key runs on the plugin's key. A key that is blank or not a string raises INVALID_ARGUMENT.
  • A key in config or config.extra raises INVALID_ARGUMENT; config is recorded in traces.
  • The plugin doesn't need a key of its own: Anthropic() with no ANTHROPIC_API_KEY serves every call that brings a key in context.secrets, and a call without one fails with FAILED_PRECONDITION.
  • A client whose credential can't be swapped refuses a tenant key with FAILED_PRECONDITION rather than billing its own account: an Anthropic(client_options={'auth_token': ...}) client, one whose default_headers pin x-api-key or Authorization, and Claude on Vertex AI Model Garden, which authenticates with Google Cloud credentials.

Disclaimer

Use of Anthropic's API is subject to Anthropic's Terms of Service and Privacy Policy. You are responsible for complying with all applicable terms when using this plugin.

  • API Key Security — Never commit your Anthropic API key to version control. Use environment variables or a secrets manager.
  • Usage Limits — Be aware of your Anthropic plan's rate limits and token quotas. See Anthropic Pricing.
  • Data Handling — Review Anthropic's data processing practices before sending sensitive or personally identifiable information.

License

Apache-2.0

Metadata

Release files for genkit-anthropic 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genkit-anthropic 0.13.0
File Size Uploaded Provenance Actions
genkit_anthropic-0.13.0.tar.gz 63.6 kB With provenance Details for genkit_anthropic-0.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for genkit-anthropic 0.13.0
File Interpreter ABI Platform Actions
genkit_anthropic-0.13.0-py3-none-any.whl Python 3 none any Details for genkit_anthropic-0.13.0-py3-none-any.whl

Total release size: 99.0 kB

Release files / genkit_anthropic-0.13.0.tar.gz

Download URL genkit_anthropic-0.13.0.tar.gz
Size 63.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3f38adfaa9447d915895490b9a0c5cc1b0b2c734279f09e9c8356dce98cf77f7
BLAKE2b-256 checksum
How to use checksums
0c13397a60500844829dc5851a25cd272a2ab4f58135aa049139d47e7c1906ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / genkit_anthropic-0.13.0-py3-none-any.whl

Download URL genkit_anthropic-0.13.0-py3-none-any.whl
Size 35.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0edc703928f9ecf9a9c6a52cca22272b23eb4e40d87e9d7b85d33c15804e26ad
BLAKE2b-256 checksum
How to use checksums
d09e215c7a8d29a0e7738d60dda0a42bbc1e13433463ccfd362a15171193b49b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for genkit-anthropic 0.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for genkit_anthropic-0.13.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page