API, MCP & Webhook Developer Reference
Identical routes, JSON schemas, and permission boundaries across local loopback (127.0.0.1:18765) and optional Cloud Relay (chattoapi.com/devices/:id).
REST Endpoints (/v1)
| Method | Path | Scope | Description |
|---|---|---|---|
| GET | /v1/status | any valid key | Check scoped service health and permitted active sources |
| GET | /v1/sources | sources | List permitted chat sources and capability flags |
| GET | /v1/sources/{id}/status | sources | Inspect source readability, freshness, coverage, and gaps |
| GET | /v1/conversations | conversations | List permitted conversations with ?kind=, ?source_id=, and ?keyword= filters |
| GET | /v1/conversations/{id}/group | groups | Read group metadata, owner, admins, announcement, and availability |
| GET | /v1/conversations/{id}/members | groups | Page through group roster, in-group nicknames, and roles |
| GET | /v1/conversations/{id}/messages | messages | Query messages with ?since=, ?until=, ?limit=, and signed ?cursor= |
| GET | /v1/messages/{id}/context | messages | Fetch surrounding context (?before=5&after=5, auto-infers conversation) |
| POST | /v1/search | search | Cross-conversation & multi-source text search (accelerated by optional SQLCipher FTS5) |
| GET | /v1/contacts | contacts | List contacts in permitted chats; ?scope=all requires full directory grant |
| GET | /v1/attachments/{id} | attachments | Inspect attachment metadata, MIME type, byte size, and availability |
| GET | /v1/attachments/{id}/content | attachments | Download attachment bytes. Supported formats vary by platform and source. Windows does not transcode to MP3. |
| GET | /v1/changes | changes | Poll incremental message.created events from ?cursor= |
Model Context Protocol (POST /mcp)
Streamable HTTP JSON-RPC 2.0 (protocolVersion 2025-11-25). Tools are dynamically filtered by active grant permissions.
| Tool Name | Scope | Description |
|---|---|---|
| list_sources | sources | List permitted chat sources |
| list_conversations | conversations | List or filter permitted conversations |
| list_contacts | contacts | Query authorized contacts |
| read_group_info | groups | Read group metadata and announcement |
| list_group_members | groups | Page through group members and roles |
| read_messages | messages | Read conversation messages with cursor paging |
| read_context | messages | Read messages before and after a target message |
| search_messages | search | Full-text search across permitted conversations |
| read_attachment | attachments | Read image or file attachment inline |
| read_changes | changes | Poll incremental change events |
Webhook Signature Verification (HMAC-SHA256)
When a signing secret is configured, verify X-ChatToApi-Signature = sha256=HMAC_SHA256(secret, timestamp + '.' + rawBody) and deduplicate by X-ChatToApi-Event-ID.
import crypto from 'node:crypto';
export function verifyChatToApiWebhook(rawBody: string, headers: Record<string, string>, secret: string) {
const ts = headers['x-chattoapi-timestamp'];
const sig = headers['x-chattoapi-signature']; // "sha256=<hex>"
if (!ts || !sig) return false;
const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex');
return crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
}Platform Adapter Capability Matrix
| Source | OS | Capabilities |
|---|---|---|
WeChat 4.x Live / Snapshot (SQLCipher) | macOS & Windows | Messages, Groups, Contacts, V1/V2/WebP Images, SILK->WAV, Changes |
Telegram (MTProto) Live Session | macOS & Windows | Messages, Contacts, Media Attachments, Real-Time Changes |
Apple iMessage Live Read-Only (chat.db) | macOS | Messages, attributedBody, Groups, Contacts, Attachments, ROWID Changes |
WhatsApp Export (.txt/.zip) Imported SQLCipher Archive | macOS & Windows | Messages, Multi-Participant Groups, Embedded Attachments, Changes |
Standard Error Envelope
| HTTP | Code | Retry |
|---|---|---|
| 400 | INVALID_REQUEST 参数格式、时间范围或 JSON 结构无效 / Invalid query or JSON body | false |
| 401 | UNAUTHENTICATED 缺少或未知的 Bearer API Key / Missing or invalid API key | false |
| 403 | FORBIDDEN / GRANT_REVOKED 超出会话/附件/群权限或凭据已撤销/过期 / Out of scope or expired | false |
| 404 | NOT_FOUND 目标资源不存在或不在当前授权范围内 / Resource absent or out of scope | false |
| 409 | CURSOR_EXPIRED 底层分页结果集或群名单已变化,需重新从首页查询 / Restart pagination | false |
| 422 | FORMAT_UNSUPPORTED 当前来源或媒体格式不支持该操作 / Unsupported capability or media format | false |
| 429 | RATE_LIMITED / DEVICE_BUSY 触发每分钟限流或设备并发队列已满 / Retry with backoff | true |
| 503 | DEVICE_OFFLINE / SOURCE_UNAVAILABLE 桌面客户端离线或本地数据源已锁定 / Wait for device or source | true |
| 504 | DEVICE_TIMEOUT 桌面端 30 秒预算内未完成响应 / Bounded retry | true |