API Dokumentation
Vollständige Referenz für die PrivatAI REST API. Einfach, datenschutzfreundlich und leistungsstark.
Einführung
Die PrivatAI API bietet Zugang zu Llama3.2, gehostet auf deutschen Servern mit voller DSGVO-Konformität. Alle Anfragen werden über HTTPS übertragen und Ihre Prompts werden nicht gespeichert.
Basis-URL
Authentifizierung
Authentifizieren Sie sich mit Ihrem API-Schlüssel im Authorization-Header:
Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxx
Ihren API-Schlüssel finden Sie im Dashboard nach der Anmeldung und Zahlung.
Chat Completion
Generiert eine Antwort auf Ihre Nachricht. Unterstützt Streaming via Server-Sent Events.
Request Body
| Parameter | Typ | Beschreibung |
|---|---|---|
prompt |
string | Einfache Nachricht (für einzelne Anfragen) |
messages |
array | Array von Nachrichten für Konversationen |
Einfache Anfrage
curl -X POST https://privatai.de/api/v1/chat \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"prompt": "What is machine learning?"}'
Konversation (Multi-Turn)
curl -X POST https://privatai.de/api/v1/chat \ -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)
Die Antwort wird als Server-Sent Events gestreamt:
data: {"token": "The"} data: {"token": " capital"} data: {"token": " of"} data: {"token": " France"} data: {"token": " is"} data: {"token": " Paris"} data: {"token": "."} data: {"done": true, "usage": {"prompt_tokens": 15, "completion_tokens": 7}}
Nutzung abfragen
Gibt Ihre aktuelle Token-Nutzung zurück.
curl https://privatai.de/api/v1/usage \ -H "Authorization: Bearer YOUR_API_KEY"
Response
{
"tokens_used": 15420,
"prompt_tokens": 5200,
"completion_tokens": 10220,
"requests": 89,
"last_used": "2025-12-02T14:30:00"
}
Python Beispiel
import requests API_KEY = "YOUR_API_KEY" URL = "https://privatai.de/api/v1/chat" def chat(prompt): response = requests.post( URL, headers={ "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" }, json={"prompt": prompt}, stream=True ) for line in response.iter_lines(): if line.startswith(b"data: "): data = json.loads(line[6:]) if "token" in data: print(data["token"], end="", flush=True) if data.get("done"): print() return data.get("usage") chat("Explain quantum computing in simple terms.")
JavaScript Beispiel
const API_KEY = 'YOUR_API_KEY'; async function chat(prompt) { const response = await fetch('https://privatai.de/api/v1/chat', { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt }) }); 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.token) process.stdout.write(data.token); if (data.done) console.log(); } } } } chat('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.