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

# Secure Claude Code with the LLM Gateway

> Route Claude Code through Aptible's LLM Gateway for a compliant, audited path to Claude.

## Overview

This guide walks through creating an LLM Key and pointing [Claude Code](https://docs.claude.com/en/docs/claude-code) at Aptible's LLM Gateway, so every request Claude Code makes is authenticated, audited, and covered by your organization's [Model Access Policy](/docs/llm-gateway/model-access-policies) and [Spend Limit](/docs/llm-gateway/cost-control).

## Create an LLM Key

<Steps>
  <Step title="Start your trial or sign in">
    [Sign up](https://app.aptible.com/signup) for or [sign in](https://app.aptible.com/login) to your Aptible account. Then navigate to [LLM Gateway](https://app.aptible.com/llm-gateway) to activate your trial. You'll receive \$10 of LLM credits to get you started, which can be used with any models your organization allows.

    <Warning>
      **For those processing PHI:** you'll need to execute a BAA before you can start processing PHI using the LLM Gateway. Go to **Settings > [Agreements](https://app.aptible.com/settings/legal/agreements)** to execute one.
    </Warning>
  </Step>

  <Step title="Create an LLM key">
    Click **Create Key** on the [LLM Gateway](https://app.aptible.com/llm-gateway) page and give it a descriptive name so you can identify its usage later when reviewing costs and request history.

    LLM Keys are scoped to your whole organization — any member can create and manage them, and a single key gives you access to every model your organization's [model access policy](/docs/llm-gateway/model-access-policies) allows.

    Once created, copy the key's token and endpoint URL. You won't be able to see the token again after you close this window.

    <Tip>
      If a key's token is ever lost or compromised, revoke it from [LLM Gateway](https://app.aptible.com/llm-gateway) and create a new one — see [LLM Keys](/docs/llm-gateway/llm-keys) for details.
    </Tip>
  </Step>
</Steps>

## Configure Claude Code

The LLM Gateway provides a dedicated base URL for Claude Code under `/harness/claude-code` — set it once and you won't need to change it again, even if the endpoints behind it change.

<Steps>
  <Step title="Set the gateway base URL">
    Claude Code reads its API base URL from the `ANTHROPIC_BASE_URL` environment variable:

    ```bash theme={null}
    export ANTHROPIC_BASE_URL="https://llm-gateway.aptible.com/harness/claude-code"
    ```
  </Step>

  <Step title="Set your LLM Key">
    Claude Code authenticates with either `ANTHROPIC_AUTH_TOKEN` or `ANTHROPIC_API_KEY` — both work against the LLM Gateway, but `ANTHROPIC_AUTH_TOKEN` is preferred since it's sent as a standard bearer token:

    ```bash theme={null}
    export ANTHROPIC_AUTH_TOKEN="<YOUR_LLM_KEY>"
    ```
  </Step>

  <Step title="Persist your configuration (optional)">
    To avoid setting these every session, add them to your shell profile (`~/.zshrc`, `~/.bashrc`, etc.), or add them to a project's `.claude/settings.json`:

    ```json .claude/settings.json theme={null}
    {
      "env": {
        "ANTHROPIC_BASE_URL": "https://llm-gateway.aptible.com/harness/claude-code",
        "ANTHROPIC_AUTH_TOKEN": "<YOUR_LLM_KEY>"
      }
    }
    ```

    <Warning>
      Don't commit a real LLM Key into a shared `.claude/settings.json`. Use `.claude/settings.local.json` (gitignored by default) for personal credentials, or keep the key in your shell environment instead.
    </Warning>
  </Step>

  <Step title="Choose a model (optional)">
    By default, Claude Code uses its usual model selection. To pin it to a specific model available through your organization's [Model Access Policy](/docs/llm-gateway/model-access-policies), set:

    ```bash theme={null}
    export ANTHROPIC_MODEL="claude-sonnet-5"
    ```

    See [Supported Models](/docs/llm-gateway/supported-models) for the full list of model IDs, and [Supported APIs](/docs/llm-gateway/supported-apis) for how model selection works.
  </Step>

  <Step title="Verify it's working">
    Start Claude Code and send a simple smoke-test prompt:

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

    ```text theme={null}
    > Tell me a joke about cloud security
    ```

    If you get a response back, requests are flowing through the LLM Gateway. You can confirm this by checking the key’s request history in [LLM Gateway](https://app.aptible.com/llm-gateway) to confirm, or see [Audit Logging](/docs/llm-gateway/audit-logging) for more ways to review your request.
  </Step>
</Steps>

## Troubleshooting

<AccordionGroup>
  <Accordion title="401 Unauthorized">
    Double-check `ANTHROPIC_AUTH_TOKEN` (or `ANTHROPIC_API_KEY`) is set to a valid, unrevoked LLM Key, and that `ANTHROPIC_BASE_URL` points at `https://llm-gateway.aptible.com/harness/claude-code` with no trailing path.
  </Accordion>

  <Accordion title="400 for an unrecognized or blocked model">
    Check that the model you're requesting (via `ANTHROPIC_MODEL` or `/model`) is a valid model ID from [Supported Models](/docs/llm-gateway/supported-models), and that it's allowed by your organization's [Model Access Policy](/docs/llm-gateway/model-access-policies).
  </Accordion>

  <Accordion title="402 Payment Required">
    Your organization has reached its monthly spend limit. See [Cost Visibility & Control](/docs/llm-gateway/cost-control).
  </Accordion>
</AccordionGroup>
