> ## 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 or your SDK at the LLM Gateway with your personal xpander key.

Calls made with your key run as you: on your enabled models, within your budgets, and under your name in Logs.

![Diagram](https://docs.xpander.ai/images/diagrams/run-llm-gateway-connect-tools-640c1654.svg)

| Coding tool | Setting file | Key variable |
| - | - | - |
| [Claude Code](#claude-code) | `~/.claude/settings.json` | `ANTHROPIC_AUTH_TOKEN` |
| [Codex](#codex) | `~/.codex/config.toml` | `XPANDER_GATEWAY_KEY` |
| [OpenCode](#opencode) | `~/.config/opencode/opencode.json` | `XPANDER_GATEWAY_KEY` |
| [OpenAI or Anthropic SDK](#your-own-code-sdks) | Your code | `XPANDER_GATEWAY_KEY` |

The fastest path for every coding tool is [one copied command](#the-quick-way-one-copied-command).

## Gateway address

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

Your exact address is under **Gateway address** in [AI models & keys](https://chat.xpander.ai/?settings=my-gateway). Examples below use `https://llm-gw.xpander.ai`.

## The quick way: one copied command

**1. Pick your client**

In [AI models & keys](https://chat.xpander.ai/?settings=my-gateway) (**Settings > AI models & keys**), under **Connect a client**, pick **Claude Code**, **Codex CLI**, **OpenCode** or **Your own code**.

**2. Copy and run the setup**

* **Claude Code, Codex CLI or OpenCode:** pick **macOS**, **Linux** or **Windows**, choose **Copy setup command** (it creates a key for that client and computer), and run it in your terminal (PowerShell on Windows). The coding tool stays connected in every new terminal.
* **Your own code:** choose **Copy prompt** and paste it into your project's coding agent. It wires your OpenAI or Anthropic SDK calls to the gateway, reading the key from `XPANDER_GATEWAY_KEY`. The prompt never contains your key.

**Set up manually** in the same card shows the files below with your address, a new key and a **Model** filled in.

## Claude Code

Your xpander key signs Claude Code in, with no `/login`. Add 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 your enabled models in `/model`, so no model is set. To try it in one terminal:

```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
```

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

## Codex

Codex reads your key from `XPANDER_GATEWAY_KEY`. Add 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
```

Keep the key for every new terminal:

```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")
```

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

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 your models under `models` and pick one as `xpander/<name>`. Keep `XPANDER_GATEWAY_KEY` as for Codex, then start `opencode`.

**Check it:** `opencode run "reply with exactly: OK"` answers OK.

## Your own code (SDKs)

Both SDKs take your xpander key as their API key. The Anthropic base URL has no `/v1`. The OpenAI one has `/v1`.

```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' }] });
```

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 provider that speaks another, so Codex can run an enabled Claude model.

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

The gateway reads your key from `Authorization: Bearer`, `x-api-key` or `x-xpander-api-key`. When `Authorization` already carries another sign-in, such as your own Claude plan, use `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 provider and is never logged.

## Check the connection

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

A list of models and aliases means it works. `401` means the key is unknown, revoked or expired. Your newest call shows at the top of [Logs](https://platform.xpander.ai/governance/logs) (admins) and in your [Usage](https://chat.xpander.ai/?settings=my-usage).

## Next steps

> **[Fix a refused call](https://docs.xpander.ai/run/llm-gateway/errors.md)**
>
> Messages and fixes.

> **[Create and manage your keys](https://docs.xpander.ai/use/ai-models-and-keys.md)**
>
> AI models and keys.


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