Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry
Connect Claude Code and Codex to Amazon Bedrock, Vertex AI, and Microsoft Foundry: env vars, config.toml, auth, model pinning, and limits.


The short answer
Both Claude Code and Codex can send traffic through your existing cloud accounts instead of direct Anthropic or OpenAI billing. Claude Code switches backends with CLAUDE_CODE_USE_BEDROCK=1, CLAUDE_CODE_USE_VERTEX=1, or CLAUDE_CODE_USE_FOUNDRY=1 (with interactive wizards for Bedrock and Vertex AI). Codex has built-in amazon-bedrock and gcp providers in ~/.codex/config.toml plus a custom [model_providers.azure] configuration for Azure.
| Cloud platform | Claude Code | Codex |
|---|---|---|
| Amazon Bedrock (AWS) | Built-in (CLAUDE_CODE_USE_BEDROCK=1, /setup-bedrock); AWS SDK chain or Bedrock API key | Built-in (model_provider = "amazon-bedrock" or amazon-bedrock-runtime); CLI & Desktop sign-in wizard |
| Google Cloud Vertex AI / Agent Platform | Built-in (CLAUDE_CODE_USE_VERTEX=1, /setup-vertex); ADC (gcloud) or credential JSON | Built-in (model_provider = "gcp"); OpenAI models on GCP are in private preview (CLI 0.167.0+) |
| Microsoft Foundry / Azure | Built-in (CLAUDE_CODE_USE_FOUNDRY=1, env/settings only — no wizard); Entra ID (az login), API key, or bearer token | Custom provider ([model_providers.azure]) in ~/.codex/config.toml with wire_api = "responses" |
| Corporate LLM gateway | Override base URL (ANTHROPIC_BEDROCK_BASE_URL, ANTHROPIC_VERTEX_BASE_URL, ANTHROPIC_FOUNDRY_BASE_URL) | Custom [model_providers.<id>] with gateway_oauth, env_key, or [model_providers.<id>.auth] token command |
Claude Code on Amazon Bedrock
Complete two one-time AWS steps first: enable the Anthropic models you want in the Amazon Bedrock Model catalog and submit the use case form (AWS Organizations can submit once from the management account via PutUseCaseForModelAccess), then verify your IAM role has Bedrock invoke permissions.
For an individual machine, run claude, pick **3rd-party platform** → **Amazon Bedrock** (or run /setup-bedrock when already signed in; type it in full because the command menu hides it until CLAUDE_CODE_USE_BEDROCK=1 is set). The wizard saves the result into the env block of your user settings.json. For CI or team rollouts, export the variables directly:
# 1. Authenticate (pick one: AWS SSO, aws login, instance role, or Bedrock API key)
aws sso login --profile=your-profile-name
export AWS_PROFILE=your-profile-name
# Or use a Bedrock API key instead of AWS credentials:
# export AWS_BEARER_TOKEN_BEDROCK=your-bedrock-api-key
# 2. Enable Bedrock and pin model IDs for team rollouts
export CLAUDE_CODE_USE_BEDROCK=1
export AWS_REGION=us-east-1
export ANTHROPIC_DEFAULT_OPUS_MODEL='us.anthropic.claude-opus-4-8'
export ANTHROPIC_DEFAULT_SONNET_MODEL='us.anthropic.claude-sonnet-4-6'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='us.anthropic.claude-haiku-4-5-20251001-v1:0'- **Region precedence:**
AWS_REGION→AWS_DEFAULT_REGION→ active profileregion→us-east-1. UseANTHROPIC_BEDROCK_REGION_PREFIX=eu(orus-govin GovCloud) if you want built-in defaults with a specific cross-region prefix. - **Automatic SSO refresh:** Add
"awsAuthRefresh": "aws sso login --profile myprofile"to your Claude Codesettings.jsonso expired sessions re-authenticate automatically; useawsCredentialExportfor cross-account credential helpers. - **Known differences:**
/logoutis unavailable (AWS owns auth), the built-inWebSearchtool is not available on Amazon Bedrock, and prompt caching is on by default (ENABLE_PROMPT_CACHING_1H=1opts into a 1-hour cache TTL at higher write cost). Run/statusto confirm the provider and resolved region.
Claude Code on Google Cloud Vertex AI (Agent Platform)
Anthropic's documentation now calls Google-managed Vertex AI **Google Cloud's Agent Platform**, though Claude Code's login prompt still labels it **Google Vertex AI**. Enable aiplatform.googleapis.com in your GCP project and request Claude model access in Model Garden (approval can take 24–48 hours), then run claude → **3rd-party platform** → **Google Vertex AI** (or /setup-vertex), or configure it via environment variables:
# 1. Authenticate via Application Default Credentials (or GOOGLE_APPLICATION_CREDENTIALS)
gcloud auth application-default login
# 2. Enable Vertex AI integration and pin models
export CLAUDE_CODE_USE_VERTEX=1
export CLOUD_ML_REGION=global
export ANTHROPIC_VERTEX_PROJECT_ID=YOUR-PROJECT-ID
# Optional: override region for models that require a regional endpoint
# export VERTEX_REGION_CLAUDE_HAIKU_4_5=us-east5
export ANTHROPIC_DEFAULT_OPUS_MODEL='claude-opus-4-8'
export ANTHROPIC_DEFAULT_SONNET_MODEL='claude-sonnet-5'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='claude-haiku-4-5@20251001'- **Project ID wins over ADC:** Claude Code always sends requests to
ANTHROPIC_VERTEX_PROJECT_ID, even ifGOOGLE_CLOUD_PROJECTor the file behindGOOGLE_APPLICATION_CREDENTIALSlists a different project. - **Endpoints and fallback:**
CLOUD_ML_REGIONacceptsglobal, multi-region values likeusoreu, or a specific region such asus-east5(which is also the fallback if unset). Add"gcpAuthRefresh": "gcloud auth application-default login"to settings to refresh expired ADC automatically. - **Watch background & default billing:** If you don't pin models, Claude Code defaults to Opus on Agent Platform and uses Sonnet for background tasks; set
ANTHROPIC_MODEL(or pinANTHROPIC_DEFAULT_SONNET_MODELandANTHROPIC_DEFAULT_HAIKU_MODEL) to control spend. Run/statusto verifyAPI provider: Google Vertex AI.
Claude Code on Microsoft Foundry (Azure)
Unlike Bedrock and Vertex AI, Microsoft Foundry has no interactive setup wizard in Claude Code. Create a resource and Claude deployments in the Microsoft Foundry portal (ai.azure.com), choose specific model versions rather than auto-update, and point Claude Code at your resource:
# 1. Authenticate with Microsoft Entra ID (leave API key unset)...
az login
# ...or set an API key / Entra bearer token:
# export ANTHROPIC_FOUNDRY_API_KEY=your-azure-api-key
# 2. Enable Foundry and map your Azure deployment names
export CLAUDE_CODE_USE_FOUNDRY=1
export ANTHROPIC_FOUNDRY_RESOURCE=my-foundry-resource
export ANTHROPIC_DEFAULT_OPUS_MODEL='claude-opus-4-8'
export ANTHROPIC_DEFAULT_SONNET_MODEL='claude-sonnet-5'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='claude-haiku-4-5'- **Resource name vs. base URL:**
ANTHROPIC_FOUNDRY_RESOURCEtakes only the bare resource name (such asmy-foundry-resource); Claude Code refuses a full URL there. UseANTHROPIC_FOUNDRY_BASE_URLif you need a custom endpoint URL. - **Azure RBAC and token precedence:** Entra ID identities need the
Foundry User(previouslyAzure AI User) orCognitive Services Userrole on the resource. If multiple auth variables exist,ANTHROPIC_FOUNDRY_AUTH_TOKENtakes precedence overANTHROPIC_FOUNDRY_API_KEYand the Entra ID default chain. - **Custom deployment names & 1M context:** Name deployments after the model ID (or add a
modelOverridesentry insettings.json) so Claude Code detects the model and its 1M context window automatically. Run/statusto verifyMicrosoft Foundry.
Codex on Amazon Bedrock, Vertex AI, and Azure
Codex reserves amazon-bedrock, amazon-bedrock-runtime, and gcp as built-in model providers in ~/.codex/config.toml, while Azure is configured as a custom provider entry:
# Option A: Amazon Bedrock (Mantle endpoint; use amazon-bedrock-runtime for Runtime)
model_provider = "amazon-bedrock"
model = "<bedrock-model-id>"
[model_providers.amazon-bedrock.aws]
profile = "default"
region = "us-east-1"
# Option B: Google Cloud Vertex AI (private preview; CLI 0.167.0+)
# model_provider = "gcp"
# [model_providers.gcp]
# project_id = "my-project"
# location = "global"
# credential_file = "/path/to/adc-credentials.json"
# Option C: Azure OpenAI (custom provider; set AZURE_OPENAI_API_KEY in shell)
# model_provider = "azure"
# [model_providers.azure]
# name = "Azure"
# base_url = "https://YOUR_PROJECT_NAME.openai.azure.com/openai"
# env_key = "AZURE_OPENAI_API_KEY"
# query_params = { api-version = "2025-04-01-preview" }
# wire_api = "responses"- **Codex on Amazon Bedrock:** You can also sign in interactively from
codexor the desktop app via **Use Amazon Bedrock** and choose among **AWS profile**, **AWS access keys**, **Environment variables**, or a **Bedrock API key** plus your region. Omittingprofileinconfig.tomlfalls back to the standard AWS credential chain. - **Codex on Google Cloud Vertex AI:** OpenAI models on Vertex AI are in **private preview** (request access first) and require Codex CLI
0.167.0+or Codex desktop app26.1103.32239+. Sign in via **Sign in another way** → **Use Google Cloud Vertex AI** (CLI) / **Use Google Cloud** (Desktop). Codex runsgcloud auth application-default print-access-tokenusing your local ADC login, or setsGOOGLE_APPLICATION_CREDENTIALStocredential_file. Changelocationfromglobalto a regional endpoint if compliance requires it. - **Codex through an enterprise gateway:** If your security team puts one internal LLM gateway in front of Bedrock, Vertex, or Azure, configure a custom
[model_providers.<id>]withgateway_oauthor a[model_providers.<id>.auth]token command rather than handing out raw cloud keys.
Running cloud-backed agents side by side in Mirasim
When an organization standardizes on AWS, GCP, or Azure for compliance and billing, engineers still often want Claude Code on one task and Codex on another—without giving a third-party app their cloud IAM keys.
- **Inherits your local cloud config directly:** Mirasim runs the Claude Code and Codex CLIs already installed on your machine, so your
CLAUDE_CODE_USE_BEDROCK/VERTEX/FOUNDRYsettings, AWS SSO profiles,gcloudADC,az login, and~/.codex/config.tomlproviders keep working as-is without proxying credentials. - **No Mirasim credit charged on your own cloud billing:** Sessions running on your local Bedrock, Vertex AI, or Azure/Foundry configuration bill straight to your cloud account and don't consume Mirasim credit.
- **Side-by-side multi-agent workspace:** Open a Bedrock-backed Claude Code pane next to a Vertex- or Bedrock-backed Codex pane on separate git worktrees in the same project, and review both diffs in one place.
Chapter 16 · Models, accounts and quota › Bring your own keys → Choosing models, bringing your own keys, and switching credit sources per session in Mirasim.
FAQ
- Should our team pin model versions on Bedrock, Vertex AI, and Foundry?
- Yes. Anthropic recommends pinning
ANTHROPIC_DEFAULT_OPUS_MODEL,ANTHROPIC_DEFAULT_SONNET_MODEL, andANTHROPIC_DEFAULT_HAIKU_MODELbefore rolling out to a team so model aliases don't silently resolve to a release your cloud account hasn't enabled yet. - Why does Claude Code fail on Microsoft Foundry when I pass the full endpoint URL to
ANTHROPIC_FOUNDRY_RESOURCE? ANTHROPIC_FOUNDRY_RESOURCEexpects only the Azure resource name (for examplemy-resource) and builds the hostname itself. To pass a full URL or custom gateway, useANTHROPIC_FOUNDRY_BASE_URLinstead.- Is prompt caching enabled on Bedrock, Vertex AI, and Microsoft Foundry?
- Yes, Claude Code enables prompt caching automatically on all three cloud platforms. You can set
ENABLE_PROMPT_CACHING_1H=1for a 1-hour cache TTL (billed at a higher cache-write rate). - Can anyone use Codex on Google Cloud Vertex AI today?
- OpenAI models on Google Cloud are in private preview, so your organization needs access approval first, plus Codex CLI
0.167.0+or Codex desktop app26.1103.32239+.
Article · Using an API key with Claude Code and Codex: setup, custom endpoints, and switching back → Using direct API keys or a custom LLM gateway with Claude Code and Codex.
Article · Configuring Claude Code and Codex behind a proxy, firewall, or custom CA certificate → Configuring corporate HTTP proxies, custom root CAs, and mTLS for Claude Code and Codex.
Article · Claude Code for teams: access, shared setup, and working in one session → Rolling out Claude Code to a team: seats, managed settings, and shared conventions.
Article · Codex for teams: ChatGPT Business and Enterprise, shared setup, and working in one session → Rolling out Codex to a team: ChatGPT Business/Enterprise, managed configuration, and spend controls.
Sources
Checked on November 29, 2026 against Anthropic's Claude Code docs (code.claude.com/docs/en: third-party-integrations, amazon-bedrock, google-vertex-ai, microsoft-foundry) and OpenAI's Codex docs (learn.chatgpt.com/docs: amazon-bedrock, enterprise/connect-to-vertex-ai, config-file/config-advanced, enterprise/connect-to-a-gateway). Cloud model IDs and preview availability change frequently; verify against those pages before deploying.
Keep reading

Fixing OpenAI and Codex 403 “unsupported_country_region_territory”
Why OpenAI and Codex return 403 unsupported_country_region_territory, how to fix false positives on VPNs or cloud IPs, and compliant alternatives.

Using Claude Code with Chrome and Codex Browser: live debugging, Playwright, and previews
How to connect Claude Code to Chrome (extension, console logs, login limits) and use Codex Browser or Playwright, plus live dev-server previews in Mirasim.

Cutting Claude Code and Codex token usage: /context, /compact, prompt caching, and model routing
How to cut Claude Code and Codex token spend and stretch usage limits: /context, /compact, /clear, prompt caching, subagents, and local usage tracking.