HTTP API
Everything the wx CLI and the OpenClaw plugin do goes through this API, so your own bot, agent plugin or app can do the same. The daemon serves JSON at http://127.0.0.1:6174/v1. Every request except GET /health needs a bearer token.
Make your first request
-
Create a token limited to what you need. It is printed once, in the
tokenfield (more on scopes):Terminal window wx tokens create my-bot --accounts '*' --scopes read --scopes send -
Check that the daemon is running. This is the only route that needs no token:
Terminal window export HOST=http://127.0.0.1:6174 TOKEN=...export WX=$HOST/v1curl $HOST/health -
List accounts and pick the
idof yours:Terminal window curl -H "Authorization: Bearer $TOKEN" $WX/accountsexport ACCOUNT=... -
List chats, then read one chat’s messages:
Terminal window curl -H "Authorization: Bearer $TOKEN" "$WX/accounts/$ACCOUNT/threads?limit=2"curl -H "Authorization: Bearer $TOKEN" "$WX/accounts/$ACCOUNT/threads/filehelper/messages?limit=1"Lists return
itemsand anextCursor. Pass it back ascursor=with the same query for the next page. An abridged response:{"items": [{"id": "filehelper", "kind": "system", "displayName": "File Transfer","unreadCount": 0, "muted": false, "pinned": false,"lastMessage": { "id": "MESSAGE_ID", "direction": "incoming", "type": 1, "text": "hello" }}],"nextCursor": "OPAQUE_CURSOR"}
How the API is organized
Everything about an account lives under /v1/accounts/{account}/{resource} for a collection and /v1/accounts/{account}/{resource}/{id} for one item. {account} is the daemon’s account ID from GET /v1/accounts, not a WeChat username. Use standard methods: GET to read, POST to create, PATCH or PUT to change, DELETE to remove. Each resource group has a reference page listing its routes, scopes and fields.
| Group | What it covers |
|---|---|
| accounts | Accounts, their settings and background operations |
| auth | Signing in, connecting and signing out |
| calls | Voice and video calls (guide) |
| contacts | Saved contacts and their avatars |
| events | The replayable event log and stream |
| groups | Saved groups, their members and group changes |
| media | Uploads, media assets, downloads and jobs |
| messages | Saved messages, sending and recall |
| stickers | Saved stickers and official packs (guide) |
| system | Daemon health, status and shutdown |
| threads | Chats, read state and chat settings |
| tokens | API tokens, managed with the owner token (guide) |
IDs are opaque strings. Server message IDs can exceed JavaScript’s safe integer range, so never parse them as numbers.
Receive messages
Follow the event stream, and fetch each new message when its event arrives:
curl -N -H "Authorization: Bearer $TOKEN" "$WX/accounts/$ACCOUNT/events/stream?newest=true"A new message arrives as a message.committed event whose data holds messageId and threadId. Fetch it with GET /messages/{messageId}. Every event has a cursor that only increases.
Other events report changes to saved data. For example, group.updated fires when a saved group’s name, notification setting, announcement or members change. Re-read the group when it arrives.
- Start point. Without a cursor the stream starts at the beginning of the log. Add
?newest=trueto receive only events from now on. - Resume. After a disconnect or restart, reconnect with
?after=CURSORor the standardLast-Event-IDheader, and the daemon replays what you missed. - Acknowledge.
POST /consumers/{name}/ackwith{"cursor": "..."}records how far a named consumer has processed. An ack never marks a message read. - Expiry. The daemon keeps about the newest 10,000 events per account. An older cursor returns
410 event_cursor_expired: restart withnewest=trueand reread the chats you care about.
Send reliably
Every send needs an Idempotency-Key header. Repeat the same key after a timeout and you get the original send back, not a second message:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ -H "Idempotency-Key: order-1234-confirmation" \ -d '{"threadId": "filehelper", "text": "Order 1234 confirmed"}' \ "$WX/accounts/$ACCOUNT/sends"The reply is 202 with a send. Poll GET /sends/{id}, or look it up by key with GET /sends/by-idempotency-key?key=.... Media sends are jobs: stage the bytes with POST /uploads, send the source ID, and poll GET /jobs/{id}. Other slow work, such as sign-in, returns an operation to poll at GET /operations/{id}. Closing your request does not cancel it.
A send in state needs_review has an unknown outcome: WeChat may have accepted it. Check the chat; don’t resend with a new key. Sends and recovery explains the states.
Clients
- Rust: the protocol, profile and voice-media crates are described in Rust libraries.
- OpenAPI:
openapi.jsondescribes every route and schema; generate a client in any language from it. - Calls use WebSockets instead: see Calls API.