> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flexinference.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Point Claude Code at FlexInference with an agent key that carries the deadline.

Claude Code speaks the Anthropic Messages API. We run that API at `POST /v1/messages`, so a base URL and a key are the whole integration.

Claude Code gives you nowhere to set `start_within`, so the deadline goes on the key. Create one first (see [agent keys](/agent-keys)).

A duration races Claude's cheaper tier on managed keys, without streaming, inside a window of three to ten minutes. An interactive session streams, so pick a tier here. A key duration still works either way, because it falls back to a tier rather than failing. See [Claude durations need a longer window](/deadline-routing#claude-durations-need-a-longer-window).

Your organization has to be able to run Anthropic before you start. On your own keys that means an Anthropic provider key on the **Provider keys** tab, because we don't resell inference. On [Managed Keys](/billing#managed-keys) it means Anthropic turned on and funded.

## Set this up with an agent

Open the block below and copy it into any coding agent. The prompt never asks for your API key: the agent configures everything else, then prints the one export line for you to run yourself.

<Accordion title="Copy agent setup prompt">
  ```text theme={null}
  Configure Claude Code to send its requests to FlexInference, which serves the Anthropic Messages API.

  You will never see or handle my API key. Claude Code reads it from the `ANTHROPIC_AUTH_TOKEN` environment variable, and I export that myself. Do not ask me for the key, do not write it into any file, and do not read it from my environment.

  Ask me whether to configure this globally or for one project, then edit `~/.claude/settings.json` or `.claude/settings.json` accordingly. Create the file if it does not exist, and preserve every setting already in it.

  Add this `env` block, merging into any existing `env` rather than replacing it. Note that it carries no credential:

  {
    "env": {
      "ANTHROPIC_BASE_URL": "https://api.flexinference.com",
      "ANTHROPIC_MODEL": "claude-opus-5",
      "ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-4-5",
      "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
    }
  }

  Then print this line for me to run in the shell I start Claude Code from. Do not run it and do not ask for the value:

  export ANTHROPIC_AUTH_TOKEN=<paste your key here>

  Rules that matter, do not deviate:
  - `ANTHROPIC_BASE_URL` must NOT end in `/v1`. Claude Code appends `/v1/messages` itself.
  - The credential must arrive as `ANTHROPIC_AUTH_TOKEN`, never `ANTHROPIC_API_KEY`. The first sends `Authorization: Bearer`, which FlexInference requires. The second sends `x-api-key`, which it refuses with `401 missing_api_key`.
  - Both model variables must be `claude-*` slugs. Claude Code sends Anthropic-native fields such as `output_config` on every request, and FlexInference refuses to mistranslate them onto a non-Claude model.
  - `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` must be `"1"`. Without it Claude Code sends experimental beta fields such as `context_management`, FlexInference does not forward the `anthropic-beta` headers they need, and every request fails with `400 context_management: Extra inputs are not permitted`.
  - Do not add a retry setting. Claude Code retries on its own and my key may carry its own policy.

  Finally, tell me that Anthropic must be servable on my FlexInference organization. On BYOK that means an Anthropic provider key on the API, then Provider keys tab. On Managed Keys it means Anthropic enabled and funded. Then start a new Claude Code session and report what you changed.
  ```
</Accordion>

## Configure Claude Code

1. Create or open `~/.claude/settings.json`. A per-project file at `.claude/settings.json` works the same way.

2. Add an `env` block naming the router, your key, and both models.

   ```json theme={null}
   {
     "env": {
       "ANTHROPIC_BASE_URL": "https://api.flexinference.com",
       "ANTHROPIC_AUTH_TOKEN": "flex_live_...",
       "ANTHROPIC_MODEL": "claude-opus-5",
       "ANTHROPIC_SMALL_FAST_MODEL": "claude-haiku-4-5",
       "CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
     }
   }
   ```

3. Start Claude Code.

   ```bash theme={null}
   claude
   ```

Export the same variables in your shell instead, to keep the secret out of a file.

```bash theme={null}
export ANTHROPIC_BASE_URL=https://api.flexinference.com
export ANTHROPIC_AUTH_TOKEN=flex_live_...
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
```

Four rules make this work.

**Omit the `/v1` suffix.** Claude Code appends `/v1/messages` to the base URL itself.

**Use `ANTHROPIC_AUTH_TOKEN`, never `ANTHROPIC_API_KEY`.** The first sends `Authorization: Bearer`, which we require. The second sends `x-api-key`, which we refuse.

**Set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` to `1`.** Claude Code otherwise sends experimental beta fields such as `context_management`. We don't forward the `anthropic-beta` headers those fields need, so every request fails.

**Set both model variables.** Claude Code runs a large main-loop model and a small background model against one key. Both must be `claude-*` slugs.

## Confirm the key applied

Every response comes with `x-flexinference-defaults-applied`. Claude Code doesn't show response headers, so read the request in the dashboard under **Logs** instead.

## Troubleshooting

**`400 context_management: Extra inputs are not permitted`.** Claude Code sent an experimental beta field, and we don't forward the `anthropic-beta` header it needs. Set `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1` and start a new session. The same flag clears any other `Extra inputs are not permitted` refusal naming a beta field.

**[`401 missing_api_key`](/errors#missing_api_key).** You set `ANTHROPIC_API_KEY`, so the client sent `x-api-key`, which we don't read. Set `ANTHROPIC_AUTH_TOKEN` instead and unset `ANTHROPIC_API_KEY`.

**[`400 unsupported_parameter`](/errors#unsupported_parameter) naming `output_config`.** A model variable points at a non-Claude slug, and Claude Code sends Anthropic-native fields we refuse to mistranslate. Set both model variables to `claude-*` slugs.

**[`404 unknown_url`](/errors#unknown_url) naming `/v1/messages/count_tokens`.** We don't route that path. A `claude -p` run never calls it, though an interactive session may.

**Every request spends a full retry budget.** Claude Code retries on its own, and a key `retry` policy stacks with it. Leave `retry` unset on a key this client uses.

See [errors](/errors) for every refusal we return, and [agent keys](/agent-keys#troubleshooting-faq) for the ones that are not specific to Claude Code.
