How Claude Code connects
Claude Code reaches the AI Gateway in the Anthropic Messages format, throughANTHROPIC_BASE_URL, whichever provider sits behind it. Don’t set CLAUDE_CODE_USE_BEDROCK or CLAUDE_CODE_USE_VERTEX.
Because Claude Code thinks it is talking to the Claude API, it sends the full set of Anthropic features even when the AI Gateway routes to Bedrock or Vertex AI. The AI Gateway bridges the difference: it strips beta flags the provider doesn’t support, rewrites the ones the provider renamed, and drops body fields the provider rejects.
What the AI Gateway handles
Versions are the enterprise gateway release that added each behavior. Hybrid gateways need at least that version.
On gateways older than v2.22.0, add
"forward_headers": ["anthropic-beta"] to the config, or features like extended context stay off with no error.
Claude Code settings
Show gateway models in /model
- Keep
ANTHROPIC_AUTH_TOKENset. Claude Code skips discovery when the credential is only inANTHROPIC_CUSTOM_HEADERS. - With
x-portkey-providerset, the picker lists that provider’s models. Without a provider, the gateway returns models across the workspace. - Claude Code keeps only IDs that contain
claudeoranthropic. Bedrock IDs likeus.anthropic.claude-sonnet-4-5-20250929-v1:0pass; non-Claude models from the universal provider don’t appear.
Bedrock and Vertex AI upstreams
If a request fails with400 and Extra inputs are not permitted, a pre-release Anthropic feature reached a provider that doesn’t accept it. Turn pre-release features off in Claude Code:
strict, defer_loading), structured output format and MCP tool search. Effort, extended context and interleaved thinking stay on.
Gateway caching
The AI Gateway’s simple cache keys on the request body. Claude Code v2.1.181 and later keep the system prompt prefix stable within a conversation, so caching works without changes. On older versions, setCLAUDE_CODE_ATTRIBUTION_HEADER=0.
Guardrails
Claude Code expects thesystem, tools and messages content of earlier turns to reach the provider unchanged. Guardrails that rewrite the request, such as PII redaction, can cause:
- Cache misses on every turn
400errors saying a thinking block isbound to a different conversation. Claude Code recovers by dropping earlier thinking blocks.
strip_scaffolding to avoid false positives from Claude Code’s system reminders.
Requests that skip the gateway
Two checks callapi.anthropic.com directly and never appear in the AI Gateway logs:
- The fast mode availability check
- The WebFetch domain safety check
api.anthropic.com, fast mode can report a connectivity error while requests through the AI Gateway keep working. See fast mode behind gateways.

