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

# Create chat

> Crea un chat nuevo y empieza a construir con IA

Crea un chat nuevo e inicia el proceso de la IA.

## Solicitud

```
POST /api/chat
```

### Encabezados

| Encabezado | Obligatorio | Descripción |
| - | - | - |
| `Authorization` | Sí | `Bearer macaly_...` |
| `Content-Type` | Sí | `application/json` |

### Parámetros del cuerpo de la solicitud

| Campo | Tipo | Obligatorio | Predeterminado | Descripción |
| - | - | - | - | - |
| `content` | string | Sí | - | El mensaje o prompt del usuario |
| `stream` | boolean | No | `true` | Si es `false`, devuelve JSON en lugar de un stream |
| `backend` | string | No | `"DEFAULT"` | Backend que se va a usar |
| `executionMode` | `"auto"` \| `"planning"` \| `"build"` | No | - | Determina cómo aborda la IA la tarea |
| `model` | `"gpt-5.6-terra"` \| `"gpt-6.1-sol"` \| `"gpt-6-luna"` \| `"grok-4-6"` \| `"kimi-k3"` \| `"sonnet-5-5"` \| `"opus-5-5"` \| `"blueai-glm-5-3"` \| `"blueai-glm-5-3-flash"` | No | - | Modelo de IA que se va a usar. Si no se especifica, se usa el modelo configurado para el equipo |
| `reasoningEffort` | `"medium"` \| `"high"` | No | - | Determina cuánto razona la IA sobre la tarea |
| `experimental_attachments` | array | No | `[]` | Archivos adjuntos (formato descrito a continuación) |

#### Formato de los archivos adjuntos

Cada elemento del array `experimental_attachments` tiene la siguiente estructura:

| Campo | Tipo | Obligatorio | Descripción |
| - | - | - | - |
| `url` | string | Sí | URL del archivo que se va a adjuntar |
| `name` | string | No | Nombre visible del archivo adjunto |
| `contentType` | string | No | Tipo MIME del archivo |

### Solicitud de ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://www.macaly.com/api/chat \
    -H "Authorization: Bearer macaly_abc123..." \
    -H "Content-Type: application/json" \
    -d '{
      "content": "Create a landing page for a coffee shop",
      "stream": false
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://www.macaly.com/api/chat', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer macaly_abc123...',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      content: 'Create a landing page for a coffee shop',
      stream: false,
    }),
  });

  const data = await response.json();
  console.log(data.chatId);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://www.macaly.com/api/chat',
      headers={
          'Authorization': 'Bearer macaly_abc123...',
          'Content-Type': 'application/json',
      },
      json={
          'content': 'Create a landing page for a coffee shop',
          'stream': False,
      },
  )

  data = response.json()
  print(data['chatId'])
  ```
</CodeGroup>

## Respuesta

### Respuesta JSON (con `stream: false`)

```json theme={null}
{
  "chatId": "abc123def456",
  "url": "https://www.macaly.com/chat/abc123def456",
  "streamId": "stream_xyz789",
  "assistantMessageId": "msg_123"
}
```

| Campo | Tipo | Descripción |
| - | - | - |
| `chatId` | string | El identificador único del chat |
| `url` | string | URL directa para ver el chat |
| `streamId` | string \| undefined | Identificador del stream al que suscribirse. Solo está presente en backends basados en procesos |
| `assistantMessageId` | string \| undefined | ID del mensaje del asistente que se está generando. Solo está presente en backends basados en procesos |

### Respuesta en streaming (con `stream: true`, valor predeterminado)

Cuando el streaming está activado, la respuesta es un stream de texto:

```
2:[{"chatId":"abc123def456"}]
0:"Starting to build..."
...
```

La primera línea contiene el ID del chat con el formato `2:[{"chatId":"..."}]`.

#### Extraer el ID del chat del stream

```javascript theme={null}
const text = await response.text();
const match = text.match(/2:\[{"chatId":"([^"]+)"/);
const chatId = match?.[1];
```

## Códigos de estado

| Código | Descripción |
| - | - |
| 200 | Correcto: chat creado |
| 400 | Cuerpo de la solicitud no válido |
| 401 | Clave API no válida o ausente |
| 402 | Créditos insuficientes |
| 403 | Acceso denegado: sin permiso para el equipo especificado |
| 422 | Error de validación |
| 429 | Límite de solicitudes alcanzado |
| 500 | Error del servidor |

## Siguientes pasos

Después de crear un chat:

1. **Sigue el progreso** con [`GET /api/chat/{chatId}/status`](/docs/es/api/get-status)
2. **Suscríbete al stream** con [`GET /api/chat/{chatId}/subscribe`](/docs/es/api/subscribe-stream) para recibir actualizaciones en tiempo real
3. **Envía mensajes de seguimiento** con [`POST /api/chat/{chatId}/publish`](/docs/es/api/publish-message)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.