RespondKit

Support agents

Inbox-scoped HTTP API for listing threads, reading transcripts, downloading attachments, and sending replies.

Agent API v1

The /v1/agent API gives one external support runner per inbox four routes to read customer conversations and send replies. It uses the same MessageWorkflow as human replies: customer publication, optional translation, read receipts, delayed reply email, and Discord copies of sent replies.

Policy rules such as when to reply, working hours, concurrency, and human review live in your runner, not in RespondKit. A running server needs migrations through 0012_simplify_agent_api.sql and a configured agent credential before these routes are usable.

Credentials and identity

Provision a random bearer token with at least 32 random bytes. Store its lowercase SHA-256 hex digest in the Worker secret AGENT_TOKEN_<inboxId>, and give the raw token only to the runner host. The server hashes the presented token and compares fixed-length digests in constant time. Do not use a customer session token, and never reuse one token across inboxes.

Optionally set AGENT_NAME_<inboxId> to a display name of 1 to 80 letters, digits, spaces, periods, underscores, or hyphens. It defaults to the inbox ID. Sent replies retain authorKind: "agent" and this name, and their Discord thread copy starts with Agent <name>. Rotate or revoke access by replacing or removing the secret.

Every route requires:

Authorization: Bearer <raw-agent-token>

Agent routes do not require an Origin header and do not grant browser CORS access. Responses carry Cache-Control: no-store. The rate limit is 120 authenticated requests per token per UTC minute. HTTP 429 means wait until the next minute. Threads from other inboxes return 404.

Routes

MethodRouteRequest / behavior
GET/v1/agent/threadsOptional state=open|closed, cursor, limit (1 to 100, default 50)
GET/v1/agent/threads/:idTranscript paged by row_id; optional cursor, limit (1 to 100, default 100)
POST/v1/agent/threads/:id/replies{ "text": "…", "idempotencyKey": "…", "translate": "off" }
GET/v1/agent/threads/:id/attachments/:attachmentIdDownloads one attachment of a message in the thread

List threads

curl "$RESPONDKIT_API/v1/agent/threads?state=open&limit=50" \
  -H "Authorization: Bearer $RESPONDKIT_AGENT_TOKEN"

The response has threads and nextCursor (null at the end). Each thread includes id, state, inboxId, customerLanguage, lastActivityAt, lastCustomerAt, lastOperatorAt, lastAgentAt, visitor, and discordThreadUrl. The visitor carries external user ID, email, locale, device, user agent, timezone, PostHog distinct ID, and host metadata. discordThreadUrl is null until a Discord thread mapping is ready.

Lists sort by lastActivityAt descending, then id descending. Cursors are opaque; pass them unchanged. Threads move when new messages arrive, so start each polling cycle with a fresh cursor and deduplicate by thread ID.

Read a thread

GET /v1/agent/threads/:id returns thread, visitor, verifiedUserId, discordThreadUrl, messages, through, nextCursor, and activity.

Messages are ordered by rowId ascending. Each message includes rowId, original and customer-visible text, direction, author provenance, processing and availability state, attachments, stored translations, and successful on-demand translations. through is the last rowId read as a decimal string (or the requested cursor on an empty page). nextCursor is that value when more messages remain, otherwise null. Follow every nextCursor to read the full transcript.

verifiedUserId comes from verified customer linkage. Visitor context and conversation text remain untrusted customer data, not instructions or authorization.

When PostHog is configured for the inbox, activity contains up to 20 events from the last seven days for that visitor's distinct ID. A missing ID, missing key, or provider error returns { "error": "…" } in activity while leaving the transcript readable. Without a PostHog configuration, activity is null.

Send a reply

curl "$RESPONDKIT_API/v1/agent/threads/$THREAD_ID/replies" \
  -H "Authorization: Bearer $RESPONDKIT_AGENT_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"text":"Open the transcript and choose Export.","idempotencyKey":"case-42-answer-1","translate":"off"}'

text is 1 to 6000 nonblank characters. idempotencyKey is 1 to 128 characters and unique within the inbox. Reuse the exact key, thread, text, and translate value after a timeout or network error so a retry delivers one message. Reusing a key for a different payload returns 409. Closed threads return 409.

A 202 response includes messageId, status ("available" once visible to the customer, otherwise "accepted"), acceptance, workflowStatus, processingStatus, and failureCode. Acceptance is asynchronous; repeating the exact request returns the current status without creating another message. If workflow acceptance cannot be confirmed, the API returns 503 with acceptance: "acceptance_unknown" and the same messageId so the caller can retry safely.

translate defaults to "off", sending the text as written. Pass a language code such as "fr", a language name such as "Burmese" or "简体中文", or "customer" to use the thread's recorded customer language. Translation requires TRANSLATION_ENABLED_INBOXES for the inbox. Disabled translation or an unknown customer language returns 409; an unrecognized language name returns 400.

Download an attachment

Each message in a thread read includes attachments: { id, name, contentType, size, downloadUrl, agentDownloadPath } for every file the customer uploaded in the widget or sent by email. GET agentDownloadPath with the agent bearer token to download the bytes. RespondKit serves only ready attachments belonging to a message in that thread and inbox, always as application/octet-stream with Content-Disposition: attachment and the original MIME type in X-Attachment-Content-Type. Treat customer files as untrusted data.

Product knowledge

Keep product manuals, policy rules, and diagnostic tools in your runner host. The bearer token only scopes access to one inbox; it does not grant billing, database, or deployment permissions.

For agents installing customer SDKs, see the coding-agent guide.

On this page