aichat.md API
Connect aichat.md AI agents to your CRM, Zapier, Make or n8n: leads, conversations, messages and real-time webhooks with one API key.
You are integrating my system with the aichat.md public API (AI agents on Facebook, Instagram, WhatsApp, Telegram, 999.md and websites).
Before writing any code, read the complete documentation for agents: https://aichat.md/llms-api-full.txt
(index: https://aichat.md/llms-api.txt, interactive reference: https://aichat.md/en/docs/api/reference).
Facts:
- Base URL: https://aichat.md/api/public/v1
- Auth: header "Authorization: Bearer <key>". The key (aik_live_…) is created in aichat.md → Settings → Developers and is shown once.
- Read the key ONLY from the environment variable AICHAT_API_KEY. Never print it, log it, commit it or put it in browser/mobile code.
- Start with GET /me to check the key and its scopes. Ask for the smallest scopes the integration needs.
- Lists: cursor pagination (limit ≤ 100, next_cursor). Send an Idempotency-Key header on every POST.
- Respect 429 Retry-After and the RateLimit-* headers. Errors have the shape { error: { type, code, message, param, request_id } }.
- Prefer webhooks (lead.created, conversation.handoff_requested, message.received, credit.low) over polling.
- Every webhook request must be verified: HMAC-SHA256 of `${t}.${raw body}` with the whsec_ secret (env AICHAT_WEBHOOK_SECRET), header Aichat-Signature, 5-minute tolerance, constant-time compare. Answer 2xx within 10 s, process asynchronously, dedupe on the event id.
- Ignore response fields you do not know (the API adds fields without notice).
Your job:
1. Ask me what I want to automate (for example: new leads into my CRM, status back from the CRM, operator alerts) and which stack I use, if it is not clear from the project.
2. Propose a short plan: endpoints, webhook events, scopes, where the code runs.
3. Implement it with tests (mock the API in tests; never call it with a real key in CI), plus a README with the environment variables.
4. Show me how to test it end to end with "Send test" in Settings → Developers → Webhooks.
Reply to me in English.What you can build
- Leads and contacts — read the leads your agents capture (name, phone, e-mail, summary) and sync the status back from your CRM.
- Conversations and messages — see conversations from Facebook, Instagram, WhatsApp, Telegram, 999.md and your website, reply as an operator, take over or hand back to the agent.
- Agents and channels — list agents, pause or resume them, check every channel.
- Knowledge — add a web page or a text to an agent's knowledge.
- Webhooks — receive signed events the moment they happen.
- AI agents (MCP) — connect the account to Claude, ChatGPT or Cursor and run it in plain words. See MCP.
The basics
| Base URL | https://aichat.md/api/public/v1 |
| Authentication | Authorization: Bearer aik_live_… — key from Settings → Developers |
| Format | JSON, ISO 8601 UTC dates, prefixed IDs (lead_…, conv_…) |
| Limits | 120 requests/minute per key, 600/minute per workspace |
| Version | v1 in the URL; breaking changes only ship in a v2 |
A key only sees the data of the workspace that created it. Another account's object always answers 404, as if it did not exist.