Unified /v1 Contract

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).

http://127.0.0.1:18765
curl -sS "http://127.0.0.1:18765/v1/conversations?limit=20" \
  -H "Authorization: Bearer <YOUR_API_KEY>"

Pass Authorization: Bearer <YOUR_API_KEY> on every /v1/* and /mcp request. Local keys never leave your device unless explicitly bound in Settings -> Devices.

REST Endpoints (/v1)

MethodPathScopeDescription
GET/v1/statusany valid keyCheck scoped service health and permitted active sources
GET/v1/sourcessourcesList permitted chat sources and capability flags
GET/v1/sources/{id}/statussourcesInspect source readability, freshness, coverage, and gaps
GET/v1/conversationsconversationsList permitted conversations with ?kind=, ?source_id=, and ?keyword= filters
GET/v1/conversations/{id}/groupgroupsRead group metadata, owner, admins, announcement, and availability
GET/v1/conversations/{id}/membersgroupsPage through group roster, in-group nicknames, and roles
GET/v1/conversations/{id}/messagesmessagesQuery messages with ?since=, ?until=, ?limit=, and signed ?cursor=
GET/v1/messages/{id}/contextmessagesFetch surrounding context (?before=5&after=5, auto-infers conversation)
POST/v1/searchsearchCross-conversation & multi-source text search (accelerated by optional SQLCipher FTS5)
GET/v1/contactscontactsList contacts in permitted chats; ?scope=all requires full directory grant
GET/v1/attachments/{id}attachmentsInspect attachment metadata, MIME type, byte size, and availability
GET/v1/attachments/{id}/contentattachmentsDownload attachment bytes. Supported formats vary by platform and source. Windows does not transcode to MP3.
GET/v1/changeschangesPoll 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 NameScopeDescription
list_sourcessourcesList permitted chat sources
list_conversationsconversationsList or filter permitted conversations
list_contactscontactsQuery authorized contacts
read_group_infogroupsRead group metadata and announcement
list_group_membersgroupsPage through group members and roles
read_messagesmessagesRead conversation messages with cursor paging
read_contextmessagesRead messages before and after a target message
search_messagessearchFull-text search across permitted conversations
read_attachmentattachmentsRead image or file attachment inline
read_changeschangesPoll 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

SourceOSCapabilities
WeChat 4.x
Live / Snapshot (SQLCipher)
macOS & WindowsMessages, Groups, Contacts, V1/V2/WebP Images, SILK->WAV, Changes
Telegram (MTProto)
Live Session
macOS & WindowsMessages, Contacts, Media Attachments, Real-Time Changes
Apple iMessage
Live Read-Only (chat.db)
macOSMessages, attributedBody, Groups, Contacts, Attachments, ROWID Changes
WhatsApp Export (.txt/.zip)
Imported SQLCipher Archive
macOS & WindowsMessages, Multi-Participant Groups, Embedded Attachments, Changes

Standard Error Envelope

HTTPCodeRetry
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