Conventions
Pagination, idempotency, rate limits, IDs and versioning.
Pagination
Lists answer { "object": "list", "data": [...], "has_more": true, "next_cursor": "…" }. Send next_cursor as cursor for the next page; limit is 1–100 (default 20). A cursor is bound to the filters it was created with.
let cursor = null;
do {
const url = new URL("https://aichat.md/api/public/v1/contacts");
url.searchParams.set("limit", "100");
if (cursor) url.searchParams.set("cursor", cursor);
const page = await (await fetch(url, { headers })).json();
for (const contact of page.data) save(contact);
cursor = page.next_cursor;
} while (cursor);GET /conversations is the exception: it returns the most recent conversations across all channels. To sync, send updated_after with the newest updated_at you have.
Idempotency
Every POST accepts an Idempotency-Key header (up to 255 characters, e.g. a UUID or order-4821). Repeat the request with the same key within 24 hours and you get exactly the same response, with Idempotent-Replayed: true, and the action does not run again. The same key with a different body returns 409 idempotency_key_reused.
curl https://aichat.md/api/public/v1/conversations/conv_MTEy/messages \
-H "Authorization: Bearer $AICHAT_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-4821-confirmation" \
-d '{"text": "Your order #4821 is confirmed. We deliver tomorrow 10-14."}'Rate limits
| Limit | Value |
|---|---|
| Per key | 120 requests per minute |
| Per workspace (all keys) | 600 requests per minute |
| Sending messages | 30 per minute per key |
Every response carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset (seconds). Over the limit you get 429 with Retry-After: wait that many seconds and retry.
IDs and dates
IDs are opaque prefixed strings (agt_, conv_, msg_, lead_, ct_, ch_, ks_, we_, evt_). Store them as text; do not parse them. Dates are ISO 8601 UTC. Every response has Aichat-Request-Id: include it when you contact support.
Versioning
The major version is in the URL (/v1). We add fields, endpoints and events without notice: your code must ignore fields it does not know. A breaking change only ships in /v2; v1 keeps working for at least 12 months after, with Deprecation and Sunset headers and a changelog announcement.