---
title: "LiteLLM integration"
description: "Settings for using LiteLLM with MiniRouter."
canonical_url: "https://minirouter.sh/docs/integrations/litellm"
markdown_url: "https://minirouter.sh/docs/integrations/litellm.md"
last_updated: "2026-09-26"
---

# LiteLLM

Reach every MiniRouter model from the LiteLLM SDK or proxy.

[Get a key](https://minirouter.sh/key)

[LiteLLM](https://docs.litellm.ai) is a Python SDK and proxy with one OpenAI-style interface. Add MiniRouter once and every app behind it reaches the [catalog](https://minirouter.sh/models), [routers](https://minirouter.sh/docs/auto-router) and your [presets](https://minirouter.sh/docs/presets), on one balance.

> **Note:** Prefix every model with `openai/`. LiteLLM strips it and sends the rest, such as `zai/glm-5.3-flash`, to MiniRouter.

## Quick start

### 1. Install the proxy

**pip**

```sh
pip install 'litellm[proxy]'
```

**uv**

```sh
uv tool install 'litellm[proxy]'
```

### 2. Export your key

[Create a key](https://minirouter.sh/key), then export it where the proxy runs.

**macOS / Linux**

```sh
export MINIROUTER_API_KEY=mr-live-YOUR-KEY-HERE
```

**Windows**

```powershell
setx MINIROUTER_API_KEY mr-live-YOUR-KEY-HERE
```

> **Tip:** Give the proxy its own key, so its spend shows separately in [Usage](https://minirouter.sh/dashboard/usage) and a limit stops only the proxy.

### 3. Add a model

```yaml
model_list:
  - model_name: glm-5.3-flash
    litellm_params:
      model: openai/zai/glm-5.3-flash
      api_base: https://api.minirouter.sh/v1
      api_key: os.environ/MINIROUTER_API_KEY
```

Clients of the proxy call the `model_name`. `litellm_params.model` is what MiniRouter receives.

### 4. Start and verify

```sh
litellm --config config.yaml
```

```sh
curl http://0.0.0.0:4000/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"glm-5.3-flash","messages":[{"role":"user","content":"Hello"}]}'
```

Open [Activity](https://minirouter.sh/dashboard/activity). The request lists its model, tokens and exact cost.

## Call from the Python SDK

No proxy needed. Pass the base URL and key on each call.

```python
import os
from litellm import completion

response = completion(
    model="openai/zai/glm-5.3-flash",
    api_base="https://api.minirouter.sh/v1",
    api_key=os.environ["MINIROUTER_API_KEY"],
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
```

> **Warning:** Set `api_base` to `https://api.minirouter.sh/v1` exactly. LiteLLM does not add `/v1` to a custom base.

## Add routers and presets

Each entry becomes one `model_name` for proxy clients.

```yaml
model_list:
  - model_name: auto-code
    litellm_params:
      model: openai/minirouter/auto:code
      api_base: https://api.minirouter.sh/v1
      api_key: os.environ/MINIROUTER_API_KEY
  - model_name: my-preset
    litellm_params:
      model: openai/@preset/your-slug
      api_base: https://api.minirouter.sh/v1
      api_key: os.environ/MINIROUTER_API_KEY
```

| litellm_params.model | Uses |
| --- | --- |
| `openai/minirouter/auto:code` | A tool-capable model [Auto](https://minirouter.sh/docs/auto-router) picks. |
| `openai/minirouter/fusion` | The model and effort [Fusion](https://minirouter.sh/docs/fusion) picks. |
| `openai/@preset/your-slug` | Your saved [preset](https://minirouter.sh/docs/presets), editable from the [dashboard](https://minirouter.sh/dashboard/presets). |

## Keep spend in check

> **Warning:** Every proxy user spends from the key in `config.yaml`. Cap that key before sharing the proxy.

- [Own key](https://minirouter.sh/dashboard/keys): One key for the proxy.
- [Spend cap](https://minirouter.sh/docs/rate-limits): Daily or monthly limit on that key.
- [Activity](https://minirouter.sh/dashboard/activity): Every request and its cost.

Restrict models or filter content with [Guardrails](https://minirouter.sh/docs/guardrails).

## Recommended models

| Model | Why |
| --- | --- |
| [`zai/glm-5.3-flash`](https://minirouter.sh/models/zai/glm-5.3-flash) | Best current balance of coding ability, agentic performance, context and cost. |
| [`openai/gpt-5.6-sol`](https://minirouter.sh/models/openai/gpt-5.6-sol) | Higher-intelligence option when task quality matters more than spend. |
| [`spacexai/grok-4.6`](https://minirouter.sh/models/spacexai/grok-4.6) | Strong agentic alternative with a 500K-token window. |
| [`google/gemini-3.8-flash`](https://minirouter.sh/models/google/gemini-3.8-flash) | Multimodal coding alternative with a 1M-token window. |

Browse every model in the [catalog](https://minirouter.sh/models).

## Troubleshooting

### 404 from the gateway

Set api_base to https://api.minirouter.sh/v1 exactly. LiteLLM's OpenAI transport does not add /v1 for a custom api_base, so include it yourself and nothing after it.

Error: [400 `invalid_request`](https://minirouter.sh/docs/errors#invalid_request).

### Cost tracking shows $0 for every request

LiteLLM prices from its own model table, which does not list our ids. Billing on our side is unaffected; read the x-minirouter-balance-usd header for the truth.

### 401 on every request

Wrong or rotated key. Keys start with mr-live-; after a rotation the old key keeps working for 24 hours, then dies.

Error: [401 `invalid_api_key`](https://minirouter.sh/docs/errors#invalid_api_key).

### 402 before any tokens arrive

Balance below the estimated cost of the request. Top up (from $0.50 with direct Solana payments) — and watch the x-minirouter-balance-usd header, the low-balance signal every response carries.

Error: [402 `insufficient_credits`](https://minirouter.sh/docs/errors#insufficient_credits).

Every error code, with its fix: [Errors](https://minirouter.sh/docs/errors).

## Next steps

- [Presets](https://minirouter.sh/docs/presets): Save a model and its settings under one name.
- [Guardrails](https://minirouter.sh/docs/guardrails): Budgets and model lists per key.
- [Auto router](https://minirouter.sh/docs/auto-router): Let MiniRouter pick the model.
