Advanced Tool Use & Agent Engineering

Running the Agent SDK on Amazon Bedrock

One environment variable points the Claude Agent SDK's loop at Bedrock instead of Anthropic — after which your existing AWS credentials, IAM policies, and billing take over. The details live in the credential chain, the Mantle flag, and one missing tool.

Claude 3P 101 · Updated July 2026 · Unofficial guide

The Claude Agent SDK — the library form of Claude Code's agent loop — doesn't care where its model tokens come from. Set CLAUDE_CODE_USE_BEDROCK=1 and every model call the loop makes routes to Amazon Bedrock in your AWS account, authenticated with AWS credentials rather than an Anthropic API key. The agent still runs in your process with local JSONL session state (see Agent SDK vs. Managed Agents); only the inference endpoint moves. This shares configuration with Claude Code itself, which also offers a /setup-bedrock login wizard and, from v2.1.94, a startup model check.

How credentials and region resolve

There is no Claude-specific auth. The SDK uses the default AWS SDK credential chain — CLI configuration, access keys, an SSO profile, aws login, or a Bedrock API key supplied as AWS_BEARER_TOKEN_BEDROCK. Whatever your other AWS workloads use will work here, which is precisely the appeal for enterprises: agent traffic is authorized, audited, and billed like any other Bedrock workload, with no Anthropic API key to provision or rotate. Region resolution (v2.1.172+) follows a documented order: AWS_REGIONAWS_DEFAULT_REGION → the active AWS profile's region → fallback us-east-1. Worth pinning explicitly in containers and CI runners, where a missing region variable silently lands you in us-east-1 — a confusing failure if your model access or inference profiles live elsewhere.

Model selection is also env-var driven: ANTHROPIC_MODEL plus ANTHROPIC_DEFAULT_OPUS_MODEL / ANTHROPIC_DEFAULT_SONNET_MODEL / ANTHROPIC_DEFAULT_HAIKU_MODEL, taking cross-region inference profile IDs (e.g. us.anthropic.claude-opus-4-8, with a us-gov. prefix in GovCloud) or application inference profile ARNs; a modelOverrides setting maps model versions to per-version ARNs for stricter pinning.

IAM: the four actions you need

The documented policy grants bedrock:InvokeModel, bedrock:InvokeModelWithResponseStream, bedrock:ListInferenceProfiles, and bedrock:GetInferenceProfile, scoped to inference-profile, application-inference-profile, and foundation-model ARNs, plus a conditional aws-marketplace:Subscribe if roles will subscribe to models themselves. Note the pair of profile-related actions: because model pinning uses inference profiles, the agent needs to list and read them, not just invoke. General setup guidance is in Bedrock IAM setup.

The Mantle flag: Bedrock's native Anthropic API shape

Bedrock has two serving surfaces for Claude: the classic Invoke API and the newer Mantle endpoint, which speaks the native Anthropic API shape with dateless anthropic.-prefixed model IDs like anthropic.claude-sonnet-5. The SDK exposes this as a second flag:

Mantle also matters for context size: on Bedrock, Sonnet 5 is served through Mantle and always runs with the 1M-token window, while Opus 4.6+ and Sonnet 4.6 enable 1M context via a [1m] suffix on the model ID. For long-running agent sessions — where the loop's accumulated history is the main consumer of context — that difference decides how long an agent can work before compaction kicks in. Background on the endpoint itself is in the Mantle endpoint explainer.

Gaps and extras on Bedrock

BehaviorOn Bedrock
WebSearch toolNot available — Bedrock has no server-side web search; see workarounds
/logoutUnavailable; authentication is AWS-side
API surfaceUses the Bedrock Invoke API; the Converse API is not supported
Prompt cachingAutomatic; DISABLE_PROMPT_CACHING=1 to disable, ENABLE_PROMPT_CACHING_1H=1 for 1-hour TTL (billed higher than the 5-minute default)
Service tierANTHROPIC_BEDROCK_SERVICE_TIER = default/flex/priority, sent as X-Amzn-Bedrock-Service-Tier
GuardrailsAttach via ANTHROPIC_CUSTOM_HEADERS with X-Amzn-Bedrock-GuardrailIdentifier / X-Amzn-Bedrock-GuardrailVersion
Plan around the WebSearch gap early. Agents written against the first-party API often lean on WebSearch for research steps; on Bedrock those steps need a client-side alternative or a different design. This is the single most common porting surprise.

Where to go next

Compare the sibling setups on Google Cloud and Microsoft Foundry, or dig into Bedrock's model-ID prefix rules and cross-region inference.

Sources