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

# Chat aanmaken

> Maak een nieuwe chatsessie aan en begin te bouwen met AI

Maakt een nieuwe chatsessie aan en start de AI-workflow.

## Verzoek

```
POST /api/chat
```

### Headers

| Header          | Vereist | Beschrijving        |
| --------------- | ------- | ------------------- |
| `Authorization` | Ja      | `Bearer macaly_...` |
| `Content-Type`  | Ja      | `application/json`  |

### Bodyparameters

| Veld                       | Type                                                             | Vereist | Standaard   | Beschrijving                                                               |
| -------------------------- | ---------------------------------------------------------------- | ------- | ----------- | -------------------------------------------------------------------------- |
| `content`                  | string                                                           | Ja      | -           | Het bericht of de prompt van de gebruiker                                  |
| `stream`                   | boolean                                                          | Nee     | `true`      | Als `false`, retourneert JSON in plaats van een stream                     |
| `backend`                  | string                                                           | Nee     | `"DEFAULT"` | Te gebruiken backend                                                       |
| `executionMode`            | `"auto"` \| `"planning"` \| `"build"`                            | Nee     | -           | Bepaalt hoe de AI de taak benadert                                         |
| `model`                    | `"sonnet-4-5"` \| `"sonnet-4-6"` \| `"opus-4-5"` \| `"opus-4-6"` | Nee     | -           | AI-model om te gebruiken. Standaard het geconfigureerde model van het team |
| `reasoningEffort`          | `"medium"` \| `"high"`                                           | Nee     | -           | Bepaalt hoe diep de AI nadenkt over de taak                                |
| `experimental_attachments` | array                                                            | Nee     | `[]`        | Bestandsbijlagen (zie formaat hieronder)                                   |

#### Bijlageformaat

Elk item in de `experimental_attachments`-array heeft de volgende structuur:

| Veld          | Type   | Vereist | Beschrijving                         |
| ------------- | ------ | ------- | ------------------------------------ |
| `url`         | string | Ja      | URL van het bestand om bij te voegen |
| `name`        | string | Nee     | Weergavenaam voor de bijlage         |
| `contentType` | string | Nee     | MIME-type van het bestand            |

### Voorbeeldverzoek

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

## Respons

### JSON-respons (bij `stream: false`)

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

| Veld                 | Type                | Beschrijving                                                                              |
| -------------------- | ------------------- | ----------------------------------------------------------------------------------------- |
| `chatId`             | string              | De unieke chat-ID                                                                         |
| `url`                | string              | Directe URL om de chat te bekijken                                                        |
| `streamId`           | string \| undefined | Stream-ID om u te abonneren. Alleen aanwezig voor workflow-backends                       |
| `assistantMessageId` | string \| undefined | ID van het assistentbericht dat wordt gegenereerd. Alleen aanwezig voor workflow-backends |

### Streamingrespons (bij `stream: true`, standaard)

Wanneer streaming is ingeschakeld, is de respons een tekststroom:

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

De eerste regel bevat de chat-ID in het formaat `2:[{"chatId":"..."}]`.

#### De chat-ID uit de stream halen

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

## Statuscodes

| Status | Beschrijving                                         |
| ------ | ---------------------------------------------------- |
| 200    | Succes - Chat aangemaakt                             |
| 400    | Ongeldig verzoek                                     |
| 401    | Ongeldige of ontbrekende API-sleutel                 |
| 402    | Onvoldoende credits                                  |
| 403    | Forbidden - Geen toestemming voor het opgegeven team |
| 422    | Validatiefout                                        |
| 429    | Limiet bereikt                                       |
| 500    | Serverfout                                           |

## Volgende stappen

Na het aanmaken van een chat:

1. **Controleer de status** met [`GET /api/chat/{chatId}/status`](/docs/nl/api/get-status)
2. **Abonneer u op de stream** met [`GET /api/chat/{chatId}/subscribe`](/docs/nl/api/subscribe-stream) voor realtime updates
3. **Stuur vervolgberichten** met [`POST /api/chat/{chatId}/publish`](/docs/nl/api/publish-message)
