API reference

Chat with the agent

Your system talks to its agent with the API key: systems, permissions, long tasks, streaming and errors.

With your API key, your system talks to its agent just like you do in Qaalia Chat: the agent uses its systems(on the internet, on your machine or MCP) with each operation's permission, works with files, searches the web and, if the job is large, continues it as a background task. Your system doesn't declare or run anything: it just sends the message.

Endpoint

POST https://csevfgnqeweymrgebayc.supabase.co/functions/v1/agent-chatAuthorization: Bearer <TU_API_KEY>Content-Type: application/json

Create your API key in API keys. The model isn't sent: Qaalia uses the one you configured on the agent.

curl -X POST "https://csevfgnqeweymrgebayc.supabase.co/functions/v1/agent-chat" \  -H "Authorization: Bearer $QAALIA_API_KEY" \  -H "Content-Type: application/json" \  -d '{ "mensaje": "Hola, ¿qué puedes hacer por mí?" }'

Request body

mensajestring
The user's message, up to 200,000 characters. Required unless you send adjuntos.
conversation_idstring (uuid)
The identifier a previous response returned. It continues that conversation with its memory; if you don't send it, Qaalia creates a new conversation.
user_idstring
Who your user is (up to 200 characters). If you turn on the agent's memory, it remembers each person separately. A conversation stays tied to its user_id.
sistemasarray of uuid
Optional: limits the conversation to those systems or MCP servers of the agent. Without the field, the agent can use all active ones.
adjuntosarray
Files uploaded beforehand with the attachments API: [{ "ruta_storage": "…" }]. See Attachments.
buscar_webboolean
Lets the agent search the internet for this response.
habilidadesarray of string
Optional: the skills the agent must use, by name (for example ["generar-pdf"]). It's the same as writing /generar-pdf in the message.
streamboolean
truereturns the response as it's generated (Server-Sent Events). Without it, you get a single JSON when it finishes.

Response

Without stream, Qaalia responds with one of these three types:

  • respuesta: the agent finished and replies.
{  "exito": true,  "tipo": "respuesta",  "respuesta": "¡Hola! Puedo responder dudas sobre tu negocio y ejecutar acciones en tu sistema.",  "conversation_id": "7d1f3c2a-9b4e-4f6a-8c1d-2e5b6a7f9c30"}

If a skill generated files, the response includes archivos: each with nombre, url (valid for 7 days), mime and bytes.

  • tarea: the job is large and continues in the background (for example, registering hundreds of rows). Check its progress with Long tasks.
{  "exito": true,  "tipo": "tarea",  "task_id": "3b9e0c1d-5a7f-4e2b-9c8d-1f0a2b3c4d5e",  "titulo": "Registrar 480 estudiantes",  "conversation_id": "7d1f3c2a-9b4e-4f6a-8c1d-2e5b6a7f9c30"}
  • pregunta: the agent needs some information before continuing. Reply in the next mensaje with the same conversation_id.
{  "exito": true,  "tipo": "pregunta",  "preguntas": [{    "pregunta": "¿En qué curso los registro?",    "encabezado": "Curso",    "opciones": [{ "etiqueta": "Química" }, { "etiqueta": "Física" }]  }],  "respuesta": "",  "conversation_id": "7d1f3c2a-9b4e-4f6a-8c1d-2e5b6a7f9c30"}

Systems and permissions

The agent works with its systems' operations according to the permission you gave them in Qaalia Chat → Systems: allowed ones run, the ones that ask for approval wait for you (the owner) to approve them in Qaalia Chat, and the agent doesn't even know about blocked ones. Your systems' credentials never travel in the request or reach the model.

Long tasks

When the response is of type tarea, Qaalia keeps running it even if your system disconnects: it advances in stretches, saves its progress and never runs the same action twice. Check its status and its events (use despues with the last id received to fetch only the new ones):

curl -X POST "https://csevfgnqeweymrgebayc.supabase.co/functions/v1/agent-chat" \  -H "Authorization: Bearer $QAALIA_API_KEY" \  -H "Content-Type: application/json" \  -d '{ "consultar_tarea": "3b9e0c1d-5a7f-4e2b-9c8d-1f0a2b3c4d5e", "despues": 0 }'

The response includes status (queued, running, completed, failed, cancelled), progreso, eventos and, when it finishes, respuesta. To stop it send { "cancelar_tarea": "<task_id>" }.

Streaming

With stream: true you receive the same events Qaalia Chat sees, each one as data: {…}:

EventWhat it means
text_deltaA chunk of the text in delta.
pasoWhat the agent is doing (for example, «Registrando 480 estudiantes»).
tool_start · tool_resultA system operation starts and finishes.
ask_userThe agent asks something (preguntas).
task_startedThe work continues in the background (task_id).
chat_endEnd of the turn, with respuesta and conversation_id.
errorSomething failed; it includes error.
Read the stream
const respuesta = await fetch("https://csevfgnqeweymrgebayc.supabase.co/functions/v1/agent-chat", {  method: "POST",  headers: {    Authorization: `Bearer ${process.env.QAALIA_API_KEY}`,    "Content-Type": "application/json",  },  body: JSON.stringify({ mensaje: "Registra los clientes del archivo", stream: true }),})const lector = respuesta.body.getReader()const decodificador = new TextDecoder()let pendiente = ""while (true) {  const { done, value } = await lector.read()  if (done) break  pendiente += decodificador.decode(value, { stream: true })  const bloques = pendiente.split("\n\n")  pendiente = bloques.pop()  for (const bloque of bloques) {    if (!bloque.startsWith("data:")) continue // ": ping" mantiene viva la conexión    const e = JSON.parse(bloque.slice(5))    if (e.event === "text_delta") process.stdout.write(e.delta)    if (e.event === "task_started") console.log("\nTarea en segundo plano:", e.task_id)    if (e.event === "chat_end") console.log("\nconversation_id:", e.conversation_id)  }}

Errors

Errors respond with { "exito": false, "error": "…" } and an HTTP code:

HTTPReason
400The message is missing or an attachment isn't valid.
401The API key is missing or isn't valid. Includes codigo: no_encontrada, desactivada, expirada, agente_inactivo or negocio_inactivo.
404The requested task doesn't exist or doesn't belong to this agent.
502The agent couldn't respond (for example, the AI model isn't connected or didn't respond). The message explains the cause.

Every error is recorded in your logs with its cause.

Use the API key only from your server. Never put it in a browser's or a mobile app's code.

Limits

  • Model: usage is billed by your AI provider (BYOK); Qaalia doesn't limit its tokens. Messages are unlimited.
  • Operations: the ones your plan allows per agent, spread across its systems.
  • Long tasks: one at a time per conversation.