> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.astropods.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.astropods.com/_mcp/server.

# Anthropic API

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:

| Detail          | Value                                                      | Why                                                                                                    |
| --------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| **Base URL**    | `${ASTRO_GATEWAY_URL}/anthropic`                           | The client appends `/v1/messages`, giving `${ASTRO_GATEWAY_URL}/anthropic/v1/messages`.                |
| **Auth header** | `x-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 id**    | `bedrock/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.

**`Claude Code / Claude Agent SDK (env)`**

```bash title="Claude Code / Claude Agent SDK (env)"
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
```

**`Anthropic SDK (TypeScript)`**

```typescript title="Anthropic SDK (TypeScript)"
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
    baseURL: `${process.env.ASTRO_GATEWAY_URL}/anthropic`,   // client appends /v1/messages
    authToken: process.env.ASTRO_GATEWAY_API_KEY,            // placeholder; gateway ignores it
    defaultHeaders: { "x-bf-vk": process.env.ASTRO_GATEWAY_API_KEY! },  // the real auth
});

const message = await client.messages.create({
    model: "bedrock/claude-opus-4-8",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Hello" }],
});
```

**`Raw HTTP`**

```bash title="Raw HTTP"
curl "$ASTRO_GATEWAY_URL/anthropic/v1/messages" \
    -H "x-bf-vk: $ASTRO_GATEWAY_API_KEY" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{"model":"bedrock/claude-opus-4-8","max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]}'
```

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](/ai-gateway/web-search)). Otherwise wire up your own tool and feed the result back as a tool result.

## Next steps

* [Monitor Claude Code](/monitor-claude-code): send Claude Code telemetry to your dashboard
* [Errors and limits](/ai-gateway/limits): status codes and gateway boundaries