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

# Connect your tools

> Point Claude Code, Codex, OpenCode and the OpenAI or Anthropic SDKs at the LLM Gateway with your personal xpander API key.

Your coding tools and scripts reach your company's models through the LLM Gateway with a personal xpander API key. Calls made with your key run as you: on the models your organization enabled for you, within your budgets, and they show under your name in Logs.

## Gateway address

| Your organization runs on | Gateway address |
| - | - |
| xpander cloud | `https://llm-gw.xpander.ai` |
| A Hybrid install | `https://llm-gw.xpander.ai`: your coding tools connect to xpander cloud, while your agents keep running on your install |
| An Air-Gapped install | `https://llm-gw.<your domain>`, published by your admin ([Self-hosted](/run/llm-gateway/self-hosted)) |

[AI models & keys](https://chat.xpander.ai/?settings=my-gateway) shows your exact address under **Gateway address**, with a copy button. The examples below use `https://llm-gw.xpander.ai`; replace it with yours on an Air-Gapped install.

## The quick way: one copied command

1. Open [AI models & keys](https://chat.xpander.ai/?settings=my-gateway) in Xpander Chat (**Settings > AI models & keys**).
2. Under **Connect a client**, pick **Claude Code**, **Codex CLI**, **OpenCode** or **Your own code**.
3. For Claude Code, Codex CLI and OpenCode, pick your system (**macOS**, **Linux** or **Windows**) and choose **Copy setup command**. Copying creates an API key for that client and computer. Paste the command in your terminal (PowerShell on Windows) and press Enter. Your coding tool starts already connected, and saves the connection in its own settings so every new terminal uses it.
4. For **Your own code**, choose **Copy prompt** and paste it into the coding agent you use in your project. It wires your project's OpenAI or Anthropic SDK calls to the gateway, reading the key from the `XPANDER_GATEWAY_KEY` environment variable. The prompt never contains your key.

**Set up manually**, in the same card, shows the files and commands below with your address filled in. While a new key is on screen, the key is filled in too. Codex, OpenCode and the SDK samples also take a **Model** you pick there.

## Claude Code

No `/login` is needed: your xpander key signs Claude Code in. Add this to `~/.claude/settings.json` (`%USERPROFILE%\.claude\settings.json` on Windows):

```json theme={"dark"}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://llm-gw.xpander.ai",
    "ANTHROPIC_AUTH_TOKEN": "<your key>",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}
```

The address has no `/v1`. `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY` lists the models your organization enabled for you in Claude Code's `/model`, so there is no model to set.

To try it in one terminal only:

<CodeGroup>
  ```bash macOS / Linux theme={"dark"}
  export ANTHROPIC_BASE_URL='https://llm-gw.xpander.ai'
  export ANTHROPIC_AUTH_TOKEN='<your key>'
  export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY='1'
  claude
  ```

  ```powershell Windows (PowerShell) theme={"dark"}
  $env:ANTHROPIC_BASE_URL="https://llm-gw.xpander.ai"
  $env:ANTHROPIC_AUTH_TOKEN="<your key>"
  $env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
  claude
  ```
</CodeGroup>

Check it: run `claude -p "reply with exactly: OK"`. In Claude Code, `/status` shows the gateway address.

## Codex

No login is needed: Codex reads your key from `XPANDER_GATEWAY_KEY`. Add this to `~/.codex/config.toml` (`%USERPROFILE%\.codex\config.toml` on Windows), with a model from [AI models & keys](https://chat.xpander.ai/?settings=my-gateway):

```toml theme={"dark"}
model_provider = "xpander"
model = "<model>"

[model_providers.xpander]
name = "xpander LLM Gateway"
base_url = "https://llm-gw.xpander.ai/v1"
env_key = "XPANDER_GATEWAY_KEY"
wire_api = "responses"
supports_websockets = false
```

Then keep the key for every new terminal:

<CodeGroup>
  ```bash macOS / Linux (add to ~/.zshrc or ~/.bashrc) theme={"dark"}
  export XPANDER_GATEWAY_KEY='<your key>'
  ```

  ```powershell Windows (PowerShell, once) theme={"dark"}
  [Environment]::SetEnvironmentVariable("XPANDER_GATEWAY_KEY", "<your key>", "User")
  ```
</CodeGroup>

Open a new terminal and start `codex`. Switch models with `/model`. Check it: `codex exec --skip-git-repo-check "reply with exactly: OK"` answers OK.

## OpenCode

No login is needed: OpenCode reads your key from `XPANDER_GATEWAY_KEY`. Add a provider to `~/.config/opencode/opencode.json` (`%USERPROFILE%\.config\opencode\opencode.json` on Windows):

```json theme={"dark"}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "xpander": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "xpander LLM Gateway",
      "options": {
        "baseURL": "https://llm-gw.xpander.ai/v1",
        "apiKey": "{env:XPANDER_GATEWAY_KEY}"
      },
      "models": {
        "<model>": {}
      }
    }
  },
  "model": "xpander/<model>"
}
```

List every model you use under `models`, and pick one as `xpander/<name>`. Keep `XPANDER_GATEWAY_KEY` for every new terminal as in the Codex section, then start `opencode`. Check it: `opencode run "reply with exactly: OK"` answers OK.

## Your own code (SDKs)

The Anthropic SDK takes the address without `/v1`; the OpenAI SDK takes it with `/v1`. Both take your xpander key as their API key.

<CodeGroup>
  ```python Python theme={"dark"}
  import os
  from anthropic import Anthropic
  from openai import OpenAI

  # Anthropic SDK: base URL without /v1
  anthropic = Anthropic(base_url="https://llm-gw.xpander.ai", api_key=os.environ["XPANDER_GATEWAY_KEY"])
  reply = anthropic.messages.create(model="<model>", max_tokens=256, messages=[{"role": "user", "content": "Hello"}])

  # OpenAI SDK: base URL with /v1
  openai = OpenAI(base_url="https://llm-gw.xpander.ai/v1", api_key=os.environ["XPANDER_GATEWAY_KEY"])
  reply = openai.chat.completions.create(model="<model>", messages=[{"role": "user", "content": "Hello"}])
  ```

  ```typescript Node (TypeScript) theme={"dark"}
  import OpenAI from 'openai';

  const client = new OpenAI({ baseURL: 'https://llm-gw.xpander.ai/v1', apiKey: process.env.XPANDER_GATEWAY_KEY });
  const reply = await client.chat.completions.create({ model: '<model>', messages: [{ role: 'user', content: 'Hello' }] });
  ```
</CodeGroup>

The gateway accepts these formats:

| Format | Path on the gateway address |
| - | - |
| Anthropic Messages | `/v1/messages` |
| OpenAI Chat Completions and Responses | `/v1/chat/completions`, `/v1/responses` |
| Embeddings | `/v1/embeddings` |
| The models your key may use | `/v1/models` |

A call in one format can be served by a model from a provider that speaks another, so Codex can run a Claude model when your organization enabled one for you.

### Sending your key next to another sign-in

The gateway reads your xpander key from `Authorization: Bearer`, from `x-api-key`, or from the `x-xpander-api-key` header. When the `Authorization` header already carries another sign-in, such as your own Claude plan in Claude Code, send your xpander key in `x-xpander-api-key`:

```bash theme={"dark"}
curl https://llm-gw.xpander.ai/v1/messages \
  -H "x-xpander-api-key: $XPANDER_GATEWAY_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "<model>", "max_tokens": 64, "messages": [{"role": "user", "content": "Say hello"}]}'
```

The header is removed before the call reaches the model provider, and is never written to a log.

## Check the connection

```bash theme={"dark"}
curl https://llm-gw.xpander.ai/v1/models -H "Authorization: Bearer $XPANDER_GATEWAY_KEY"
```

The answer lists the models and aliases your key may use. A `401` means the key is unknown, revoked or expired. Your newest call appears at the top of [Logs](https://platform.xpander.ai/governance/logs) (for admins) and in your own [Usage](https://chat.xpander.ai/?settings=my-usage). When a call is refused, [Errors and what to do](/run/llm-gateway/errors) lists every message.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.