Skip to content

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

  1. Create a token limited to what you need. It is printed once, in the token field (more on scopes):

    Terminal window
    wx tokens create my-bot --accounts '*' --scopes read --scopes send
  2. 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/v1
    curl $HOST/health
  3. List accounts and pick the id of yours:

    Terminal window
    curl -H "Authorization: Bearer $TOKEN" $WX/accounts
    export ACCOUNT=...
  4. 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 items and a nextCursor. Pass it back as cursor= 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.

GroupWhat it covers
accountsAccounts, their settings and background operations
authSigning in, connecting and signing out
callsVoice and video calls (guide)
contactsSaved contacts and their avatars
eventsThe replayable event log and stream
groupsSaved groups, their members and group changes
mediaUploads, media assets, downloads and jobs
messagesSaved messages, sending and recall
stickersSaved stickers and official packs (guide)
systemDaemon health, status and shutdown
threadsChats, read state and chat settings
tokensAPI 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:

Terminal window
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=true to receive only events from now on.
  • Resume. After a disconnect or restart, reconnect with ?after=CURSOR or the standard Last-Event-ID header, and the daemon replays what you missed.
  • Acknowledge. POST /consumers/{name}/ack with {"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 with newest=true and 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:

Terminal window
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.json describes every route and schema; generate a client in any language from it.
  • Calls use WebSockets instead: see Calls API.