DocumentationThe assistant endpoint
Your assistants
The assistant endpoint
A single request in the OpenAI format. Your assistant answers with its instructions and memory, streamed.
Call the assistant
POST /v1/agents/chat/completions A complete conversation turn.
Identify the assistant with assistantId. To continue the same conversation, send threadId instead.
curl -N https://api.learnya.ai/v1/agents/chat/completions \
-H "Authorization: Bearer $LEARNYA_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"assistantId": "ASSISTANT_ID",
"stream": true,
"messages": [
{"role": "user", "content": "Where is my invoice?"}
]
}'with requests.post(
f"{API}/agents/chat/completions",
headers=HEADERS,
json={
"assistantId": assistant["id"],
"stream": True,
"messages": [
{"role": "user", "content": "Where is my invoice?"}
],
},
stream=True,
) as response:
for line in response.iter_lines(decode_unicode=True):
if line.startswith("data: ") and line != "data: [DONE]":
chunk = json.loads(line[6:])
delta = chunk["choices"][0]["delta"].get("content")
print(delta or "", end="", flush=True)const response = await fetch(`${API}/agents/chat/completions`, {
method: "POST",
headers,
body: JSON.stringify({
assistantId: assistant.id,
stream: true,
messages: [
{ role: "user", content: "Where is my invoice?" },
],
}),
})
const decoder = new TextDecoder()
for await (const part of response.body) {
for (const line of decoder.decode(part).split("\n")) {
if (!line.startsWith("data: ")) continue
if (line === "data: [DONE]") continue
const chunk = JSON.parse(line.slice(6))
process.stdout.write(chunk.choices[0]?.delta?.content ?? "")
}
}interface Chunk {
choices: { delta: { content?: string } }[]
}
const response = await fetch(`${API}/agents/chat/completions`, {
method: "POST",
headers,
body: JSON.stringify({
assistantId: assistant.id,
stream: true,
messages: [
{ role: "user", content: "Where is my invoice?" },
],
}),
})
const text = response.body!.pipeThrough(new TextDecoderStream())
for await (const part of text) {
for (const line of part.split("\n")) {
if (!line.startsWith("data: ")) continue
if (line === "data: [DONE]") continue
const chunk = JSON.parse(line.slice(6)) as Chunk
process.stdout.write(chunk.choices[0]?.delta?.content ?? "")
}
}The response
| Mode | What you get |
|---|---|
| Streaming | OpenAI-format chat.completion.chunk events, then [DONE] |
| Without streaming | An immediate response with no text, with finish_reason set to queued and the thread, message and run IDs to track |
How it differs from a model on its own
| Subject | With an assistant |
|---|---|
| The model field | It picks the model for this response, not the assistant |
| tool messages and images | Rejected: the assistant calls its own tools |
| Token count | An estimate, and completion_tokens is 0 |
| Access | A user’s access token, not an API key |
For a model without an assistant, stick to the plain chat endpoint with an API key.