> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/litellm.md).

# LiteLLM KI-Gateway

Deploye LiteLLM als KI-Gateway-Proxy für 100+ LLMs auf Clore.ai-GPUs

LiteLLM ist ein Open-Source-AI-Gateway, das eine einheitliche, OpenAI-kompatible API für über 100 Anbieter von Sprachmodellen bereitstellt — darunter OpenAI, Anthropic, Azure, Bedrock, HuggingFace und lokal gehostete Modelle. Deploye es auf CLORE.AI, um alle deine LLM-API-Aufrufe über einen einzigen Endpunkt zu routen, per Lastverteilung zu verteilen und zu verwalten — mit integrierter Kostenverfolgung, Ratenbegrenzung und Fallback-Logik.

Die wahre Stärke von LiteLLM zeigt sich im großen Maßstab: Teams, die gemischte lokale+Cloud-Stacks betreiben, können Modelle im laufenden Betrieb austauschen, ohne Anwendungscode anzufassen. Ersetze `gpt-4o` mit `mistral-7b-local` in der Konfiguration, neu starten — fertig.

{% hint style="success" %}
Alle Beispiele können auf GPU-Servern ausgeführt werden, die gemietet wurden über [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Serveranforderungen

| Parameter  | Minimum            | Empfohlen                     |
| ---------- | ------------------ | ----------------------------- |
| RAM        | 4 GB               | 8 GB+                         |
| VRAM       | N/A (nur Proxy)    | k. A.                         |
| Festplatte | 10 GB              | 20 GB+                        |
| GPU        | Nicht erforderlich | Optional (für lokale Modelle) |

{% hint style="info" %}
LiteLLM selbst ist ein CPU-basierter Proxy und benötigt keine GPU. Es ergibt jedoch Sinn, es auf einem CLORE.AI-GPU-Server zu deployen, wenn du lokale Modelle (über Ollama, TGI, vLLM) zusammen mit LiteLLM als einheitliches Gateway auf derselben Maschine ausführen möchtest.
{% endhint %}

## Schnellbereitstellung auf CLORE.AI

**Docker-Image:** `ghcr.io/berriai/litellm:main-latest`

**Ports:** `22/tcp`, `4000/http`

**Umgebungsvariablen:**

| Variable             | Beispiel           | Beschreibung                                     |
| -------------------- | ------------------ | ------------------------------------------------ |
| `OPENAI_API_KEY`     | `sk-xxx...`        | OpenAI-API-Schlüssel                             |
| `ANTHROPIC_API_KEY`  | `sk-ant-xxx...`    | Anthropic-API-Schlüssel                          |
| `AZURE_API_KEY`      | `xxx...`           | Azure OpenAI-Schlüssel                           |
| `LITELLM_MASTER_KEY` | `sk-my-master-key` | Master-Authentifizierungsschlüssel für den Proxy |
| `DATABASE_URL`       | `postgresql://...` | PostgreSQL für Kostenverfolgung                  |
| `STORE_MODEL_IN_DB`  | `True`             | Modellkonfiguration in der DB speichern          |

## Schritt-für-Schritt-Einrichtung

### 1. Miete einen Server auf CLORE.AI

LiteLLM funktioniert auch auf reinen CPU-Servern hervorragend. Gehe zu [CLORE.AI-Marktplatz](https://clore.ai/marketplace) und filtere nach:

* Günstigste CPU-Server für ein reines Proxy-Setup
* GPU-Server (RTX 3090+) wenn du auch lokale Modelle ausführen möchtest

### 2. Verbinden Sie sich per SSH mit Ihrem Server

```bash
ssh -p <PORT> root@<SERVER_IP>
```

### 3. Erstelle eine Konfigurationsdatei

LiteLLM verwendet eine YAML-Konfigurationsdatei, um Modelle zu definieren:

```bash
mkdir -p /root/litellm
cat > /root/litellm/config.yaml << 'EOF'
model_list:
  # OpenAI-Modelle
  - model_name: gpt-4o
    litellm_params:
      model: openai/gpt-4o
      api_key: "os.environ/OPENAI_API_KEY"

  - model_name: gpt-4o-mini
    litellm_params:
      model: openai/gpt-4o-mini
      api_key: "os.environ/OPENAI_API_KEY"

  # Anthropic-Modelle
  - model_name: claude-3-5-sonnet
    litellm_params:
      model: anthropic/claude-3-5-sonnet-20241022
      api_key: "os.environ/ANTHROPIC_API_KEY"

  # Lokales Modell über TGI (auf demselben Server, Port 8080)
  - model_name: mistral-7b-local
    litellm_params:
      model: openai/mistralai/Mistral-7B-Instruct-v0.3
      api_base: "http://localhost:8080/v1"
      api_key: "none"

  # Lastverteiler: Weiterleitung an mehrere Endpunkte
  - model_name: fast-model
    litellm_params:
      model: openai/gpt-4o-mini
      api_key: "os.environ/OPENAI_API_KEY"
    model_info:
      mode: chat

litellm_settings:
  drop_params: True
  set_verbose: False
  num_retries: 3
  request_timeout: 60

general_settings:
  master_key: "sk-my-secret-master-key"  # Das hier ändern!
  alerting: []
EOF
```

### 4. Starte LiteLLM

**Grundlegender Start:**

```bash
docker run -d \
  --name litellm \\
  --network host \\
  -v /root/litellm/config.yaml:/app/config.yaml \\
  -e OPENAI_API_KEY=sk-your-openai-key \\
  -e ANTHROPIC_API_KEY=sk-ant-your-anthropic-key \\
  -e LITELLM_MASTER_KEY=sk-my-secret-master-key \\
  ghcr.io/berriai/litellm:main-latest \\
  --config /app/config.yaml \\
  --port 4000 \\
  --host 0.0.0.0
```

**Mit PostgreSQL für Kostenverfolgung:**

Zuerst einen PostgreSQL-Container starten:

```bash
docker run -d \
  --name postgres \\
  -e POSTGRES_PASSWORD=litellm_pass \\
  -e POSTGRES_DB=litellm \\
  -p 5432:5432 \\
  postgres:15

# Dann LiteLLM mit DB starten
docker run -d \
  --name litellm \\
  -p 4000:4000 \\
  -v /root/litellm/config.yaml:/app/config.yaml \\
  -e OPENAI_API_KEY=sk-your-openai-key \\
  -e ANTHROPIC_API_KEY=sk-ant-your-anthropic-key \\
  -e LITELLM_MASTER_KEY=sk-my-secret-master-key \\
  -e DATABASE_URL="postgresql://postgres:litellm_pass@localhost:5432/litellm" \\
  --network host \\
  ghcr.io/berriai/litellm:main-latest \\
  --config /app/config.yaml \\
  --port 4000 \\
  --host 0.0.0.0
```

**Mit Docker Compose (empfohlen):**

```bash
cat > /root/litellm/docker-compose.yml << 'EOF'
version: "3.8"
services:
  litellm:
    image: ghcr.io/berriai/litellm:main-latest
    ports:
      - "4000:4000"
    volumes:
      - ./config.yaml:/app/config.yaml
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - LITELLM_MASTER_KEY=sk-my-secret-master-key
      - DATABASE_URL=postgresql://postgres:litellm_pass@db:5432/litellm
    command: --config /app/config.yaml --port 4000 --host 0.0.0.0
    depends_on:
      - db

  db:
    image: postgres:15
    environment:
      POSTGRES_PASSWORD: litellm_pass
      POSTGRES_DB: litellm
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:
EOF

cd /root/litellm && docker compose up -d
```

### 5. Server überprüfen

```bash
# Status prüfen
curl http://localhost:4000/health

# Verfügbare Modelle auflisten
curl http://localhost:4000/v1/models \\
  -H "Authorization: Bearer sk-my-secret-master-key"
```

### 6. Zugriff über den CLORE.AI HTTP-Proxy

Deine CLORE.AI-http\_pub-URL für Port 4000:

```
https://<order-id>-4000.clore.ai/v1
```

Verwende dies als dein `api_base` in jedem OpenAI-kompatiblen Client.

***

## Anwendungsbeispiele

### Beispiel 1: Direkter API-Aufruf über den Proxy

```bash
curl http://localhost:4000/v1/chat/completions \\
  -X POST \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer sk-my-secret-master-key" \\
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {"role": "user", "content": "Was ist die Hauptstadt von Deutschland?"}
    ]
  }'
```

### Beispiel 2: OpenAI Python SDK mit LiteLLM-Proxy

```python
from openai import OpenAI

# Ändere einfach base_url und api_key — alles andere ist identisch
client = OpenAI(
    base_url="http://localhost:4000/v1",
    api_key="sk-my-secret-master-key",
)

# Verwende ein beliebiges Modell aus deiner Konfiguration
response = client.chat.completions.create(
    model="gpt-4o-mini",  # oder "claude-3-5-sonnet", "mistral-7b-local"
    messages=[{"role": "user", "content": "Fasse die Vorteile des GPU-Computings zusammen."}],
)
print(response.choices[0].message.content)

# Modelle ohne Codeänderungen wechseln
response2 = client.chat.completions.create(
    model="claude-3-5-sonnet",
    messages=[{"role": "user", "content": "Gleiche Frage, anderes Modell."}],
)
print(response2.choices[0].message.content)
```

### Beispiel 3: LiteLLM Python SDK (direkt)

```python
import litellm

# Direkt ohne Proxy verwenden
response = litellm.completion(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hallo!"}],
    api_key="your-openai-key",
)

# Oder über deinen Proxy routen
response = litellm.completion(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "Hallo!"}],
    api_base="http://localhost:4000",
    api_key="sk-my-secret-master-key",
)
```

### Beispiel 4: Fallback-Konfiguration

Automatische Fallbacks zwischen Modellen konfigurieren:

```yaml
# In config.yaml
model_list:
  - model_name: smart-fallback
    litellm_params:
      model: gpt-4o
      api_key: "os.environ/OPENAI_API_KEY"

router_settings:
  routing_strategy: least-busy
  model_group_alias:
    "gpt-4-fallback":
      - "gpt-4o"
      - "claude-3-5-sonnet"
      - "mistral-7b-local"
  num_retries: 3
  fallbacks:
    - gpt-4o:
        - claude-3-5-sonnet
        - mistral-7b-local
```

### Beispiel 5: Dashboard zur Kostenverfolgung

Nach Aktivierung von PostgreSQL kannst du auf Ausgabenanalysen zugreifen:

```bash
# Ausgaben nach Benutzer abrufen
curl http://localhost:4000/global/spend/users \\
  -H "Authorization: Bearer sk-my-secret-master-key"

# Ausgaben nach Modell abrufen
curl http://localhost:4000/global/spend/models \\
  -H "Authorization: Bearer sk-my-secret-master-key"

# Ausgabenbericht erstellen
curl "http://localhost:4000/global/spend?start_date=2024-01-01&end_date=2024-12-31" \\
  -H "Authorization: Bearer sk-my-secret-master-key"
```

***

## Konfiguration

### Virtuelle Schlüssel (API-Schlüssel pro Benutzer)

Erstelle separate Schlüssel mit Ratenlimits und Budgets:

```bash
# Einen Schlüssel mit Budget erstellen
curl http://localhost:4000/key/generate \\
  -X POST \\
  -H "Content-Type: application/json" \\
  -H "Authorization: Bearer sk-my-secret-master-key" \\
  -d '{
    "models": ["gpt-4o-mini", "claude-3-5-sonnet"],
    "duration": "30d",
    "max_budget": 10.0,
    "metadata": {"user_id": "user_123"}
  }'
```

### Lastverteilung

```yaml
model_list:
  # Round-Robin zwischen mehreren OpenAI-API-Schlüsseln
  - model_name: gpt-4o
    litellm_params:
      model: openai/gpt-4o
      api_key: sk-key-1
  - model_name: gpt-4o
    litellm_params:
      model: openai/gpt-4o
      api_key: sk-key-2

router_settings:
  routing_strategy: least-busy  # oder: simple-shuffle, latency-based-routing
```

### Caching

```yaml
litellm_settings:
  cache: True
  cache_params:
    type: redis
    host: localhost
    port: 6379
    ttl: 3600  # 1 Stunde
```

### Ratenbegrenzung

```yaml
general_settings:
  default_team_settings:
    tpm_limit: 100000   # Tokens pro Minute
    rpm_limit: 1000     # Anfragen pro Minute
```

***

## Leistungstipps

### 1. Caching für wiederholte Prompts aktivieren

Für RAG- oder Chatbot-Anwendungen mit häufigen Fragen senkt Redis-Caching die Kosten um 30–70 % und reduziert die P50-Latenz bei Cache-Treffern auf unter 5 ms:

```yaml
litellm_settings:
  cache: True
  cache_params:
    type: redis
    host: localhost
    port: 6379
```

### 2. Asynchrone Anfragen verwenden

```python
import asyncio
import litellm

async def batch_complete(prompts):
    tasks = [
        litellm.acompletion(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": p}],
        )
        for p in prompts
    ]
    return await asyncio.gather(*tasks)

results = asyncio.run(batch_complete(["Hello", "World", "Test"]))
```

### 3. Lokales Modell-Routing

Leite günstige/einfache Anfragen an lokale Modelle auf Clore.ai-GPUs weiter, komplexe an GPT-4:

```yaml
model_list:
  - model_name: smart-router
    litellm_params:
      model: openai/gpt-4o
      api_key: "os.environ/OPENAI_API_KEY"
```

Ein typisches Setup: Mistral 7B oder Llama 3 8B lokal auf einer Clore.ai RTX 3090 ($0.07–0.21/Stunde) ausführen, dort 80 % des Traffics verarbeiten und komplexe Aufgaben an GPT-4o eskalieren. Kosteneinsparungen von 3–5× gegenüber reinem Cloud-Betrieb sind üblich.

### 4. Timeouts und Wiederholungen festlegen

```yaml
litellm_settings:
  request_timeout: 30
  num_retries: 3
  retry_after: 5
```

***

## GPU-Empfehlungen für Clore.ai

LiteLLM selbst benötigt keine GPU — es ist ein Proxy. Die GPU-Wahl ist nur dann relevant, wenn du lokale Inferenz zusätzlich dazu betreibst.

| Lokales Modell                              | GPU                | Warum                                                                  |
| ------------------------------------------- | ------------------ | ---------------------------------------------------------------------- |
| Mistral 7B / Llama 3 8B (bf16)              | **RTX 3090** 24 GB | Passt bequem, Durchsatz von etwa 200 tok/s                             |
| Mixtral 8×7B oder Llama 3 70B (AWQ)         | **RTX 4090** 24 GB | Schnellere Speicherbandbreite als die 3090; passt für 70B AWQ 4-bit    |
| Llama 3 70B (bf16) oder Multi-Model-Serving | **A100 80 GB**     | Mehrere 7–13B-Modelle gleichzeitig ausführen; HBM2e für geringe Latenz |

**Empfohlener Stack für einen einzelnen Entwickler:** RTX 3090 + Mistral 7B + LiteLLM-Gateway. Gesamtkosten auf Clore.ai: $0.07–0.21/Stunde. Bewältigt problemlos etwa 50 Anfragen/Minute, mit GPT-4o-Fallback für komplexe Aufgaben.

**Team-/Produktions-Stack:** A100 80GB, Llama 3 70B + LiteLLM + PostgreSQL ausführen. Bedient 20+ gleichzeitige Benutzer, vollständige Kostenverfolgung, für die meisten Anfragen keine Cloud-LLM-Kosten.

***

## Fehlerbehebung

### Problem: „Modell nicht gefunden"

Stelle sicher, dass der Modellname in deiner Anfrage exakt mit dem übereinstimmt, was in `config.yaml`:

```bash
curl http://localhost:4000/v1/models -H "Authorization: Bearer sk-my-secret-master-key"
```

### Problem: „Authentifizierung fehlgeschlagen"

Prüfe deine `LITELLM_MASTER_KEY` Umgebungsvariable und verwende sie als Bearer-Token.

### Problem: Konfigurationsänderungen werden nicht übernommen

Starte den Container nach Konfigurationsänderungen neu:

```bash
docker restart litellm
```

### Problem: Hohe Latenz bei der ersten Anfrage

LiteLLM lädt Modellkonfigurationen beim Start. Die ersten paar Anfragen können langsamer sein, während Verbindungen aufgebaut werden.

### Problem: Fehler bei der Datenbankverbindung

```bash
# Prüfe, ob PostgreSQL läuft
docker logs postgres

# Verifiziere das Format der Verbindungszeichenfolge
DATABASE_URL="postgresql://user:password@host:5432/dbname"
```

### Problem: 429-Ratenlimit-Fehler von Anbietern

Fallbacks konfigurieren:

```yaml
litellm_settings:
  num_retries: 5
  fallbacks:
    - gpt-4o: [claude-3-5-sonnet]
```

***

## GPU-Empfehlungen für Clore.ai

LiteLLM ist ein API-Gateway/Proxy — es führt selbst keine Inferenz durch. Die GPU-Auswahl hängt davon ab, ob du zu Cloud-APIs oder lokalen Modellen routest.

| Einrichtung          | GPU              | Clore.ai-Preis                            | Anwendungsfall                                                      |
| -------------------- | ---------------- | ----------------------------------------- | ------------------------------------------------------------------- |
| Nur Cloud-API-Proxy  | Nur CPU          | \~$0,02/Stunde                            | Weiterleitung an OpenAI, Anthropic, Gemini — keine GPU erforderlich |
| Lokales vLLM-Backend | RTX 3090 (24 GB) | ca. 0,07–0,21 $/h                         | Selbst gehostete 7B–13B-Modelle mit LiteLLM als Frontend            |
| Lokales vLLM-Backend | RTX 4090 (24 GB) | ca. 0,14–0,42 $/h                         | Lokale 7B–34B-Modelle mit höherem Durchsatz                         |
| Lokales vLLM-Backend | A100 40GB        | [Bare Metal](https://clore.ai/bare-metal) | 70B-Modelle, lokales Serving für den Produktionseinsatz             |

{% hint style="info" %}
**Gängigstes Setup:** Betreibe LiteLLM als einheitlichen Proxy vor deinen auf Clore.ai gehosteten vLLM-/Ollama-Instanzen. Das gibt dir Provider-Fallbacks, Ratenbegrenzung, Kostenverfolgung und OpenAI-kompatibles Routing — während die gesamte Inferenz lokal und günstig bleibt.

**Beispielkosten:** Betreibe den LiteLLM-Proxy auf einer CPU-only-Instanz ($0.07–0.21/Stunde) und verweise ihn auf einen vLLM-Server auf einer RTX 3090 ($0.07–0.21/Stunde). Gesamtkosten: $0.07–0.21/Stunde für eine produktionsreife, selbst gehostete LLM-API mit Fallbacks, Logging und Ratenbegrenzung.
{% endhint %}

***

## Links

* [GitHub](https://github.com/BerriAI/litellm)
* [Dokumentation](https://docs.litellm.ai)
* [Docker Hub / GHCR](https://github.com/BerriAI/litellm/pkgs/container/litellm)
* [Unterstützte Anbieter](https://docs.litellm.ai/docs/providers)
* [CLORE.AI-Marktplatz](https://clore.ai/marketplace)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/sprachmodelle/litellm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
