API Docs Blog
Chat Anmelden

API Dokumentation

Vollständige Referenz für die PrivatAI REST API. Einfach, datenschutzfreundlich und leistungsstark.

Einführung

Die PrivatAI API bietet Zugang zu LLM-Modellen (z.B. phi4-mini, Llama3.2), gehostet auf deutschen Servern mit voller DSGVO-Konformität. Alle Anfragen werden über HTTPS übertragen und Ihre Prompts werden nicht gespeichert.

🔒 Datenschutz: Wir speichern keine Prompts oder Antworten. Nur Token-Zähler für die Abrechnung.

Basis-URL

https://privatai.com/api/v1

OpenAI- und Grok-kompatibel: In Ihrem Client nur die Basis-URL auf https://privatai.com/api/v1 setzen.

Authentifizierung

Authentifizieren Sie sich mit Ihrem API-Schlüssel im Authorization-Header:

http
Authorization: Bearer privat_xxxxxxxxxxxxxxxxxxxx

Ihren API-Schlüssel finden Sie im Dashboard nach der Anmeldung und Zahlung.

Chat Completion

POST /api/v1/chat/completions

Generiert eine Antwort auf Ihre Nachricht. OpenAI-kompatibles Format; standardmäßig eine JSON-Antwort, optional Streaming via Server-Sent Events.

Request Body

Parameter Typ Beschreibung
messages array Erforderlich. Array von Nachrichten (role, content)
model string Optional. Modell-ID; sonst Server-Präferenz
stream boolean Optional, Standard false
temperature, max_tokens number Optional

Einfache Anfrage

bash
curl -X POST https://privatai.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "What is machine learning?"}]}'

Mit Tools (funktionaler Aufruf)

bash
curl -X POST https://privatai.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "messages": [
    {"role": "user", "content": "What is the weather in Berlin?"}
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {"type": "string"}
          },
          "required": ["location"]
        }
      }
    }
  ],
  "tool_choice": "auto",
  "stream": false
}'

Konversation (Multi-Turn)

bash
curl -X POST https://privatai.com/api/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "messages": [
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris."},
    {"role": "user", "content": "What is the population?"}
  ]
}'

Response (SSE Stream, OpenAI-Format)

Die Antwort wird als Server-Sent Events im OpenAI-Format gestreamt:

text/event-stream
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":...,"model":"...","choices":[{"index":0,"delta":{"content":"The"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":" capital"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":" of"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":" France"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":" is"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":" Paris"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":15,"completion_tokens":7,"total_tokens":22}}

Thinking-Modelle (Reasoning)

Modelle wie Qwen3.5, gpt-oss und DeepSeek R1 sind Denk-Modelle. Beim Streamen senden sie optional delta.thinking (Gedankengang) vor oder vermischt mit delta.content (Antwort).

Behandlung: Accumulieren Sie delta.thinking für die Begründung (z. B. zum Anzeigen oder Debuggen) und delta.content für die finale Benutzer-Antwort.

json
{"choices":[{"index":0,"delta":{"thinking":"Let me analyze..."}}]}
{"choices":[{"index":0,"delta":{"content":"The answer is Paris."}}]}

Nutzung abfragen

GET /api/v1/usage

Gibt Ihre aktuelle Token-Nutzung zurück.

bash
curl https://privatai.com/api/v1/usage \
  -H "Authorization: Bearer YOUR_API_KEY"

Response

json
{
  "tokens_used": 15420,
  "prompt_tokens": 5200,
  "completion_tokens": 10220,
  "requests": 89,
  "last_used": "2025-12-02T14:30:00"
}

Modelle auflisten

GET /api/v1/models

Gibt die verfügbaren Modelle zurück (OpenAI-kompatibel).

bash
curl https://privatai.com/api/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

Python Beispiel

python
import requests
import json

API_KEY = "YOUR_API_KEY"
URL = "https://privatai.com/api/v1/chat/completions"

def chat(messages):
    response = requests.post(
        URL,
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json"
        },
        json={"messages": messages},
        stream=True
    )
    
    for line in response.iter_lines():
        if line.startswith(b"data: "):
            data = json.loads(line[6:])
            if data.get("choices") and data["choices"][0].get("delta", {}).get("content"):
                print(data["choices"][0]["delta"]["content"], end="", flush=True)
            if data.get("choices") and data["choices"][0].get("finish_reason"):
                print()
                return data.get("usage")

chat([{"role": "user", "content": "Explain quantum computing in simple terms."}])

JavaScript Beispiel

javascript
const API_KEY = 'YOUR_API_KEY';

async function chat(messages) {
  const response = await fetch('https://privatai.com/api/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ messages })
  });

  const reader = response.body.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    const chunk = decoder.decode(value);
    for (const line of chunk.split('\n')) {
      if (line.startsWith('data: ')) {
        const data = JSON.parse(line.slice(6));
        if (data.choices && data.choices[0]?.delta?.content) process.stdout.write(data.choices[0].delta.content);
        if (data.choices && data.choices[0]?.finish_reason) console.log();
      }
    }
  }
}

chat([{ role: 'user', content: 'What is the meaning of life?' }]);

Fehlerbehandlung

Die API gibt Standard-HTTP-Statuscodes zurück:

Code Bedeutung
200 Erfolg
400 Ungültige Anfrage (z.B. fehlendes prompt)
401 Ungültiger oder fehlender API-Schlüssel
429 Rate Limit überschritten
500 Server-Fehler

Rate Limits

Mit einem aktiven Abonnement haben Sie unbegrenzte API-Anfragen. Die Rate wird nur durch die Serverkapazität begrenzt. Der Web-Chat auf der Website ist aus Fairness-Gründen limitiert.

✨ Pro-Abonnenten: Unbegrenzte API-Anfragen.