> ## 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.

# Créer un chat

> Créez une nouvelle session de chat et commencez à construire avec l'IA

Crée une nouvelle session de chat et lance le workflow IA.

## Requête

```
POST /api/chat
```

### En-têtes

| En-tête | Requis | Description |
| - | - | - |
| `Authorization` | Oui | `Bearer macaly_...` |
| `Content-Type` | Oui | `application/json` |

### Paramètres du corps

| Champ | Type | Requis | Défaut | Description |
| - | - | - | - | - |
| `content` | string | Oui | - | Le message ou prompt de l'utilisateur |
| `stream` | boolean | Non | `true` | Si `false`, retourne du JSON au lieu d'un stream |
| `backend` | string | Non | `"DEFAULT"` | Backend à utiliser |
| `executionMode` | `"auto"` \| `"planning"` \| `"build"` | Non | - | Contrôle l'approche de l'IA pour la tâche |
| `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"` | Non | - | Modèle IA à utiliser. Par défaut, le modèle configuré pour l'équipe |
| `reasoningEffort` | `"medium"` \| `"high"` | Non | - | Contrôle la profondeur de raisonnement de l'IA |
| `experimental_attachments` | array | Non | `[]` | Pièces jointes (voir le format ci-dessous) |

#### Format des pièces jointes

Chaque élément du tableau `experimental_attachments` a la structure suivante :

| Champ | Type | Requis | Description |
| - | - | - | - |
| `url` | string | Oui | URL du fichier à joindre |
| `name` | string | Non | Nom d'affichage de la pièce jointe |
| `contentType` | string | Non | Type MIME du fichier |

### Exemple de requête

<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>

## Réponse

### Réponse JSON (quand `stream: false`)

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

| Champ | Type | Description |
| - | - | - |
| `chatId` | string | L'identifiant unique du chat |
| `url` | string | URL directe pour voir le chat |
| `streamId` | string \| undefined | Identifiant du stream pour s'abonner. Présent uniquement pour les backends avec workflow |
| `assistantMessageId` | string \| undefined | ID du message de l'assistant en cours de génération. Présent uniquement pour les backends avec workflow |

### Réponse streaming (quand `stream: true`, par défaut)

Lorsque le streaming est activé, la réponse est un flux texte :

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

La première ligne contient l'ID du chat au format `2:[{"chatId":"..."}]`.

#### Extraire l'ID du chat depuis le stream

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

## Codes de statut

| Statut | Description |
| - | - |
| 200 | Succès - Chat créé |
| 400 | Corps de requête invalide |
| 401 | Clé API invalide ou manquante |
| 402 | Crédits insuffisants |
| 403 | Forbidden - Pas de permission pour l'équipe spécifiée |
| 422 | Erreur de validation |
| 429 | Limite de requêtes atteinte |
| 500 | Erreur serveur |

## Étapes suivantes

Après avoir créé un chat :

1. **Interrogez le statut** avec [`GET /api/chat/{chatId}/status`](/docs/fr/api/get-status)
2. **Abonnez-vous au stream** avec [`GET /api/chat/{chatId}/subscribe`](/docs/fr/api/subscribe-stream) pour des mises à jour en temps réel
3. **Envoyez des messages de suivi** avec [`POST /api/chat/{chatId}/publish`](/docs/fr/api/publish-message)


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