← Blog

How-to6 min read

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.

Running Claude Code and Codex with cloud-backed providers side by side in MirasimRunning Claude Code and Codex with cloud-backed providers side by side in Mirasim

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 platformClaude CodeCodex
Amazon Bedrock (AWS)Built-in (CLAUDE_CODE_USE_BEDROCK=1, /setup-bedrock); AWS SDK chain or Bedrock API keyBuilt-in (model_provider = "amazon-bedrock" or amazon-bedrock-runtime); CLI & Desktop sign-in wizard
Google Cloud Vertex AI / Agent PlatformBuilt-in (CLAUDE_CODE_USE_VERTEX=1, /setup-vertex); ADC (gcloud) or credential JSONBuilt-in (model_provider = "gcp"); OpenAI models on GCP are in private preview (CLI 0.167.0+)
Microsoft Foundry / AzureBuilt-in (CLAUDE_CODE_USE_FOUNDRY=1, env/settings only — no wizard); Entra ID (az login), API key, or bearer tokenCustom provider ([model_providers.azure]) in ~/.codex/config.toml with wire_api = "responses"
Corporate LLM gatewayOverride 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:

Manual Amazon Bedrock setup for Claude Code
# 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 profile region → us-east-1. Use ANTHROPIC_BEDROCK_REGION_PREFIX=eu (or us-gov in 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 Code settings.json so expired sessions re-authenticate automatically; use awsCredentialExport for cross-account credential helpers.
  • **Known differences:** /logout is unavailable (AWS owns auth), the built-in WebSearch tool is not available on Amazon Bedrock, and prompt caching is on by default (ENABLE_PROMPT_CACHING_1H=1 opts into a 1-hour cache TTL at higher write cost). Run /status to 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:

Manual Vertex AI / Agent Platform setup for Claude Code
# 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 if GOOGLE_CLOUD_PROJECT or the file behind GOOGLE_APPLICATION_CREDENTIALS lists a different project.
  • **Endpoints and fallback:** CLOUD_ML_REGION accepts global, multi-region values like us or eu, or a specific region such as us-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 pin ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL) to control spend. Run /status to verify API 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:

Microsoft Foundry setup for Claude Code
# 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_RESOURCE takes only the bare resource name (such as my-foundry-resource); Claude Code refuses a full URL there. Use ANTHROPIC_FOUNDRY_BASE_URL if you need a custom endpoint URL.
  • **Azure RBAC and token precedence:** Entra ID identities need the Foundry User (previously Azure AI User) or Cognitive Services User role on the resource. If multiple auth variables exist, ANTHROPIC_FOUNDRY_AUTH_TOKEN takes precedence over ANTHROPIC_FOUNDRY_API_KEY and the Entra ID default chain.
  • **Custom deployment names & 1M context:** Name deployments after the model ID (or add a modelOverrides entry in settings.json) so Claude Code detects the model and its 1M context window automatically. Run /status to verify Microsoft 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:

~/.codex/config.toml examples (use one block at a time)
# 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 codex or 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. Omitting profile in config.toml falls 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 app 26.1103.32239+. Sign in via **Sign in another way** → **Use Google Cloud Vertex AI** (CLI) / **Use Google Cloud** (Desktop). Codex runs gcloud auth application-default print-access-token using your local ADC login, or sets GOOGLE_APPLICATION_CREDENTIALS to credential_file. Change location from global to 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>] with gateway_oauth or 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 / FOUNDRY settings, AWS SSO profiles, gcloud ADC, az login, and ~/.codex/config.toml providers 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.

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, and ANTHROPIC_DEFAULT_HAIKU_MODEL before 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_RESOURCE expects only the Azure resource name (for example my-resource) and builds the hostname itself. To pass a full URL or custom gateway, use ANTHROPIC_FOUNDRY_BASE_URL instead.
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=1 for 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 app 26.1103.32239+.

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