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

Connect a gateway you already run in either direction: your gateway calls xpander, or xpander calls your gateway. Either way, xpander checks each call against your 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-cc972fcf.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, and 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 here, export it as `XPANDER_GATEWAY_KEY`:

```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, or [connect it to xpander directly](https://docs.xpander.ai/use/ai-models-and-keys.md#connect-a-coding-tool).

## xpander in front of your gateway

In [Models](https://platform.xpander.ai/governance/model-access), add your gateway as a [custom endpoint](https://docs.xpander.ai/run/llm-gateway/providers-and-keys.md#custom-endpoints): usually **OpenAI-compatible**, a **Base URL** with `/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` ([address rules](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…**](https://docs.xpander.ai/run/llm-gateway/providers-and-keys.md#who-may-use-which-models), or callers get *This model is not enabled for you on the xpander AI 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**. Without one, spend reads zero and dollar budgets don't count it. These calls are never 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`.

### Route a self-hosted install through your gateway

On Hybrid and Air-Gapped, each provider's upstream is an environment variable on the Agent Controller, so your gateway can sit between xpander and the vendor. The controller egresses to `api.anthropic.com` by default; with an override, the override is the only host it needs. xpander applies its policy, budget and record before the call leaves. Your gateway's other clients stay outside xpander's controls.

> [accordion] The controller variable per provider
>
> | Provider | Controller environment |
> | - | - |
> | Anthropic | `LLM_PROXY_ANTHROPIC_BASE_URL` |
> | Amazon Bedrock | `LLM_PROXY_AMAZON_BEDROCK_BASE_URL` (a VPC or PrivateLink runtime endpoint on Air-Gapped) |
> | Any OpenAI-compatible runtime (vLLM, Ollama, NVIDIA NIM, your gateway) | The provider's `apiBase` under `global.llm` |

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

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

> [card] [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.