# API Schnellrezepte: kopieren, einfügen, ausführen

_API · 7 Min. Lesezeit · Aktualisiert 2026-10-22 · https://lanachat.ai/guides/de/api-recipes/_

Acht vollständige Rezepte für die Aufgaben, die Agenturen zuerst automatisieren. Jedes ist bereit zum Kopieren, in cURL und in JavaScript (Node 20 oder höher, keine Bibliothek). Setzen Sie Ihr Token einmal, wie im [Quick Start](https://lanachat.ai/guides/de/api-overview/), und jeder Block läuft so wie er ist.

```bash
export LANACHAT_TOKEN="lc_live_8f2c1d0e9b7a4c6f"
```

Die JavaScript-Rezepte verwenden diesen kleinen Helfer. Fügen Sie ihn einmal oben in Ihre Datei ein:

```js
const API = 'https://api.lanachat.ai/v1';

async function lanachat(method, path, body) {
  const res = await fetch(API + path, {
    method,
    headers: {
      Authorization: `Bearer ${process.env.LANACHAT_TOKEN}`,
      'Content-Type': 'application/json',
      ...(method === 'POST' ? { 'Idempotency-Key': crypto.randomUUID() } : {}),
    },
    body: body ? JSON.stringify(body) : undefined,
  });
  const data = await res.json();
  if (!res.ok) throw new Error(`${res.status} ${data.error.code}: ${data.error.message}`);
  return data;
}
```

## 1. Eine Creatorin hinzufügen und ihr Telegram-Konto verbinden

Benötigt `can_setup` und ein **owner**-Token für die Lizenz (Schritt 4). Erstellen Sie die Creatorin, füllen Sie ihre Identität aus, fügen Sie ihr Konto mit dem Bot-Token hinzu und vergeben Sie dann eine Lizenz für das Konto, damit es antworten kann.

```bash
# 1. the creator
curl -X POST https://api.lanachat.ai/v1/creators \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"name": "Lea", "timezone": "Europe/Paris"}'

# 2. her identity (she must be 18 or older)
curl -X PUT https://api.lanachat.ai/v1/creators/cr_lea/identity \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Content-Type: application/json" \
  -d '{"first_name": "Lea", "date_of_birth": "2001-04-12", "nationality": "FR", "languages": ["fr", "en"]}'

# 3. her Telegram account
curl -X POST https://api.lanachat.ai/v1/accounts \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"creator_id": "cr_lea", "bot_token": "<bot token>", "market": "fr", "traffic": "instagram"}'

# 4. a licence from your stock
curl -X POST https://api.lanachat.ai/v1/billing/licences/assign \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"account_id": "acc_1001"}'
```

```js
const creator = await lanachat('POST', '/creators', { name: 'Lea', timezone: 'Europe/Paris' });
await lanachat('PUT', `/creators/${creator.id}/identity`, {
  first_name: 'Lea', date_of_birth: '2001-04-12', nationality: 'FR', languages: ['fr', 'en'],
});
const account = await lanachat('POST', '/accounts', {
  creator_id: creator.id, bot_token: process.env.BOT_TOKEN, market: 'fr', traffic: 'instagram',
});
await lanachat('POST', '/billing/licences/assign', { account_id: account.id });
console.log(account.id, account.health);   // "pending" until she confirms in Telegram
```

Das Konto bleibt `pending`, bis die Creatorin die Geschäftsverbindung in ihren Telegram-Einstellungen bestätigt. Ein [Webhook](https://lanachat.ai/guides/de/api-webhooks/) informiert Sie, wenn es auf `connected` wechselt: das Ereignis `account.health_changed`. Siehe [Telegram accounts](https://lanachat.ai/guides/de/api-telegram-accounts/) und [Billing](https://lanachat.ai/guides/de/api-billing/).

## 2. Heutige Verkäufe auslesen

Benötigt `can_sales_read`. `/stats` liefert die Tagesgesamtwerte, pro Link und Quelle; Stars zählen mit $0,013 pro Stück im Nettoumsatz.

```bash
TODAY=$(date -u +%F)
curl "https://api.lanachat.ai/v1/stats?from=$TODAY&to=$TODAY" \
  -H "Authorization: Bearer $LANACHAT_TOKEN"
```

```js
const today = new Date().toISOString().slice(0, 10);
const stats = await lanachat('GET', `/stats?from=${today}&to=${today}`);
const stars = stats.days.reduce((sum, d) => sum + d.revenue_stars, 0);
console.log(`${stars} Stars today, about $${(stars * 0.013).toFixed(2)}`);
for (const l of stats.links) console.log(l.link_id, l.buyers, 'buyers', l.revenue_stars, 'Stars');
```

Fügen Sie `creator_id=cr_lea` für eine einzelne Creatorin hinzu. Tage sind UTC-Tage. Um jeden Verkauf sofort zu erhalten, verwenden Sie Rezept 6.

## 3. Eine Nachricht an einen Fan senden

Benötigt `can_chat`. Finden Sie die Konversation, dann senden Sie. Eine über die API gesendete Nachricht zählt als von einer Person gesendet und übernimmt die Konversation, bis Sie sie zurückgeben (Rezept 4).

```bash
# conversations of Lea with unread messages
curl "https://api.lanachat.ai/v1/conversations?creator_id=cr_lea&unread=true" \
  -H "Authorization: Bearer $LANACHAT_TOKEN"

# send a text and a paid photo
curl -X POST https://api.lanachat.ai/v1/conversations/conv_1001_88231/messages \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"text": "Only for you, tonight", "media": [{"id": "med_5522", "stars": 250}]}'
```

```js
const { data: convs } = await lanachat('GET', '/conversations?creator_id=cr_lea&unread=true');
const conv = convs[0];
const msg = await lanachat('POST', `/conversations/${conv.id}/messages`, {
  text: 'Only for you, tonight',
  media: [{ id: 'med_5522', stars: 250 }],
});
console.log(msg.status);   // "queued", then "sent" and "read"
```

Fügen Sie `"send_at"` (ISO 8601, bis zu 7 Tage im Voraus) hinzu, um zu planen. Siehe [Conversations](https://lanachat.ai/guides/de/api-conversations/).

## 4. Eine Konversation übernehmen, dann an die KI zurückgeben

Benötigt `can_chat`. Solange eine Person die Konversation hält, antwortet die KI diesem Fan nicht.

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

# ... your team replies ...

curl -X POST https://api.lanachat.ai/v1/conversations/conv_1001_88231/release \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)"
```

```js
const id = 'conv_1001_88231';
await lanachat('POST', `/conversations/${id}/takeover`);   // state: "human"
// ... your team replies ...
await lanachat('POST', `/conversations/${id}/release`);    // back to the AI
```

Eine Konversation, die aus Sicherheitsgründen gestoppt wurde, kann nicht an die KI zurückgegeben werden: die API antwortet mit `409`.

## 5. Einen Tracking-Link erstellen

Benötigt `can_tracking`. Ein Link pro Anzeige oder Bio, damit Sie wissen, welcher verkauft.

```bash
curl -X POST https://api.lanachat.ai/v1/links \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"name": "Insta bio · Lea", "slug": "lea-bio", "creator_id": "cr_lea", "source": "instagram", "destination": "pool"}'
```

```js
const link = await lanachat('POST', '/links', {
  name: 'Insta bio · Lea', slug: 'lea-bio', creator_id: 'cr_lea', source: 'instagram', destination: 'pool',
});
console.log(link.public_url);   // put this URL in her bio
```

Fügen Sie `"domain"` hinzu, um eine Ihrer verifizierten Domains zu verwenden. Lesen Sie Klicks, Konversationen und Käufer mit `GET /links/{id}` oder `/stats`. Siehe [Tracking](https://lanachat.ai/guides/de/api-tracking/).

## 6. Jeden Verkauf auf Ihrem Server erhalten, sobald er passiert

Benötigt ein **owner**-Token, um den Endpunkt hinzuzufügen. LanaChat sendet für jeden verifizierten Verkauf und jede Rückerstattung ein signiertes `POST`.

```bash
curl -X POST https://api.lanachat.ai/v1/webhooks \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"url": "https://hooks.mia-agency.com/lanachat/webhook", "events": ["sale.completed", "sale.refunded"]}'
```

```js
import express from 'express';
import { createHmac, timingSafeEqual } from 'node:crypto';

// once: add the endpoint (keep the secret of the answer as LANACHAT_WEBHOOK_SECRET)
// await lanachat('POST', '/webhooks', { url: 'https://hooks.mia-agency.com/lanachat/webhook', events: ['sale.completed', 'sale.refunded'] });

// the receiver: check the signature, answer 200 fast, then work

function verify(raw, header, secret) {
  const parts = (header || '').split(',').map((p) => p.trim().split('='));
  const t = parts.find(([k]) => k === 't')?.[1];
  if (!t || !(Math.abs(Date.now() / 1000 - Number(t)) < 300)) return false;
  const want = createHmac('sha256', secret).update(t + '.').update(raw).digest('hex');
  return parts.some(([k, v]) => k === 'v1' && v.length === want.length && timingSafeEqual(Buffer.from(v), Buffer.from(want)));
}

const app = express();
app.post('/lanachat/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  if (!verify(req.body, req.get('LanaChat-Signature'), process.env.LANACHAT_WEBHOOK_SECRET)) return res.sendStatus(400);
  res.sendStatus(200);
  const event = JSON.parse(req.body);
  if (event.type === 'sale.completed') console.log('Sale:', event.data.stars, 'Stars,', event.data.creator_id, event.data.sent_by);
  if (event.type === 'sale.refunded') console.log('Refund of', event.data.sale_id);
});
app.listen(3000);
```

Das Signatur-Geheimnis erhalten Sie einmalig in der Antwort des ersten Aufrufs: speichern Sie es als `LANACHAT_WEBHOOK_SECRET`. Drücken Sie **Test** (`POST /webhooks/{id}/test`), um einen `ping` zu erhalten. Python, Wiederholungen und alle Events finden Sie in [Webhooks](https://lanachat.ai/guides/de/api-webhooks/).

## 7. Ein Foto in den Vault hochladen und bepreisen

Benötigt `can_setup`. Fordern Sie eine Upload-URL an, senden Sie die Datei dorthin, bestätigen Sie, dann setzen Sie den Preis.

```bash
# 1. upload URL
curl -X POST https://api.lanachat.ai/v1/media/uploads \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"creator_id": "cr_lea", "file_name": "beach-01.jpg", "content_type": "image/jpeg", "size_bytes": 2483201}'

# 2. the file, to the "url" of the answer (no Authorization header there)
curl -X PUT "<url from step 1>" -H "Content-Type: image/jpeg" --data-binary @beach-01.jpg

# 3. confirm, 4. price it
curl -X POST https://api.lanachat.ai/v1/media/uploads/up_7781/complete \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Idempotency-Key: $(uuidgen)"
curl -X PATCH https://api.lanachat.ai/v1/media/med_5521 \
  -H "Authorization: Bearer $LANACHAT_TOKEN" -H "Content-Type: application/json" \
  -d '{"access": "paid", "stars": 300, "description": "Beach, golden hour, white bikini"}'
```

```js
import { readFile, stat } from 'node:fs/promises';

const file = 'beach-01.jpg';
const up = await lanachat('POST', '/media/uploads', {
  creator_id: 'cr_lea', file_name: file, content_type: 'image/jpeg', size_bytes: (await stat(file)).size,
});
const put = await fetch(up.url, { method: up.method, headers: up.headers, body: await readFile(file) });
if (!put.ok) throw new Error('Upload failed: ' + put.status);
const media = await lanachat('POST', `/media/uploads/${up.upload_id}/complete`);
await lanachat('PATCH', `/media/${media.id}`, { access: 'paid', stars: 300, description: 'Beach, golden hour, white bikini' });
```

Das Medium ist `processing`, dann `ready`: der `media.ready`-Webhook informiert Sie, wann. Siehe [Vault](https://lanachat.ai/guides/de/api-vault/).

## 8. Ein Brain ändern, testen, veröffentlichen

Benötigt `can_engine` und `can_publish` für den letzten Schritt. Das Live-Brain ändert sich nur bei Veröffentlichung.

```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}}'

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

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

```js
await lanachat('PATCH', '/brains/br_lea_main/draft', { settings: { first_offer_after_messages: 6 } });
const test = await lanachat('POST', '/playground/br_lea_main/message', {
  text: 'hey, are you real?', fan: { language: 'en', is_new: true },
});
console.log(test.reply.text, '|', test.explain);
// happy with the answer? publish
const live = await lanachat('POST', '/brains/br_lea_main/publish');
console.log('Live version', live.version);
```

Der Playground schreibt nie an einen Fan und verkauft nie. Siehe [AI Brains](https://lanachat.ai/guides/de/api-ai-brains/).

## Verwandte Artikel

- [LanaChat API: Schnellstart, Authentifizierung und Fehler](https://lanachat.ai/guides/de/api-overview/)
- [API: Webhooks, Events und Signaturen](https://lanachat.ai/guides/de/api-webhooks/)
- [API & MCP: Einen KI-Assistenten verbinden](https://lanachat.ai/guides/de/api-mcp/)
