AI Gateway

Anthropic API

Run Claude Code and the Claude Agent SDK against the gateway's native Messages passthrough
View as Markdown

Agents built on the native Anthropic Messages API (Claude Code, the Claude Agent SDK, or the @anthropic-ai/sdk client) can’t use the OpenAI-compatible surface. Use the gateway’s /anthropic passthrough endpoint instead. This is the only way to run a Claude-Code-based agent on the gateway.

The platform injects only ASTRO_GATEWAY_URL and ASTRO_GATEWAY_API_KEY. It does not set any ANTHROPIC_* variables. You map them yourself, and there are three gateway-specific details:

DetailValueWhy
Base URL${ASTRO_GATEWAY_URL}/anthropicThe client appends /v1/messages, giving ${ASTRO_GATEWAY_URL}/anthropic/v1/messages.
Auth headerx-bf-vk: ${ASTRO_GATEWAY_API_KEY}The gateway reads the virtual key from x-bf-vk, not Authorization / x-api-key, which it ignores.
Model idbedrock/claude-opus-4-8 (or -sonnet-4-6, -haiku-4-5)Models are served under bedrock/<name> ids; bare claude-* returns 401.

Authenticate with the x-bf-vk header, not a Bearer token. The gateway ignores Authorization and x-api-key. For Claude Code, also set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 to disable its pre-release beta flags, which Bedrock rejects.

export ANTHROPIC_BASE_URL="$ASTRO_GATEWAY_URL/anthropic"
# The gateway reads the virtual key from x-bf-vk; ANTHROPIC_AUTH_TOKEN is set only so
# the client has *a* credential (the gateway ignores it).
export ANTHROPIC_CUSTOM_HEADERS="x-bf-vk: $ASTRO_GATEWAY_API_KEY"
export ANTHROPIC_AUTH_TOKEN="$ASTRO_GATEWAY_API_KEY"
# Bedrock-served model ids (bare claude-* returns 401):
export ANTHROPIC_MODEL="bedrock/claude-opus-4-8"
export ANTHROPIC_DEFAULT_SONNET_MODEL="bedrock/claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="bedrock/claude-haiku-4-5"
# Bedrock rejects Claude Code's first-party pre-release beta flags:
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
# then run `claude` (or the Agent SDK) as usual

Streaming, client-defined tool use, and adaptive thinking all work over this path. Anthropic’s server-side tools (web_search, web_fetch, code execution, computer use) are not available on the Claude models, because they run on Amazon Bedrock, which doesn’t host them. For web search, use one of the gpt-* models on the OpenAI-compatible surface (see Web search). Otherwise wire up your own tool and feed the result back as a tool result.

Next steps