Published on

KI-Server-API-Design: OpenAI-kompatible APIs im Unternehmen

Authors

Warum OpenAI-kompatible APIs?

Die OpenAI-API ist zum De-facto-Standard für LLM-Integration geworden. Jedes Framework (LangChain, LlamaIndex, Dify) unterstützt sie nativ — daher ist es sinnvoll, die eigene Infrastruktur mit einer kompatiblen API zu versehen.

OpenAI-kompatible Server

|| Server | GPU-Support | Multi-GPU | Batch | API-Status | ||---|---|---|---|---| || vLLM | NVIDIA, AMD | Ja | Excellent | OpenAI-kompatibel | || Ollama | NVIDIA, AMD | Ja | Gut | Eigenes Format | || LiteLLM | Alle | Ja | Gut | OpenAI-kompatibel | || Text Generation Inference | NVIDIA | Ja | Excellent | OpenAI-kompatibel |

vLLM: Der Enterprise-Standard

# Client-Code (funktioniert mit vLLM und OpenAI gleich)
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",  # vLLM
    # base_url="https://api.openai.com/v1",  # OpenAI
    api_key="sk-fake-key"  # vLLM ignoriert Key
)

response = client.chat.completions.create(
    model="llama3.3:70b",
    messages=[{"role": "user", "content": "Hallo Welt"}],
    temperature=0
)
print(response.choices[0].message.content)

API-Authentifizierung

# nginx.conf: API-Authentifizierung
upstream llm_api {
    server localhost:8000;
}

server {
    listen 443 ssl;
    server_name ki.firma.de;

    location /v1/ {
        # API-Key prüfen
        if ($http_author !~ "^Bearer sk-[a-z0-9]+$") {
            return 401;
        }
        
        proxy_pass http://llm_api;
        proxy_set_header Host $host;
    }
}

LiteLLM: Proxy für Multi-Provider

LiteLLM ermöglicht eine einzige API-Endpunkt für mehrere LLMs:

# proxy-config.yaml
model_list:
  - model_name: "production"
    litellm_params:
      model: "ollama/llama3.3:70b"
      api_base: "http://localhost:11434"
      
  - model_name: "fallback"
    litellm_params:
      model: "ollama/qwen2.5:32b"
      api_base: "http://localhost:11434"

Fazit

OpenAI-kompatible APIs sind der Standard für LLM-Integration. vLLM ist die performanteste Lösung, LiteLLM der flexibelste Proxy.

👉 KI-Server Guide 👉 Pexon Consulting: API-Integration

📖 Verwandte Artikel

Weitere interessante Beiträge zu ähnlichen Themen

Bereit für KI im Mittelstand?

Nutzen Sie unsere 10 kostenlosen KI-Tools und Praxis-Guides – oder sprechen Sie direkt mit unseren Experten.

Pexon Consulting – KI-Beratung für den Mittelstand | Scaly Academy – Geförderte KI-Weiterbildung (KI-Spezialist, KI-Experte, Workflow-Automatisierung)