Frameworks & Plattformen

LiteLLM

LiteLLM mit TokenLab verbinden

Übersicht

LiteLLM kann TokenLab auf zwei Arten nutzen:

  • Verwenden Sie TokenLab als OpenAI-kompatiblen Endpunkt hinter LiteLLM
  • Verwenden Sie das Gateway von LiteLLM, wenn Ihr Team zusätzlich dessen virtuelle Schlüssel, Aliase oder Logs benötigt

Konfigurieren Sie für Chat Completions den custom OpenAI / OpenAI-kompatiblen Client von LiteLLM mit https://api.tokenlab.sh/v1.

Wenn Ihre Anwendung Claude Messages oder Gemini-Felder benötigt, verwenden Sie eine Integration, die dieses API-Format beibehält.

Installation

pip install 'litellm[proxy]'

Proxy-Konfiguration

Erstellen Sie eine litellm-config.yaml wie folgt:

model_list:
  - model_name: tokenlab-gpt-5.4
    litellm_params:
      model: custom_openai/gpt-5.4
      api_base: https://api.tokenlab.sh/v1
      api_key: os.environ/OPENAI_API_KEY

  - model_name: tokenlab-claude-sonnet
    litellm_params:
      model: custom_openai/claude-sonnet-4-6
      api_base: https://api.tokenlab.sh/v1
      api_key: os.environ/OPENAI_API_KEY

Starten Sie den Proxy:

export OPENAI_API_KEY="sk-your-tokenlab-key"
litellm --config litellm-config.yaml --port 4000

Aufruf von LiteLLM über das OpenAI SDK

from openai import OpenAI

client = OpenAI(
    api_key="anything",
    base_url="http://127.0.0.1:4000"
)

response = client.chat.completions.create(
    model="tokenlab-gpt-5.4",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)

Direkte Python-Nutzung

Wenn Sie LiteLLM als Python-Bibliothek anstelle des Proxys verwenden, behalten Sie dieselbe TokenLab-Basis-URL bei:

import litellm

response = litellm.completion(
    model="custom_openai/gpt-5.4",
    api_base="https://api.tokenlab.sh/v1",
    api_key="sk-your-tokenlab-key",
    messages=[{"role": "user", "content": "Summarize this repo."}]
)

Empfehlungen

Fehlerbehebung

Auf dieser Seite