Repository navigation
feat(py/anthropic): explore AmazonBedrock backend for Anthropic - #261
Closed
huangjeff5 wants to merge 2 commits into
Closed
huangjeff5 wants to merge 2 commits into
huangjeff5 wants to merge 2 commits into
Conversation
This was referenced Nov 30, 2026
… HEAD # Conflicts: # packages/genkit-anthropic/pyproject.toml # uv.lock
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an
AmazonBedrock(region=..., profile=...)backend togenkit-anthropic(behind thegenkit-anthropic[amazon-bedrock]extra) so Claude callers on AWS can use the native Anthropic Messages API (AsyncAnthropicBedrock) and fullAnthropicConfig(adaptive thinking,effort,task_budget, prompt caching) instead of Bedrock Converse's lowest-common-denominatorBedrockConfig.What Fit Cleanly vs. Real Friction Found
Backendseam mostly held with zero core changes: AddingAmazonBedrock+AmazonBedrockBackendtook one self-contained module (_amazon_bedrock.py), theamazon-bedrockextra (anthropic[bedrock]>=0.96.0,<1), and a dispatch arm in_backend_for. LikeGoogleCloud, no backend types are exported fromgenkitcore.claude-sonnet-4-6), Bedrock Runtime requires Bedrock model IDs or cross-region inference-profile IDs (global.anthropic.claude-sonnet-4-6,us.anthropic.claude-sonnet-4-5-20250929-v1:0,global.anthropic.claude-opus-4-6-v1with per-model suffixes). We addedBackend.include_static_catalog = Falsesolist_actions()doesn't advertise bareclaude-*IDs in the Dev UI that 400 on Bedrock; note thatget_model_info()also falls back toDEFAULT_SUPPORTS(prompt-based JSON instead ofConstrainedSupport.ALL) for Bedrock-formatted IDs.AsyncAnthropicBedrocksilently defaults tous-east-1and blocks on boto3 auth: The SDK's_infer_region()silently falls back tous-east-1, and_prepare_request()callsboto3.Session().get_credentials()synchronously on the event loop, raising a rawRuntimeErrorwhen credentials are missing (which Retry middleware would treat as transient). Preflighting inasyncio.to_thread(load_aws_context, ...)enforces an explicit region (matchinggenkit-amazon-bedrock) and turns missing profiles/credentials intoFAILED_PRECONDITION.AsyncAnthropicBedrock.beta.messageshas no.stream()method: Inanthropic==0.112.0,AsyncAnthropicandAsyncAnthropicVertexexposebeta.messages.stream(), butAsyncAnthropicBedrock.beta.messagesexposescreate()only.AnthropicModel._generate_streaming()now falls back tomessages.stream()withextra_headers={'anthropic-beta': ...}, whichAsyncAnthropicBedrock._prepare_options()turns intoanthropic_betain the InvokeModel JSON body.genkit-amazon-bedrockrather than replacing it: Unlikegenkit-vertexai(which only wrappedAsyncAnthropicVertexandAsyncOpenAIand can be deprecated in feat(py): deprecate genkit-vertexai; remove it in the next release #260),genkit-amazon-bedrockcovers Bedrock Converse (Nova, Llama, Mistral, Cohere, DeepSeek), Stability images, and Titan/Cohere embedders.Anthropic(backend=AmazonBedrock(...))gives Claude users native Anthropic features on AWS billing.Open Questions to Decide Before Moving Past Exploration
bedrock-runtime(AsyncAnthropicBedrock) vs. Bedrock Mantle (AsyncAnthropicBedrockMantle):anthropic==0.112.0already shipsAsyncAnthropicBedrockMantle(https://bedrock-mantle.{region}.api.aws/anthropic), which uses standard/v1/messages+ SSE, hasbeta.messages.stream(), and accepts cleaneranthropic.<model>IDs without regional inference-profile suffixes. ShouldAmazonBedrocktargetbedrock-runtime(broader regional/model availability today), Mantle, or distinguish the two?AmazonBedrockstay strictly pass-through (Anthropic.claude('global.anthropic.claude-sonnet-4-6')), or normalize Bedrock Claude IDs inget_model_info()so native structured outputs (ConstrainedSupport.ALL) work without passingextra?AWS_BEARER_TOKEN_BEDROCK): Right now top-levelAnthropic(backend=AmazonBedrock(), api_key=...)is rejected (mirroringGoogleCloud), whileAWS_BEARER_TOKEN_BEDROCKandclient_options={'api_key': ...}work without boto3 SigV4. Shouldapi_key=stay rejected (to avoid confusion withANTHROPIC_API_KEY) or accept a Bedrock bearer token?_prepare()catches missing/broken creds before the first call, but if short-lived STS/SSO credentials expire hours later during_prepare_request(),AsyncAnthropicBedrockwill still raise rawRuntimeError/BotoCoreError. If we ship this,Backendlikely needs an optional error-mapping hook so_models.pystays boto3-free while still mapping mid-run AWS auth failures cleanly.OpenAICompatible(backend=AmazonBedrock(...))? AWS Bedrock Mantle also exposes an OpenAI-compatible endpoint (https://bedrock-mantle.{region}.api.aws/openai/v1). Worth deciding separately whetherOpenAICompatiblewants anAmazonBedrockbackend for Mantle alongsidegenkit-amazon-bedrock.Verification
uv run --no-sync pytest packages/genkit-anthropic/ tests/version_bounds_guard_test.py(489 passed, 5 live skipped)uv run --no-sync ruff format --check --preview packages/genkit-anthropic/uv run --no-sync ruff check --preview packages/genkit-anthropic/uv run --no-sync ty check .uv run --no-sync pyrefly checkpython3 scripts/check_consistency.pyanduv lock --check