> 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 AI Gateway

LiteLLM ist ein Open-Source-AI-Gateway, das eine einheitliche OpenAI-kompatible API für über 100 Sprachmodell-Anbieter bereitstellt – einschließlich OpenAI, Anthropic, Azure, Bedrock, HuggingFace und lokal gehosteter Modelle. Setzen Sie es auf CLORE.AI ein, um alle Ihre LLM-API-Aufrufe über einen einzigen Endpunkt mit eingebauter Kostenverfolgung, Ratenbegrenzung und Fallback-Logik zu routen, zu load-balancen und zu verwalten.

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

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

## Serveranforderungen

| Parameter  | Minimum                     | Empfohlen                     |
| ---------- | --------------------------- | ----------------------------- |
| RAM        | 4 GB                        | 8 GB+                         |
| VRAM       | Nicht anwendbar (nur Proxy) | Nicht anwendbar               |
| 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 macht jedoch Sinn, es auf einem CLORE.AI-GPU-Server bereitzustellen, wenn Sie lokale Modelle (über Ollama, TGI, vLLM) zusammen mit LiteLLM als einheitliches Gateway auf derselben Maschine ausführen möchten.
{% endhint %}

## Schnelle Bereitstellung 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 persistieren       |

## Schritt-für-Schritt-Einrichtung

### 1. Mieten Sie einen Server auf CLORE.AI

LiteLLM funktioniert auch auf CPU-only-Servern hervorragend. Gehen Sie zu [CLORE.AI Marketplace](https://clore.ai/marketplace) und filtern Sie nach:

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

### 2. SSH auf Ihren Server

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

### 3. Erstellen Sie 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"

  # Load Balancer: Route zu mehreren Endpunkten
  - 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"  # Ändern Sie dies!
  alerting: []
EOF
```

### 4. Starten Sie LiteLLM

**Basisstart:**

```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:**

Starten Sie zuerst einen PostgreSQL-Container:

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

**Verwendung von 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. Überprüfen Sie den Server

```bash
# Prüfe Gesundheitszustand
curl http://localhost:4000/health

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

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

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

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

Verwenden Sie dies als Ihr `api_base` in jedem OpenAI-kompatiblen Client.

***

## Beispielanwendungen

### Beispiel 1: Direkter API-Aufruf über 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": "What is the capital of Germany?"}
    ]
  }'
```

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

```python
from openai import OpenAI

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

# Verwenden Sie jedes Modell aus Ihrer Konfiguration
response = client.chat.completions.create(
    model="gpt-4o-mini",  # oder "claude-3-5-sonnet", "mistral-7b-local"
    messages=[{"role": "user", "content": "Summarize the benefits of GPU computing."}],
)
print(response.choices[0].message.content)

# Wechseln Sie Modelle ohne Codeänderungen
response2 = client.chat.completions.create(
    model="claude-3-5-sonnet",
    messages=[{"role": "user", "content": "Same question, different model."}],
)
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": "Hello!"}],
    api_key="your-openai-key",
)

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

### Beispiel 4: Fallback-Konfiguration

Konfigurieren Sie automatische Fallbacks zwischen Modellen:

```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: Kosten-Tracking-Dashboard

Nachdem Sie PostgreSQL aktiviert haben, greifen Sie auf Ausgabenanalysen zu:

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

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

# Ausgabebericht erzeugen
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 (pro Benutzer API-Schlüssel)

Erstellen Sie separate Schlüssel mit Ratenbegrenzungen und Budgets:

```bash
# Erstellen Sie einen Schlüssel mit Budget
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
```

***

## Leistungs-Tipps

### 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 <5 ms:

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

### 2. Verwenden Sie asynchrone Anfragen

```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. Lokale Modell-Routing

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

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

Eine typische Einrichtung: Führen Sie Mistral 7B oder Llama 3 8B lokal auf einer Clore.ai RTX 3090 ($0.10–0.15/Stunde) aus, bearbeiten Sie dort 80% des Traffics und eskalieren Sie komplexe Aufgaben an GPT-4o. Kosteneinsparungen von 3–5× gegenüber rein cloudbasierten Setups sind üblich.

### 4. Timeouts und Wiederholungen festlegen

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

***

## Clore.ai GPU-Empfehlungen

LiteLLM selbst benötigt keine GPU — es ist ein Proxy. Die GPU-Auswahl ist nur dann relevant, wenn Sie lokale Inferenz daneben betreiben.

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

**Empfohlener Stack für einen Solo-Entwickler:** RTX 3090 + Mistral 7B + LiteLLM-Gateway. Gesamtkosten auf Clore.ai: \~0,12 $/Stunde. Bewältigt leicht \~50 Anfragen/Min, mit GPT-4o-Fallback für komplexe Aufgaben.

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

***

## Fehlerbehebung

### Problem: „Modell nicht gefunden“

Stellen Sie sicher, dass der Modellname in Ihrer Anfrage genau mit dem in `config.yaml`:

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

### Problem: „Authentifizierung fehlgeschlagen“

Überprüfen Sie Ihre `LITELLM_MASTER_KEY` Umgebungsvariable und verwenden Sie sie als Bearer-Token.

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

Starten Sie 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 Anfragen können langsamer sein, da Verbindungen aufgebaut werden.

### Problem: Datenbankverbindungsfehler

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

# Überprüfen Sie das Format der Verbindungszeichenfolge
DATABASE_URL="postgresql://user:password@host:5432/dbname"
```

### Problem: 429 Ratenbegrenzungsfehler von Anbietern

Konfigurieren Sie Fallbacks:

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

***

## Clore.ai GPU-Empfehlungen

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

| Einrichtung          | GPU             | Clore.ai-Preis | Anwendungsfall                                                   |
| -------------------- | --------------- | -------------- | ---------------------------------------------------------------- |
| Nur Cloud-API-Proxy  | Nur CPU         | \~$0.02/Stunde | Routen Sie zu OpenAI, Anthropic, Gemini — keine GPU erforderlich |
| Lokales vLLM-Backend | RTX 3090 (24GB) | \~$0.12/Stunde | Selbst gehostete 7B–13B-Modelle mit LiteLLM als Frontend         |
| Lokales vLLM-Backend | RTX 4090 (24GB) | \~$0.70/Stunde | Höherer Durchsatz für lokale 7B–34B-Modelle                      |
| Lokales vLLM-Backend | A100 40GB       | \~$1.20/Stunde | 70B-Modelle, produktiver lokaler Betrieb                         |

{% hint style="info" %}
**Am häufigsten verwendete Konfiguration:** Führen Sie LiteLLM als einheitlichen Proxy vor Ihren Clore.ai-gehosteten vLLM/Ollama-Instanzen aus. Das gibt Ihnen Anbieter-Fallbacks, Ratenbegrenzung, Kostenverfolgung und OpenAI-kompatibles Routing — während alle Inferenz lokal und kostengünstig bleibt.

**Beispielkosten:** Führen Sie den LiteLLM-Proxy auf einer CPU-only-Instanz (\~\~0,02 $/Stunde) aus und richten Sie ihn auf einen vLLM-Server auf einer RTX 3090 (\~\~0,12 $/Stunde). Gesamtkosten \~0,14 $/Stunde für eine produktionsbereite, selbst gehostete LLM-API mit Fallbacks, Protokollierung 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 Marketplace](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:

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

The question should be specific, self-contained, and written in natural language.
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.
