# API : AI Brains, brouillons et le Playground

_API · Lecture de 6 min · Mis à jour 2026-10-22 · https://lanachat.ai/guides/fr/api-ai-brains/_

Un **AI Brain** contient la façon dont l'IA vend pour une créatrice : ses phases de vente, règles et paramètres. Vous modifiez un **brouillon**, le testez dans le **Playground**, puis le **publiez** ; le brain en direct ne change qu'à la publication. Un brain est lié à une créatrice et peut être réutilisé par ses comptes.

## Endpoints

| Méthode | Chemin | Description | Permission | Statut |
|---|---|---|---|---|
| GET | `/brains` | Liste des brains (`creator_id=`) | `can_engine` | Planned |
| POST | `/brains` | Créer un brain pour une créatrice, vide ou copié d’un autre (`copy_from`) | `can_engine` | Planned |
| GET | `/brains/{id}` | La version en direct d’un brain | `can_engine` | Planned |
| PATCH | `/brains/{id}` | Renommer ou relier à une autre créatrice | `can_engine` | Planned |
| DELETE | `/brains/{id}` | Supprimer un brain non utilisé par un compte | `can_engine` | Planned |
| GET | `/brains/{id}/draft` | Le brouillon actuel et ses différences avec la version en direct | `can_engine` | Planned |
| PATCH | `/brains/{id}/draft` | Modifier le brouillon (phases, règles, paramètres) | `can_engine` | Planned |
| DELETE | `/brains/{id}/draft` | Supprimer le brouillon | `can_engine` | Planned |
| POST | `/brains/{id}/publish` | Publier le brouillon ; il devient actif sur tous les comptes liés | `can_publish` | Planned |
| GET | `/brains/{id}/versions` | Versions publiées, la plus récente en premier | `can_engine` | Planned |
| POST | `/brains/{id}/versions/{version}/restore` | Copier une ancienne version dans le brouillon | `can_engine` | Planned |
| POST | `/playground/{brain_id}/message` | Envoyer un message test au brouillon et obtenir la réponse de l’IA | `can_engine` | Planned |
| DELETE | `/playground/{brain_id}/session` | Recommencer la conversation test | `can_engine` | Planned |

## L’objet brain

```json
{
  "id": "br_lea_main",
  "name": "Lea · main",
  "creator_id": "cr_lea",
  "version": 12,
  "published_at": "2026-10-04T21:10:00Z",
  "has_draft": true,
  "accounts": ["acc_1001", "acc_1004"],
  "phases": [
    { "key": "warm_up", "name": "Warm up", "enabled": true },
    { "key": "first_offer", "name": "First offer", "enabled": true }
  ]
}
```

| Champ | Type | Description |
|---|---|---|
| `id` | string | Commence par `br_` |
| `name` | string | Son nom dans la Console |
| `creator_id` | string | La créatrice à laquelle il est lié |
| `version` | number | La version en direct ; augmente de un à chaque publication |
| `published_at` | string ou null | Date de publication de la version en direct, ISO 8601 UTC |
| `has_draft` | boolean | `true` si un brouillon diffère de la version en direct |
| `accounts` | tableau de strings | Comptes Telegram qui répondent avec ce brain |
| `phases` | tableau | Phases de vente : `key`, `name` et si chacune est `enabled` |

## Brains

### Lister les brains

`GET /brains` · `can_engine`

| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
| `creator_id` | string | Non | Seulement les brains de cette créatrice |
| `limit`, `cursor` | number, string | Non | [Pagination](https://lanachat.ai/guides/fr/api-overview/) |

```bash
curl "https://api.lanachat.ai/v1/brains?creator_id=cr_lea" \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

```json
{
  "data": [
    { "id": "br_lea_main", "name": "Lea · main", "creator_id": "cr_lea", "version": 12, "published_at": "2026-10-04T21:10:00Z", "has_draft": true, "accounts": ["acc_1001", "acc_1004"], "phases": [ { "key": "warm_up", "name": "Warm up", "enabled": true }, { "key": "first_offer", "name": "First offer", "enabled": true } ] }
  ],
  "next_cursor": null
}
```

### Créer un brain

`POST /brains` · `can_engine`

| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
| `creator_id` | string | Oui | La créatrice concernée |
| `name` | string | Non | Son nom dans la Console |
| `copy_from` | string | Non | Id d’un brain à copier ; sans cela le brain démarre vide |

```bash
curl -X POST https://api.lanachat.ai/v1/brains \
  -H "Authorization: Bearer $LANACHAT_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"creator_id": "cr_lea", "name": "Lea · TikTok test", "copy_from": "br_lea_main"}'
```

La réponse est le nouveau brain (`201`). Un `copy_from` qui n’existe pas dans cet espace répond `404`.

### Obtenir un brain

`GET /brains/{id}` · `can_engine`

```bash
curl https://api.lanachat.ai/v1/brains/br_lea_main \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

La réponse est la version en direct, comme dans l’objet brain. Le brouillon se lit avec `GET /brains/{id}/draft`.

### Renommer ou relier un brain

`PATCH /brains/{id}` · `can_engine`

| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
| `name` | string | Non | Nouveau nom |
| `creator_id` | string | Non | Le relier à une autre créatrice |

```bash
curl -X PATCH https://api.lanachat.ai/v1/brains/br_lea_main \
  -H "Authorization: Bearer $LANACHAT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "Lea · main FR"}'
```

La réponse est le brain mis à jour.

### Supprimer un brain

`DELETE /brains/{id}` · `can_engine`

```bash
curl -X DELETE https://api.lanachat.ai/v1/brains/br_lea_old \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

Un brain encore utilisé par un compte est refusé (`409`) : reliez d’abord ces comptes à un autre brain.

## Brouillons et publication

### Lire le brouillon

`GET /brains/{id}/draft` · `can_engine`

```bash
curl https://api.lanachat.ai/v1/brains/br_lea_main/draft \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

La réponse est le brouillon actuel (phases, règles et paramètres) et ses différences avec la version en direct.

### Modifier le brouillon

`PATCH /brains/{id}/draft` · `can_engine`

| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
| `phases` | array | Non | Phases de vente à modifier |
| `rules` | array | Non | Règles à modifier |
| `settings` | object | Non | Paramètres à modifier, par exemple `first_offer_after_messages` ou `max_discount_percent` |

```bash
curl -X PATCH https://api.lanachat.ai/v1/brains/br_lea_main/draft \
  -H "Authorization: Bearer $LANACHAT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"settings": {"first_offer_after_messages": 6, "max_discount_percent": 20}}'
```

Seuls les champs envoyés changent. Le brain en direct ne bouge pas tant que vous ne publiez pas.

### Supprimer le brouillon

`DELETE /brains/{id}/draft` · `can_engine`

```bash
curl -X DELETE https://api.lanachat.ai/v1/brains/br_lea_main/draft \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

Le brouillon est supprimé ; la version en direct reste inchangée et `has_draft` devient `false`.

### Publier le brouillon

`POST /brains/{id}/publish` · `can_publish`

```bash
curl -X POST https://api.lanachat.ai/v1/brains/br_lea_main/publish \
  -H "Authorization: Bearer $LANACHAT_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)"
```

```json
{ "id": "br_lea_main", "version": 13, "published_at": "2026-10-06T14:20:03Z", "has_draft": false }
```

Le brouillon devient actif sur tous les comptes liés. Publier sans brouillon répond `409`. Les profils IA avancés nécessitent leurs propres permissions propriétaires, comme dans la Console. Un [webhook](https://lanachat.ai/guides/fr/api-webhooks/) `brain.published` informe votre serveur.

## Versions

### Lister les versions

`GET /brains/{id}/versions` · `can_engine`

```bash
curl https://api.lanachat.ai/v1/brains/br_lea_main/versions \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

La réponse liste les versions publiées, la plus récente en premier, [avec pagination](https://lanachat.ai/guides/fr/api-overview/).

### Restaurer une version

`POST /brains/{id}/versions/{version}/restore` · `can_engine`

```bash
curl -X POST https://api.lanachat.ai/v1/brains/br_lea_main/versions/11/restore \
  -H "Authorization: Bearer $LANACHAT_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)"
```

L’ancienne version est copiée dans le brouillon. Rien ne change pour les fans tant que vous ne publiez pas. Une version inconnue répond `404`.

## Playground

Le Playground parle au **brouillon**, jamais à un fan. Rien n’est envoyé sur Telegram et rien n’est vendu.

### Envoyer un message test

`POST /playground/{brain_id}/message` · `can_engine`

| Paramètre | Type | Obligatoire | Description |
|---|---|---|---|
| `text` | string | Oui | Ce que le fan test écrit |
| `fan` | object | Non | Le fan test : `language` (par exemple `en`) et `is_new` |

```bash
curl -X POST https://api.lanachat.ai/v1/playground/br_lea_main/message \
  -H "Authorization: Bearer $LANACHAT_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"text": "hey, are you real?", "fan": {"language": "en", "is_new": true}}'
```

```json
{
  "reply": { "text": "Haha very real, just slow at typing 🙈 where are you from?", "media": [] },
  "phase": "warm_up",
  "explain": "Phrase bank answer for \"Are you a bot?\", then a question to keep the fan talking."
}
```

- `reply` est ce que l’IA enverrait : texte et média.
- `phase` est la phase de vente dans laquelle l’IA se trouve.
- `explain` explique en clair pourquoi elle a répondu ainsi.

Chaque appel continue la même conversation test.

### Recommencer la conversation test

`DELETE /playground/{brain_id}/session` · `can_engine`

```bash
curl -X DELETE https://api.lanachat.ai/v1/playground/br_lea_main/session \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

Le prochain message test démarre une nouvelle conversation, comme un nouveau fan.

## Articles liés

- [API LanaChat : démarrage rapide, authentification et erreurs](https://lanachat.ai/guides/fr/api-overview/)
- [Qu'est-ce qu'un AI Brain](https://lanachat.ai/guides/fr/what-is-an-ai-brain/)
- [Playground : testez une conversation en toute sécurité](https://lanachat.ai/guides/fr/playground/)
