> ## 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.

# Use xpander with your existing AI gateway

> Keep the AI gateway you already run, such as Portkey, Kong or an in-house proxy, and connect it to the LLM Gateway in either direction: your gateway calling xpander, or xpander calling your gateway.

If your company already runs an AI gateway, such as Portkey, Kong or an in-house proxy, you can keep it. The LLM Gateway connects to it in either direction:

| You want | Set up | Who calls whom |
| - | - | - |
| Your apps keep calling your gateway, and some of its models come from xpander | [Your gateway in front of xpander](#your-gateway-in-front-of-xpander) | Your gateway → xpander → the model provider |
| Your agents and people use xpander, and some models are served by your gateway | [xpander in front of your gateway](#xpander-in-front-of-your-gateway) | xpander → your gateway → the model provider |

In both directions each call is checked against your organization's models, budgets and policies, and recorded in [Logs](https://platform.xpander.ai/governance/logs).

## Your gateway in front of xpander

Your gateway treats xpander as one more upstream provider. Your apps change nothing: they keep calling your gateway, and the models you point at xpander are served on your organization's xpander keys and rules.

### 1. Create an xpander API key

The key decides who the calls belong to in Logs and which budgets apply:

* A person's key from [AI models & keys](https://chat.xpander.ai/?settings=my-gateway) records the calls under that person, within their models and budgets.
* An organization API key records the calls under the key, not a person.

Keep the key in your gateway's secret store, not in its config file.

### 2. Add xpander as an upstream

xpander accepts two formats. Pick the one your gateway uses for that model:

| Format | Base URL | Key goes in |
| - | - | - |
| OpenAI-compatible (Chat Completions) | `https://llm-gw.xpander.ai/v1` | `Authorization: Bearer <key>` |
| Anthropic (Messages) | `https://llm-gw.xpander.ai` (no `/v1`) | `x-api-key: <key>` |

If your gateway already uses the `Authorization` header for its own sign-in, send the xpander key in the `x-xpander-api-key` header instead. xpander removes it before the call reaches the model provider.

The model name is the one xpander knows, such as `gemini-2.5-flash` or `global.anthropic.claude-sonnet-5-5`. To list the names your key may use:

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

On a self-hosted install, use your own gateway address, `https://llm-gw.<your domain>`.

### Example: one upstream entry per model

Most gateways describe an upstream model with the same four settings. Add one entry for each xpander model your apps should reach:

| Setting | OpenAI-compatible model | Anthropic model |
| - | - | - |
| Name your apps call | `company-gemini` | `company-claude` |
| Upstream model | `gemini-2.5-flash` | `global.anthropic.claude-sonnet-5-5` |
| Base URL | `https://llm-gw.xpander.ai/v1` | `https://llm-gw.xpander.ai` |
| Key | the xpander key from step 1 | the xpander key from step 1 |

Read the key from your secret store or an environment variable, such as `XPANDER_API_KEY`. Your apps keep calling your gateway by the names in the first row, streamed or not.

If your gateway lets you add request headers to an upstream, you can send the key as `x-xpander-api-key: <key>` instead.

### Claude Code behind your gateway

Claude Code calls the Anthropic Messages format (`/v1/messages`), so the gateway it points at must serve that path. If yours does, point Claude Code at your gateway as its `ANTHROPIC_BASE_URL` and use your gateway's model names. To connect Claude Code to xpander directly instead, see [Connect your tools](/run/llm-gateway/connect-tools#claude-code).

### What xpander records

Each call through your gateway is one request in [Logs](https://platform.xpander.ai/governance/logs), under the key's person or under the key, with the model, provider, tokens, cost and timings. Budgets for the organization, the person, their group and the key apply as they do to any other call. Your gateway's own logs keep what they always kept.

## xpander in front of your gateway

Your gateway becomes one of xpander's providers. Your agents and your people's coding tools call xpander, and xpander calls your gateway for the models it serves.

### 1. Add your gateway as a provider

In [Models](https://platform.xpander.ai/governance/model-access), choose **Add provider**, then **Custom endpoint**. On a Hybrid or Air-Gapped install, **Add provider** opens the custom endpoint form directly. Fill it in as described in [Custom endpoints](/run/llm-gateway/providers-and-keys#custom-endpoints):

1. Enter a **Name** and the **ID (used in API calls)**.
2. Pick the **Protocol**: **OpenAI-compatible** for most AI gateways.
3. Enter the **Base URL**, including `/v1` when your gateway serves `/v1/chat/completions`, such as `https://ai-gateway.example.com/v1`.
4. Under the key, choose **Create a new key** and paste the API key your gateway issued for xpander, such as a virtual key. It is stored in your organization's vault.
5. Under **Models**, choose **Test connection** to list your gateway's models, or **Add model** to enter them.
6. Choose **Add provider**.

xpander sends your gateway only the key you stored for it. No xpander key, and no other provider's key, is sent to your gateway.

### The address must be public on xpander cloud

On xpander cloud, your gateway must be reachable at a public `https` address. A private, loopback, link-local, cloud metadata or cluster address is refused when you save it, and again on each call ([Model endpoints on xpander cloud](/run/llm-gateway/providers-and-keys#model-endpoints-on-xpander-cloud)). On a Hybrid or Air-Gapped install, your gateway can be at a private address inside your network.

### 2. Turn the models on

The models you list when you add the provider are turned on for your organization as you save it. A group with its own model list does not get them until you tick them for that group with **Who may use it…** ([Turn models on](/run/llm-gateway/providers-and-keys#turn-models-on)). A model that is not on for the caller is refused with *This model is not enabled for you on the xpander LLM Gateway.*

To call one of these models through the LLM Gateway, name it as `<provider ID>::<model>`, such as `ai_gateway::gpt-4o-mini`, the way `/v1/models` lists it.

### 3. Set a price for each model

xpander does not know what your gateway's models cost. After you add the provider, its card opens and asks for each model's cost. Choose the model, or **Set model cost** in its menu, and enter the input and output price per 1M tokens in USD. Agents and model pickers offer a model only once it has a price. Calls through the LLM Gateway work without a price, but their cost shows as unknown and dollar budgets cannot count them. Calls on your own gateway are measured, not charged in xpander credits.

### Claude Code on your gateway's models

Claude Code and other clients of the Anthropic Messages format can use a model served by your gateway: xpander takes the call in the Messages format and sends it to your gateway in the OpenAI-compatible format, so your gateway only needs to serve `/v1/chat/completions`.

## Send records to your own observability

Whichever direction you choose, [Log destinations](/run/llm-gateway/logs-export) sends a copy of every request record to the systems your existing gateway reports to: spans to an OpenTelemetry collector, such as Coralogix, Datadog or Grafana, and Parquet files to your own S3, Google Cloud Storage or Azure bucket. Neither ever carries prompt or response text.


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