Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

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()])


async def main() -> None:
    res = await ai.generate(
        model=Anthropic.claude('claude-sonnet-4-6'),
        prompt='Explain recursion in 10 words.',
    )
    print(res.text)
    # => A function that solves a problem by calling itself repeatedly.


if __name__ == '__main__':
    ai.run_main(main())

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
await ai.generate(
    model=Anthropic.claude('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'})
# Sent as: 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})
# Sent as: 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.14.0

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

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

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

Built distribution (wheel)

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

Total release size: 103.6 kB

Release files / genkit_anthropic-0.14.0.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL genkit_anthropic-0.14.0.tar.gz
Size 67.7 kB
Tags Source
SHA-256 checksum
How to use checksums
abb327558d5d1aaef282663e001e807d818357d9d26a6303c2a25d308d08cb1f
BLAKE2b-256 checksum
How to use checksums
84a7b79b2c07209b8880f7e32b3fa6fb47567fdf410978d80d4afb7b4a397f39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 19, 2026.

Transparency log

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

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL genkit_anthropic-0.14.0-py3-none-any.whl
Size 36.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52d8659bbdb90647d47df3f9e9d21e2a3dcf90837eef7cfc98a0cb5c38281d4d
BLAKE2b-256 checksum
How to use checksums
9b015a44288e1e41afd28b72ed32ec740d238899ed1a305cf8958c8a81eae9d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 19, 2026.

Transparency log

Security for genkit-anthropic 0.14.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.

Change of provenance

The repository and configuration that created this release differ from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for genkit_anthropic-0.14.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 19, 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