> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thaliq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /api/agent/chat

> Envia un mensaje y recibe la respuesta completa (sin streaming)

Endpoint para enviar un mensaje al agente y recibir la respuesta completa en un solo payload. Usa este endpoint cuando no necesites streaming.

<Note>
  Para respuestas en tiempo real, usa el endpoint de [streaming](/api-reference/stream).
</Note>

## Request

```bash theme={null}
POST https://api.thaliq.com/api/agent/chat
```

### Headers

Ver [Autenticacion](/api-reference/authentication) para el detalle completo. Headers comunes:

| Header               | Requerido | Descripcion                                                                  |
| -------------------- | :-------: | ---------------------------------------------------------------------------- |
| `X-API-Key`          |     Si    | API Key del tenant. Resuelve tambien el agente si la key esta asociada a uno |
| `Content-Type`       |     Si    | `application/json`                                                           |
| `X-Integration-Type` |     No    | `widget` o `sdk` (filtra tools por `requiresAuth`)                           |
| `X-User-Id`          |     No    | ID del usuario final (tracking)                                              |
| `X-Participant-Id`   |     No    | Fingerprint del visitante (anon)                                             |
| `X-MCP-Tokens`       |     No    | JSON con tokens MCP por server                                               |
| `Authorization`      |     No    | `Bearer <jwt>` (passthrough MCP)                                             |

### Body

```json theme={null}
{
  "message": "¿Cuales son los horarios de atencion?",
  "conversationId": "conv_abc123",
  "agentId": "agent_uuid",
  "channel": "widget"
}
```

| Campo            | Tipo     | Requerido | Descripcion                                                                                                                       |
| ---------------- | -------- | :-------: | --------------------------------------------------------------------------------------------------------------------------------- |
| `message`        | `string` |     Si    | El mensaje del usuario                                                                                                            |
| `conversationId` | `string` |     No    | ID de conversacion existente para mantener contexto. Si se omite o expiro el session timeout, el backend crea una nueva           |
| `agentId`        | `string` |     No    | Override del agente. Si se omite, se usa el agente bindeado a la API key (o el default del tenant si no hay binding)              |
| `agentType`      | `string` |     No    | `'general'` por defecto                                                                                                           |
| `channel`        | `string` |     No    | `'platform' \| 'widget' \| 'sdk' \| 'studio' \| 'whatsapp' \| 'telegram' \| 'slack'`. Afecta filtrado en stats e inbox            |
| `actionResponse` | `object` |     No    | Respuesta a una accion HITL pendiente (consent/confirm/select/form). Solo aplicable cuando se esta resumiendo un turno suspendido |

## Response

```json theme={null}
{
  "success": true,
  "data": {
    "message": "Nuestro horario de atencion es de lunes a viernes de 9am a 6pm.",
    "conversationId": "conv_abc123"
  }
}
```

| Campo                 | Tipo      | Descripcion                                           |
| --------------------- | --------- | ----------------------------------------------------- |
| `success`             | `boolean` | Si la peticion fue exitosa                            |
| `data.message`        | `string`  | La respuesta del agente                               |
| `data.conversationId` | `string`  | ID de la conversacion (usar para mensajes siguientes) |

## Ejemplo con curl

```bash theme={null}
curl -X POST https://api.thaliq.com/api/agent/chat \
  -H "Content-Type: application/json" \
  -H "X-API-Key: tq_live_xxx" \
  -d '{
    "message": "¿Cuales son los horarios de atencion?"
  }'
```

## Ejemplo con JavaScript

```javascript theme={null}
const response = await fetch('https://api.thaliq.com/api/agent/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'tq_live_xxx',
  },
  body: JSON.stringify({
    message: '¿Cuales son los horarios de atencion?',
  }),
});

const data = await response.json();
console.log(data.data.message);
// → "Nuestro horario de atencion es de lunes a viernes de 9am a 6pm."
```

## Continuando una conversacion

Usa el `conversationId` de la primera respuesta para mantener el contexto:

```javascript theme={null}
// Primer mensaje
const res1 = await fetch('https://api.thaliq.com/api/agent/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'tq_live_xxx',
  },
  body: JSON.stringify({ message: 'Hola, necesito ayuda' }),
});
const data1 = await res1.json();
const conversationId = data1.data.conversationId;

// Segundo mensaje (con contexto)
const res2 = await fetch('https://api.thaliq.com/api/agent/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'tq_live_xxx',
  },
  body: JSON.stringify({
    message: '¿Cuanto cuesta el plan Growth?',
    conversationId,
  }),
});
```
