> ## 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 run, such as Portkey, Kong or an in-house proxy, and connect it to xpander in either direction.

The LLM Gateway connects to a gateway you already run in either direction: your gateway calls xpander, or xpander calls your gateway. In both, xpander checks each call against your organization's models, budgets and policies, and records it in [Logs](https://platform.xpander.ai/governance/logs). The diagram shows the first direction.

![Diagram](https://docs.xpander.ai/images/diagrams/run-llm-gateway-existing-gateway-48b5045f.svg)

| You want | Set up |
| - | - |
| Your apps keep calling your gateway, and some models come from xpander | [Your gateway in front of xpander](#your-gateway-in-front-of-xpander) |
| 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) |

## Your gateway in front of xpander

Your gateway treats xpander as one more upstream. Your apps change nothing.

**1. Create an xpander API key** and keep it in your gateway's secret store. A person's key from [AI models & keys](https://chat.xpander.ai/?settings=my-gateway) records calls under that person, with their models and budgets. An organization API key records them under the key. To try the commands on this page, export it as `XPANDER_GATEWAY_KEY`, the name the **Connect a client** guide uses:

```bash theme={"dark"}
export XPANDER_GATEWAY_KEY=<your key>
```

**2. Add xpander as an upstream**, one entry per model your apps should reach:

| Setting | OpenAI-compatible (Chat Completions) | Anthropic (Messages) |
| - | - | - |
| 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` (no `/v1`) |
| Key header | `Authorization: Bearer <key>` | `x-api-key: <key>` |

If your gateway uses `Authorization` for its own sign-in, send the key as `x-xpander-api-key` instead. xpander removes it before the provider. On a self-hosted install, use `https://llm-gw.<your domain>`. List the model names your key may use:

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

Each call is one request in Logs, under the key's person or the key, and the organization, person, group and key budgets apply.

**Claude Code** calls `/v1/messages`, so point its `ANTHROPIC_BASE_URL` at your gateway only if your gateway serves that path. To connect it to xpander directly, see [Connect your tools](https://docs.xpander.ai/run/llm-gateway/connect-tools.md#claude-code).

## xpander in front of your gateway

Your gateway becomes one of xpander's providers. In [Models](https://platform.xpander.ai/governance/model-access), add it as a [custom endpoint](https://docs.xpander.ai/run/llm-gateway/providers-and-keys.md#custom-endpoints): usually **OpenAI-compatible**, with a **Base URL** that includes `/v1` (such as `https://ai-gateway.example.com/v1`), and **Create a new key** with the key your gateway issued for xpander. List the models with **Test connection** or **Add model**, then save.

* xpander sends your gateway only that key, never an xpander key or another provider's key.
* On xpander cloud the address must be public `https`. Private, loopback, link-local, cloud metadata and cluster addresses are refused on save and on each call ([Model endpoints on xpander cloud](https://docs.xpander.ai/run/llm-gateway/providers-and-keys.md#model-endpoints-on-xpander-cloud)). On Hybrid or Air-Gapped it can be private.
* Listed models are on for the organization when you save. A group with its own model list needs them ticked in **Who may use it…** ([Turn models on](https://docs.xpander.ai/run/llm-gateway/providers-and-keys.md#turn-models-on)). Otherwise callers get *This model is not enabled for you on the xpander LLM Gateway.*
* Call them as `<provider ID>::<model>`, such as `ai_gateway::gpt-4o-mini`.
* To count spend, set a price per 1M tokens (USD) with **Edit model** under **Keys and models…**. Without one, spend reads zero and dollar budgets don't count it. These calls are not charged in xpander credits.
* Claude Code can use these models too: xpander converts its Messages calls to the OpenAI-compatible format, so your gateway only needs `/v1/chat/completions`.

## Send records to your own observability

[Log destinations](https://docs.xpander.ai/run/llm-gateway/logs-export.md) copies every request record to an OpenTelemetry collector or your own bucket, never with prompt or response text.

## Next steps

> **[Add a custom endpoint](https://docs.xpander.ai/run/llm-gateway/providers-and-keys.md#custom-endpoints)**
>
> Every field of the form.

> **[Send records to your observability](https://docs.xpander.ai/run/llm-gateway/logs-export.md)**
>
> OpenTelemetry and buckets.


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