AnythingLLM API – Konfiguration & Anbindung
AnythingLLM bietet eine vollwertige REST-API, um Workspaces, Dokumente und Chats programmatisch zu steuern. Damit lassen sich RAG-Funktionen direkt in eigene Apps – KI-CRM, n8n-Flows, Browser-Extensions – einbetten.
1. Basis-Setup
2. API-Token erstellen
3. Wichtige Endpunkte
/api/v1/auth
Token verifizieren
GET /api/v1/workspaces
Liste aller Workspaces
POST /api/v1/workspace/new
Workspace anlegen
POST /api/v1/workspace/<slug>/upload
Dokument(e) hochladen
POST /api/v1/workspace/<slug>/update-embeddings
Dokumente in Workspace aktivieren
POST /api/v1/workspace/<slug>/chat
Chat-Anfrage mit RAG
POST /api/v1/workspace/<slug>/stream-chat
Streaming-Chat
POST /api/v1/workspace/<slug>/thread/new
Konversations-Thread anlegen
GET /api/v1/documents
Globale Dokumente-Liste
DELETE /api/v1/workspace/<slug>
Workspace löschen
4. Beispiel-Requests
4.1 Token verifizieren
curl https://rag.kistudent.local/api/v1/auth \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN"
Antwort: {"authenticated": true}.
4.2 Workspace listen
curl https://rag.kistudent.local/api/v1/workspaces \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN"
4.3 Chat-Request (RAG)
curl -X POST https://rag.kistudent.local/api/v1/workspace/produkte-jianghai/chat \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "Welche Alternativen gibt es zu Panasonic EEU-FR1V222B?",
"mode": "query"
}'
Antwort enthält textResponse, sources (mit Dokumenttitel + Chunk-Auszug) und chatId.
4.4 Mode "chat" vs. "query"
Für strikte RAG (z.B. Vertrags-Fragen): query. Für offene Sales-Konversationen: chat.
4.5 Dokument hochladen
curl -X POST https://rag.kistudent.local/api/v1/workspace/studium/upload \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN" \
-F "file=@datenblatt.pdf"
Anschliessend Embedding aktivieren:
curl -X POST https://rag.kistudent.local/api/v1/workspace/studium/update-embeddings \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"adds": ["custom-documents/datenblatt.pdf-uuid.json"],
"deletes": []
}'
4.6 Streaming-Chat (Server-Sent-Events)
curl -N -X POST https://rag.kistudent.local/api/v1/workspace/studium/stream-chat \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "Erkläre die Self-Hosting-Architektur.",
"mode": "query"
}'
Antworten kommen Token für Token; ideal für reaktive Chat-UIs (z.B. KI-CRM-Frontend).
5. Workspace-Slugs verstehen
Ein Workspace hat einen Namen ("Local AI Manager Studium") und einen Slug ("local-ai-manager-studium"). API-Calls nutzen immer den Slug. Slug bei der Erstellung lesen:
curl -X POST https://rag.kistudent.local/api/v1/workspace/new \
-H "Authorization: Bearer $ANYTHINGLLM_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Test-Workspace"}'
# Response enthält "workspace": {"slug": "test-workspace", ...}
6. Embeddings-Provider
Die API selbst hängt nicht direkt am Embedding-Modell – die Konfiguration kommt aus der Container-.env bzw. den UI-Settings (siehe AnythingLLM-Setup-Seite). Standard in diesem Setup: nomic-embed-text über Ollama.
7. Häufige Fehler
/workspaces-Endpunkt korrekte Slugs holen
500 mit "no embedding"
Embedding-Modell nicht erreichbar
Ollama-Verbindung & Modell prüfen
Chat antwortet leer
Mode "query" + keine relevanten Docs
Mode auf "chat" oder Workspace mit Dokumenten füllen
8. Beispiel-Integration in KI-CRM
Workflow im KI-CRM-Backend, wenn ein User auf "Vergleichbares Produkt finden" klickt:
9. Backup-Implikation
API-Tokens leben in der AnythingLLM-DB unter ./storage. Nach Restore eines Backups bleiben die Tokens gültig. Wichtig: Tokens niemals im Git committen – nur in Vaultwarden oder n8n-Credentials.
10. Checkliste
/api/v1/auth antwortet mit authenticated: true
☐ Workspace-Slugs dokumentiert (Tabelle in BookStack)
☐ Chat-Test mit Mode "query" liefert Sources
☐ Streaming-Test mit stream-chat funktioniert
☐ Upload-Test mit kleinem PDF + Embedding-Aktivierung erfolgreich
Querverweise: AnythingLLM Installation (Block 2) | n8n ↔ LocalAI/AnythingLLM | Nextcloud ↔ AnythingLLM