Persistente Konversationen
Dieser Leitfaden zeigt, wie Sie mit der Conversations-API mehrstufige Chat-Sitzungen führen, ohne bei jeder Anfrage den gesamten Nachrichtenverlauf erneut zu senden.
Was Sie erstellen werden
Am Ende dieses Leitfadens können Sie:
- Eine persistente Konversation erstellen
- Mehrere Nachrichten senden, ohne den Verlauf erneut zu übertragen
- Die Konversation und ihren vollständigen Nachrichtenverlauf abrufen
- Die Konversation nach Gebrauch löschen
Voraussetzungen
- Ein neuroflash-Konto mit API-Zugang
- Ihre
client_idundclient_secret(siehe Authentifizierung)
Schritt 1: Authentifizieren
- cURL
- Python
- Node.js
- Go
curl -X POST https://id.neuroflash.com/oauth/v2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "scope=openid"
import requests
BASE_URL = "https://app.neuroflash.com/api"
token = requests.post(
"https://id.neuroflash.com/oauth/v2/token",
data={
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"scope": "openid",
},
).json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
const BASE_URL = "https://app.neuroflash.com/api";
const { access_token } = await fetch(
"https://id.neuroflash.com/oauth/v2/token",
{
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
scope: "openid",
}),
}
).then((r) => r.json());
const headers = { Authorization: `Bearer ${access_token}` };
data := url.Values{
"grant_type": {"client_credentials"},
"client_id": {"YOUR_CLIENT_ID"},
"client_secret": {"YOUR_CLIENT_SECRET"},
"scope": {"openid"},
}
resp, _ := http.Post(
"https://id.neuroflash.com/oauth/v2/token",
"application/x-www-form-urlencoded",
strings.NewReader(data.Encode()),
)
defer resp.Body.Close()
var authResult struct{ AccessToken string `json:"access_token"` }
json.NewDecoder(resp.Body).Decode(&authResult)
token := authResult.AccessToken
Schritt 2: Arbeitsbereich abrufen
- cURL
- Python
- Node.js
- Go
curl "https://app.neuroflash.com/api/workspace-service/v1/workspaces" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
workspaces = requests.get(
f"{BASE_URL}/workspace-service/v1/workspaces",
headers=headers,
).json()
workspace_id = workspaces["_embedded"]["workspaces"][0]["id"]
const workspaces = await fetch(
`${BASE_URL}/workspace-service/v1/workspaces`,
{ headers }
).then((r) => r.json());
const workspaceId = workspaces._embedded.workspaces[0].id;
req, _ := http.NewRequest("GET", baseURL+"/workspace-service/v1/workspaces", nil)
req.Header.Set("Authorization", "Bearer "+token)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
// parse JSON and extract _embedded.workspaces[0].id into workspaceID
Schritt 3: Konversation erstellen
Hinweis: workspace_id gehört bei POST in den JSON-Body, nicht in einen Header.
- cURL
- Python
- Node.js
- Go
curl -X POST "https://app.neuroflash.com/api/ds-prototypes/conversations" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "workspace_id": "YOUR_WORKSPACE_ID" }'
conv = requests.post(
f"{BASE_URL}/ds-prototypes/conversations",
headers={**headers, "Content-Type": "application/json"},
json={"workspace_id": workspace_id},
).json()
conversation_id = conv["uuid"]
const conv = await fetch(`${BASE_URL}/ds-prototypes/conversations`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ workspace_id: workspaceId }),
}).then((r) => r.json());
const conversationId = conv.uuid;
body, _ := json.Marshal(map[string]string{"workspace_id": workspaceID})
req, _ := http.NewRequest("POST", baseURL+"/ds-prototypes/conversations", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
Antwort:
{
"uuid": "ebb3fbeb-69ed-41e9-bcb5-1ec8a643566e",
"workspace_id": "b481b98b-a7ed-4d72-a1f2-8b2ae3a57854",
"created_at": "2026-04-08T15:44:47.383172"
}
Schritt 4: Nachricht senden
Der Conversation-Service speichert Ihren Nachrichtenverlauf — Sie müssen frühere Nachrichten nicht erneut senden. Jede Anfrage muss nur die neue Benutzernachricht enthalten.
- cURL
- Python
- Node.js
- Go
curl -X POST "https://app.neuroflash.com/api/ds-prototypes/conversations/{uuid}/chat/completions" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "messages": [{ "role": "user", "content": "What makes neuroflash unique?" }] }'
reply = requests.post(
f"{BASE_URL}/ds-prototypes/conversations/{conversation_id}/chat/completions",
headers={**headers, "Content-Type": "application/json"},
json={"messages": [{"role": "user", "content": "What makes neuroflash unique?"}]},
).json()
const reply = await fetch(
`${BASE_URL}/ds-prototypes/conversations/${conversationId}/chat/completions`,
{
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ messages: [{ role: "user", content: "What makes neuroflash unique?" }] }),
}
).then((r) => r.json());
body, _ := json.Marshal(map[string]any{
"messages": []map[string]string{
{"role": "user", "content": "What makes neuroflash unique?"},
},
})
req, _ := http.NewRequest("POST", baseURL+"/ds-prototypes/conversations/"+conversationID+"/chat/completions", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
Antwort:
{
"id": "gen-1775000000-AbCdEfGh",
"object": "chat.completion",
"model": "openai/gpt-4.1-mini",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Neuroflash is unique because it combines brand-aware AI content generation with European data privacy standards and multi-language support."
},
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 12, "completion_tokens": 28, "total_tokens": 40, "words_used": 22 }
}
Schritt 5: Folgefrage senden
Senden Sie eine weitere Nachricht an dieselbe Konversation — ohne den Verlauf erneut zu übertragen. Der Kontext aus Schritt 4 bleibt serverseitig erhalten.
- cURL
- Python
- Node.js
- Go
curl -X POST "https://app.neuroflash.com/api/ds-prototypes/conversations/{uuid}/chat/completions" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "messages": [{ "role": "user", "content": "Can you give me an example?" }] }'
followup = requests.post(
f"{BASE_URL}/ds-prototypes/conversations/{conversation_id}/chat/completions",
headers={**headers, "Content-Type": "application/json"},
json={"messages": [{"role": "user", "content": "Can you give me an example?"}]},
).json()
const followup = await fetch(
`${BASE_URL}/ds-prototypes/conversations/${conversationId}/chat/completions`,
{
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ messages: [{ role: "user", content: "Can you give me an example?" }] }),
}
).then((r) => r.json());
body, _ := json.Marshal(map[string]any{
"messages": []map[string]string{
{"role": "user", "content": "Can you give me an example?"},
},
})
// Same endpoint and headers as Step 4.
Schritt 6: Konversation abrufen
Der Conversations-Service erzwingt workspace-gebundene Eigentümerschaft. Der Query-Parameter
workspace_id ist bei allen GET- und DELETE-Anfragen erforderlich. Fehlt er oder wird der
falsche Workspace verwendet, gibt die API 403 Forbidden zurück.
- cURL
- Python
- Node.js
- Go
curl "https://app.neuroflash.com/api/ds-prototypes/conversations/{uuid}?workspace_id=YOUR_WORKSPACE_ID" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
conv = requests.get(
f"{BASE_URL}/ds-prototypes/conversations/{conversation_id}",
headers=headers,
params={"workspace_id": workspace_id},
).json()
const conv = await fetch(
`${BASE_URL}/ds-prototypes/conversations/${conversationId}?workspace_id=${workspaceId}`,
{ headers }
).then((r) => r.json());
u := fmt.Sprintf("%s/ds-prototypes/conversations/%s?workspace_id=%s", baseURL, conversationID, workspaceID)
req, _ := http.NewRequest("GET", u, nil)
req.Header.Set("Authorization", "Bearer "+token)
Schritt 7: Nachrichtenverlauf abrufen
- cURL
- Python
- Node.js
- Go
curl "https://app.neuroflash.com/api/ds-prototypes/conversations/{uuid}/messages?workspace_id=YOUR_WORKSPACE_ID" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
history = requests.get(
f"{BASE_URL}/ds-prototypes/conversations/{conversation_id}/messages",
headers=headers,
params={"workspace_id": workspace_id},
).json()
const history = await fetch(
`${BASE_URL}/ds-prototypes/conversations/${conversationId}/messages?workspace_id=${workspaceId}`,
{ headers }
).then((r) => r.json());
u := fmt.Sprintf("%s/ds-prototypes/conversations/%s/messages?workspace_id=%s", baseURL, conversationID, workspaceID)
req, _ := http.NewRequest("GET", u, nil)
req.Header.Set("Authorization", "Bearer "+token)
Antwort:
{
"messages": [
{ "role": "user", "content": "What makes neuroflash unique?" },
{ "role": "assistant", "content": "Neuroflash is unique due to..." }
],
"next_cursor": null
}
Schritt 8: Konversation löschen
- cURL
- Python
- Node.js
- Go
curl -X DELETE "https://app.neuroflash.com/api/ds-prototypes/conversations/{uuid}?workspace_id=YOUR_WORKSPACE_ID" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
requests.delete(
f"{BASE_URL}/ds-prototypes/conversations/{conversation_id}",
headers=headers,
params={"workspace_id": workspace_id},
)
await fetch(
`${BASE_URL}/ds-prototypes/conversations/${conversationId}?workspace_id=${workspaceId}`,
{ method: "DELETE", headers }
);
u := fmt.Sprintf("%s/ds-prototypes/conversations/%s?workspace_id=%s", baseURL, conversationID, workspaceID)
req, _ := http.NewRequest("DELETE", u, nil)
req.Header.Set("Authorization", "Bearer "+token)