> 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-hi/language-models/litellm.md).

# LiteLLM AI Gateway

Clore.ai GPUs पर 100+ LLMs के लिए AI Gateway प्रॉक्सी के रूप में LiteLLM डिप्लॉय करें

LiteLLM एक ओपन-सोर्स AI गेटवे है जो 100+ भाषा मॉडल प्रदाताओं के लिए एकीकृत OpenAI-संगत API प्रदान करता है — जिनमें OpenAI, Anthropic, Azure, Bedrock, HuggingFace, और स्थानीय रूप से होस्ट किए गए मॉडल शामिल हैं। इसे CLORE.AI पर डिप्लॉय करें ताकि आप अपनी सभी LLM API कॉल्स को लागत ट्रैकिंग, दर-सीमांकन, और फ़ॉलबैक लॉजिक के साथ एक ही endpoint से रूट, लोड-बैलेंस और प्रबंधित कर सकें।

LiteLLM की असली ताकत बड़े पैमाने पर दिखती है: स्थानीय+क्लाउड मिश्रित स्टैक चलाने वाली टीमें एप्लिकेशन कोड को छुए बिना मॉडल तुरंत बदल सकती हैं। बदलें `gpt-4o` के साथ `mistral-7b-local` को कॉन्फ़िग में, रीस्टार्ट करें — हो गया।

{% hint style="success" %}
सभी उदाहरण GPU सर्वरों पर चलाए जा सकते हैं, जिन्हें किराए पर लिया गया है [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace).
{% endhint %}

## सर्वर आवश्यकताएँ

| पैरामीटर | न्यूनतम                   | अनुशंसित                         |
| -------- | ------------------------- | -------------------------------- |
| RAM      | 4 GB                      | 8 GB+                            |
| VRAM     | लागू नहीं (केवल प्रॉक्सी) | उपलब्ध नहीं                      |
| डिस्क    | 10 GB                     | 20 GB+                           |
| GPU      | आवश्यक नहीं               | वैकल्पिक (स्थानीय मॉडलों के लिए) |

{% hint style="info" %}
LiteLLM स्वयं एक CPU-आधारित प्रॉक्सी है और इसे GPU की आवश्यकता नहीं होती। हालांकि, इसे CLORE.AI GPU सर्वर पर डिप्लॉय करना तब समझ में आता है जब आप LiteLLM के साथ उसी मशीन पर स्थानीय मॉडल (Ollama, TGI, vLLM के माध्यम से) को एकीकृत गेटवे के रूप में चलाना चाहते हैं।
{% endhint %}

## CLORE.AI पर त्वरित परिनियोजन

**Docker इमेज:** `ghcr.io/berriai/litellm:main-latest`

**पोर्ट:** `22/tcp`, `4000/http`

**Environment Variables:**

| वेरिएबल              | उदाहरण             | विवरण                                            |
| -------------------- | ------------------ | ------------------------------------------------ |
| `OPENAI_API_KEY`     | `sk-xxx...`        | OpenAI API कुंजी                                 |
| `ANTHROPIC_API_KEY`  | `sk-ant-xxx...`    | Anthropic API कुंजी                              |
| `AZURE_API_KEY`      | `xxx...`           | Azure OpenAI कुंजी                               |
| `LITELLM_MASTER_KEY` | `sk-my-master-key` | प्रॉक्सी के लिए मास्टर प्रामाणिकरण कुंजी         |
| `DATABASE_URL`       | `postgresql://...` | लागत ट्रैकिंग के लिए PostgreSQL                  |
| `STORE_MODEL_IN_DB`  | `True`             | मॉडल कॉन्फ़िगरेशन को DB में स्थायी रूप से सहेजें |

## चरण-दर-चरण सेटअप

### 1. CLORE.AI पर एक सर्वर किराए पर लें

LiteLLM केवल CPU वाले सर्वरों पर भी बढ़िया काम करता है। जाएँ [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace) और इनके लिए फ़िल्टर करें:

* केवल प्रॉक्सी सेटअप के लिए सबसे कम कीमत वाले CPU सर्वर
* यदि आप स्थानीय मॉडल भी चलाना चाहते हैं तो GPU सर्वर (RTX 3090+)

### 2. अपने Server में SSH करें

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

### 3. एक कॉन्फ़िग फ़ाइल बनाएं

LiteLLM मॉडल परिभाषित करने के लिए YAML कॉन्फ़िग फ़ाइल का उपयोग करता है:

```bash
mkdir -p /root/litellm
cat > /root/litellm/config.yaml << 'EOF'
model_list:
  # OpenAI मॉडल
  - 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 मॉडल
  - model_name: claude-3-5-sonnet
    litellm_params:
      model: anthropic/claude-3-5-sonnet-20241022
      api_key: "os.environ/ANTHROPIC_API_KEY"

  # स्थानीय मॉडल TGI के माध्यम से (उसी सर्वर पर, पोर्ट 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"

  # लोड बैलेंसर: कई endpoints पर रूट करें
  - 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"  # इसे बदलें!
  alerting: []
EOF
```

### 4. LiteLLM लॉन्च करें

**बेसिक लॉन्च:**

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

**लागत ट्रैकिंग के लिए PostgreSQL के साथ:**

सबसे पहले, PostgreSQL कंटेनर शुरू करें:

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

# फिर DB के साथ LiteLLM लॉन्च करें
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
```

**Docker Compose का उपयोग करना (अनुशंसित):**

```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. सर्वर सत्यापित करें

```bash
# स्वास्थ्य जाँचें
curl http://localhost:4000/health

# उपलब्ध मॉडल सूचीबद्ध करें
curl http://localhost:4000/v1/models \
  -H "Authorization: Bearer sk-my-secret-master-key"
```

### 6. CLORE.AI HTTP प्रॉक्सी के माध्यम से पहुँचें

पोर्ट 4000 के लिए आपका CLORE.AI http\_pub URL:

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

इसे अपने रूप में उपयोग करें `api_base` किसी भी OpenAI-संगत क्लाइंट में।

***

## उपयोग के उदाहरण

### उदाहरण 1: प्रॉक्सी के माध्यम से प्रत्यक्ष API कॉल

```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": "जर्मनी की राजधानी क्या है?"}
    ]
  }'
```

### उदाहरण 2: LiteLLM प्रॉक्सी के साथ OpenAI Python SDK

```python
from openai import OpenAI

# बस base_url और api_key बदलें — बाकी सब वैसा ही है
client = OpenAI(
    base_url="http://localhost:4000/v1",
    api_key="sk-my-secret-master-key",
)

# अपने कॉन्फ़िग से कोई भी मॉडल उपयोग करें
response = client.chat.completions.create(
    model="gpt-4o-mini",  # या "claude-3-5-sonnet", "mistral-7b-local"
    messages=[{"role": "user", "content": "GPU कंप्यूटिंग के लाभों का सारांश दें।"}],
)
print(response.choices[0].message.content)

# बिना कोड बदलाव के मॉडल बदलें
response2 = client.chat.completions.create(
    model="claude-3-5-sonnet",
    messages=[{"role": "user", "content": "वही प्रश्न, लेकिन अलग मॉडल।"}],
)
print(response2.choices[0].message.content)
```

### उदाहरण 3: LiteLLM Python SDK (प्रत्यक्ष)

```python
import litellm

# प्रॉक्सी के बिना सीधे उपयोग करें
response = litellm.completion(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "नमस्ते!"}],
    api_key="your-openai-key",
)

# या अपने प्रॉक्सी के माध्यम से रूट करें
response = litellm.completion(
    model="openai/gpt-4o-mini",
    messages=[{"role": "user", "content": "नमस्ते!"}],
    api_base="http://localhost:4000",
    api_key="sk-my-secret-master-key",
)
```

### उदाहरण 4: फ़ॉलबैक कॉन्फ़िगरेशन

मॉडलों के बीच स्वचालित फ़ॉलबैक कॉन्फ़िगर करें:

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

### उदाहरण 5: लागत ट्रैकिंग डैशबोर्ड

PostgreSQL सक्षम करने के बाद, खर्च विश्लेषण तक पहुँचें:

```bash
# उपयोगकर्ता के अनुसार खर्च प्राप्त करें
curl http://localhost:4000/global/spend/users \
  -H "Authorization: Bearer sk-my-secret-master-key"

# मॉडल के अनुसार खर्च प्राप्त करें
curl http://localhost:4000/global/spend/models \
  -H "Authorization: Bearer sk-my-secret-master-key"

# खर्च रिपोर्ट जनरेट करें
curl "http://localhost:4000/global/spend?start_date=2024-01-01&end_date=2024-12-31" \
  -H "Authorization: Bearer sk-my-secret-master-key"
```

***

## कॉन्फ़िगरेशन

### वर्चुअल कुंजियाँ (प्रति-उपयोगकर्ता API कुंजियाँ)

दर सीमाओं और बजट के साथ अलग-अलग कुंजियाँ बनाएं:

```bash
# बजट के साथ एक कुंजी बनाएं
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"}
  }'
```

### लोड बैलेंसिंग

```yaml
model_list:
  # कई OpenAI API कुंजियों के बीच राउंड-रॉबिन
  - 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  # या: simple-shuffle, latency-based-routing
```

### कैशिंग

```yaml
litellm_settings:
  cache: True
  cache_params:
    type: redis
    host: localhost
    port: 6379
    ttl: 3600  # 1 घंटा
```

### दर सीमांकन

```yaml
general_settings:
  default_team_settings:
    tpm_limit: 100000   # प्रति मिनट टोकन
    rpm_limit: 1000     # प्रति मिनट अनुरोध
```

***

## प्रदर्शन सुझाव

### 1. दोहराए जाने वाले prompts के लिए कैशिंग सक्षम करें

सामान्य प्रश्नों वाले RAG या chatbot अनुप्रयोगों के लिए, Redis caching लागत को 30–70% तक घटाता है और cache hit पर P50 latency को <5ms तक लाता है:

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

### 2. Async अनुरोधों का उपयोग करें

```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. स्थानीय मॉडल रूटिंग

सस्ते/सरल अनुरोधों को Clore.ai GPUs पर स्थानीय मॉडलों तक, और जटिल अनुरोधों को GPT-4 तक रूट करें:

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

एक सामान्य सेटअप: Mistral 7B या Llama 3 8B को Clore.ai RTX 3090 ($0.07–0.21/hr) पर स्थानीय रूप से चलाएँ, वहाँ 80% ट्रैफ़िक संभालें, और जटिल कार्यों को GPT-4o पर बढ़ाएँ। केवल क्लाउड पर निर्भर रहने की तुलना में 3–5× लागत बचत आम है।

### 4. टाइमआउट और पुनः प्रयास सेट करें

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

***

## Clore.ai GPU अनुशंसाएँ

LiteLLM स्वयं को GPU की आवश्यकता नहीं — यह एक प्रॉक्सी है। GPU का चुनाव केवल तब मायने रखता है जब आप इसके साथ-साथ स्थानीय inference को सह-डिप्लॉय कर रहे हों।

| स्थानीय मॉडल                              | GPU                | क्यों                                                    |
| ----------------------------------------- | ------------------ | -------------------------------------------------------- |
| Mistral 7B / Llama 3 8B (bf16)            | **RTX 3090** 24 GB | आराम से फिट होता है, \~200 tok/s throughput              |
| Mixtral 8×7B या Llama 3 70B (AWQ)         | **RTX 4090** 24 GB | 3090 से तेज़ memory bandwidth; 70B AWQ 4-bit फिट होता है |
| Llama 3 70B (bf16) या multi-model serving | **A100 80 GB**     | एक साथ कई 7–13B मॉडल चलाएँ; कम latency के लिए HBM2e      |

**एकल डेवलपर के लिए अनुशंसित स्टैक:** RTX 3090 + Mistral 7B + LiteLLM gateway. Clore.ai पर कुल लागत: $0.07–0.21/hr। लगभग 50 req/min आसानी से संभालता है, जटिल कार्यों के लिए GPT-4o फ़ॉलबैक के साथ।

**टीम / प्रोडक्शन स्टैक:** A100 80GB, Llama 3 70B + LiteLLM + PostgreSQL चलाएँ। 20+ समकालिक उपयोगकर्ताओं को सेवा देता है, पूर्ण लागत ट्रैकिंग, और अधिकांश अनुरोधों के लिए शून्य cloud LLM खर्च।

***

## समस्या निवारण

### समस्या: "model not found"

सुनिश्चित करें कि आपके अनुरोध में model name ठीक वही है जो इसमें है `config.yaml`:

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

### समस्या: "authentication failed"

अपना `LITELLM_MASTER_KEY` environment variable जांचें और उसे Bearer token के रूप में उपयोग करें।

### समस्या: कॉन्फ़िग परिवर्तन परिलक्षित नहीं हो रहे

कॉन्फ़िग परिवर्तन के बाद कंटेनर रीस्टार्ट करें:

```bash
docker restart litellm
```

### समस्या: पहली request पर उच्च latency

LiteLLM स्टार्टअप पर model configs लोड करता है। कनेक्शन स्थापित होने के कारण शुरुआती कुछ अनुरोध धीमे हो सकते हैं।

### समस्या: डेटाबेस कनेक्शन त्रुटियाँ

```bash
# जाँचें कि PostgreSQL चल रहा है
docker logs postgres

# connection string प्रारूप सत्यापित करें
DATABASE_URL="postgresql://user:password@host:5432/dbname"
```

### समस्या: प्रदाताओं से 429 rate limit त्रुटियाँ

फ़ॉलबैक कॉन्फ़िगर करें:

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

***

## Clore.ai GPU अनुशंसाएँ

LiteLLM एक API gateway/proxy है — यह स्वयं inference नहीं करता। GPU चयन इस बात पर निर्भर करता है कि आप cloud APIs की ओर रूट कर रहे हैं या स्थानीय मॉडलों की ओर।

| सेटअप                   | GPU             | Clore.ai मूल्य                            | उपयोग-प्रकरण                                                      |
| ----------------------- | --------------- | ----------------------------------------- | ----------------------------------------------------------------- |
| केवल cloud API प्रॉक्सी | केवल CPU        | \~$0.02/hr                                | OpenAI, Anthropic, Gemini की ओर रूट करें — GPU की आवश्यकता नहीं   |
| स्थानीय vLLM backend    | RTX 3090 (24GB) | $0.07–0.21/hr                             | LiteLLM को frontend के रूप में उपयोग करके self-hosted 7B–13B मॉडल |
| स्थानीय vLLM backend    | RTX 4090 (24GB) | $0.14–0.42/hr                             | उच्च throughput वाले 7B–34B स्थानीय मॉडल                          |
| स्थानीय vLLM backend    | A100 40GB       | [bare metal](https://clore.ai/bare-metal) | 70B मॉडल, production स्थानीय serving                              |

{% hint style="info" %}
**सबसे सामान्य सेटअप:** अपने Clore.ai-hosted vLLM/Ollama इंस्टेंस के सामने एकीकृत प्रॉक्सी के रूप में LiteLLM चलाएँ। इससे आपको provider fallbacks, rate limiting, cost tracking, और OpenAI-संगत routing मिलता है — जबकि सभी inference स्थानीय और सस्ते रहते हैं।

**उदाहरण लागत:** LiteLLM प्रॉक्सी को CPU-only instance ($0.07–0.21/hr) पर चलाएँ और इसे RTX 3090 ($0.07–0.21/hr) पर मौजूद vLLM सर्वर की ओर पॉइंट करें। Fallbacks, logging, और rate limiting के साथ production-ready, self-hosted LLM API के लिए कुल लागत $0.07–0.21/hr।
{% endhint %}

***

## लिंक्स

* [GitHub](https://github.com/BerriAI/litellm)
* [दस्तावेज़ीकरण](https://docs.litellm.ai)
* [Docker Hub / GHCR](https://github.com/BerriAI/litellm/pkgs/container/litellm)
* [समर्थित प्रदाता](https://docs.litellm.ai/docs/providers)
* [CLORE.AI मार्केटप्लेस](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-hi/language-models/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.
