workbuddy logo

Open API Reference

This chapter summarizes the currently available APIs, grouped by capability into seven categories: Auth, UserProfile, Local Assistant, Cloud Tasks, ACP Channel, Session Artifacts, and Redemption Code Redemption. Developers can first choose the category that matches their business goals, then complete integration based on each API's permission requirements, request parameters, and response structure.

  • Auth API: Complete user authorization and exchange for access credentials.
  • UserProfile API: Read the total credit quota and amount used for the currently authorized user.
  • Local Assistant API: Query PC local assistant status, send messages, and query message history.
  • Cloud Task API: Create and query cloud tasks, and obtain ACP connection information for the task.
  • ACP Channel: Establish a real-time bidirectional communication channel for cloud tasks and exchange protocol messages.
  • Session Artifacts: Query plans, tasks, media, summaries, and other artifacts produced by cloud sessions.
  • Redemption Code Redemption API: Issue credits to the currently authorized user via redemption codes or vouchers.

Auth API

Overview

WorkBuddy Open Platform implements third-party application authorization based on the OAuth 2.1 authorization code flow. Developers guide users through authorization via the /authorize endpoint, then exchange the authorization code at the /token endpoint for access credentials (access_token) and refresh credentials (refresh_token). Subsequent Open API calls are authenticated with access_token.

This section includes two core endpoints:

  • "Request User Authorization" — Guide the user to complete authorization in the browser
  • "Exchange for Access Credentials" — Exchange an authorization code or refresh credential for an access_token

Request User Authorization

Guide the user to open the authorization page in the browser. After the user confirms, the platform callbacks with an Authorization Code.

ItemContent
HTTP URLGET https://www.workbuddy.cn/openapi/v2/authorize
HTTP MethodGET (browser redirect)
Permission RequirementsNo access_token required; client_id must belong to a registered application

Query Parameters

NameTypeRequiredExampleDescription
response_typeStringYescodeFixed value code, indicating authorization code mode
client_idStringYesapp_7a3f2b...Client ID obtained after application registration
redirect_uriStringYeshttps://example.com/callbackCallback URL
scopeStringYesuser.task.readable user.task.invokableRequested permission scopes; multiple scopes separated by spaces. Must be within the Scope set bound to the application
stateStringRecommendeda1b2c3_random_xyzRandom string for CSRF protection and callback state preservation. Returned as-is on callback

Request Example

GET /openapi/v2/authorize?response_type=code&client_id=app_7a3f2b1c&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&scope=user.task.readable%20user.localassistant.readable&state=a1b2c3_random_xyz HTTP/1.1
Host: www.workbuddy.cn
Accept: text/html

Callback Response

After the user confirms authorization, the platform redirects to redirect_uri with the following parameters:

NameTypeExampleDescription
codeStringauth_c0d3_xyz789Authorization code; single-use; valid for 10 minutes
stateStringa1b2c3_random_xyzMatches the state in the request. The application should validate this value to prevent CSRF attacks
GET https://example.com/callback?code=auth_c0d3_xyz789&state=a1b2c3_random_xyz

Exchange for Access Token

Exchange the authorization code for an access_token.

ItemContent
HTTP URLPOST https://www.workbuddy.cn/openapi/v2/token
HTTP MethodPOST
Content-Typeapplication/x-www-form-urlencoded
Permission RequirementsNone (use client_secret for application authentication)

Request Body

NameTypeRequiredExampleDescription
grant_typeStringYesauthorization_codeFixed value authorization_code
codeStringYesauth_c0d3_xyz789Authorization code from the previous step; single-use; valid for 10 minutes
client_idStringYesapp_7a3f2b1cApplication ID
client_secretStringYessk_live_abc123...Application secret; must never be exposed in frontend or client code
redirect_uriStringYeshttps://example.com/callbackMust exactly match (byte-for-byte) the callback URL parameter from the authorization code stage

Request Example

POST /openapi/v2/token HTTP/1.1
Host: www.workbuddy.cn
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=auth_c0d3_xyz789&client_id=app_7a3f2b1c&client_secret=sk_live_abc123...&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback

Response Body

NameTypeExampleDescription
access_tokenStringeyJhbGciOiJSUzI1NiIs...Access token used to call Open API
token_typeStringBearerToken type; fixed value Bearer
expires_inNumber604800access_token validity period in seconds (7 days)
refresh_tokenStringdef50200a1b2c3d4e...Refresh token used to obtain a new token after access_token expires. Returned only in authorization_code mode
scopeStringuser.task.readable user.localassistant.readableActually granted permission scopes
open_idStringop_9f8e7d6c5b4aUser's open_id
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 604800,
  "refresh_token": "def50200a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p...",
  "scope": "user.task.readable user.localassistant.readable",
  "open_id":"op_9f8e7d6c5b4a"
}

Refresh Access Token

Use refresh_token to refresh the access_token.

ItemContent
HTTP URLPOST https://www.workbuddy.cn/openapi/v2/token
HTTP MethodPOST
Content-Typeapplication/x-www-form-urlencoded
Permission RequirementsNone

Request Body

NameTypeRequiredExampleDescription
grant_typeStringYesrefresh_tokenFixed value refresh_token
refresh_tokenStringYesdef50200a1b2...refresh_token from the previous exchange
client_idStringYesapp_7a3f2b1cApplication ID
client_secretStringYessk_live_abc123...Application secret; must never be exposed in frontend or client code

Request Example

POST /openapi/v2/token HTTP/1.1
Host: www.workbuddy.cn
Content-Type: application/x-www-form-urlencoded
Accept: application/json

grant_type=refresh_token&refresh_token=wbjt_xxxxxxxxxxxxx&client_id=cb_xxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxx

Response Body

NameTypeExampleDescription
access_tokenStringeyJhbGciOiJSUzI1NiIs...Access token used to call Open API
token_typeStringBearerToken type; fixed value Bearer
expires_inNumber3600access_token validity period, in seconds
refresh_tokenStringeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9…Refresh token used to obtain a new token after access_token expires. Returned only in authorization_code mode
scopeStringuser.profile.readable task.writeActually granted permission scopes
open_idStringop_9f8e7d6c5b4aUser's open_id
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "scope": "user.profile.readable task.write",
  "open_id": "op_9f8e7d6c5b4a"
}

UserProfile API

Overview

The UserProfile API is used to query the total credit quota and amount used for the currently authorized user. The API supports personal users only. It does not distinguish subscription packs, top-up packs, or gift packs, and only counts resource packs whose status is "valid" or "used up".

Read Personal Credits

ItemContent
HTTP URLGET https://www.workbuddy.cn/openapi/v2/credit
HTTP MethodGET
Permission Requirementsuser.credit.readable

Request

GET /openapi/v2/credit HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "total_capacity_size": 3609,
  "total_capacity_used": 285
}

Response Body

FieldTypeRequiredDescription
total_capacity_sizeIntegerYesCurrent-period total quota of all valid and used-up resource packs
total_capacity_usedIntegerYesCurrent-period amount used of all valid and used-up resource packs

Local Assistant API

Overview

The Local Assistant API is used for message interaction with the PC local assistant connected to WorkBuddy, including querying online status, sending messages, and querying message history.

Query Local Assistant Online Status

Query whether the current user's PC local assistant is online.

ItemContent
HTTP URLGET https://www.workbuddy.cn/openapi/v2/localassistant
HTTP MethodGET
Permission Requirementsuser.localassistant.readable

Request

GET /openapi/v2/localassistant HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 74

{"code":0,"msg":"success","request_id":"a1b2c3d4e5","data":{"online":true}}

Response data

FieldTypeMeaning
onlineboolWhether the current user's PC local assistant is online

Send Message to Local Assistant

Send a message to the PC local assistant to trigger the assistant to execute a task.

ItemContent
HTTP URLPOST https://www.workbuddy.cn/openapi/v2/localassistant/message
HTTP MethodPOST
Permission Requirementsuser.localassistant.invokable
Content-Typeapplication/json

Request

POST /openapi/v2/localassistant/message HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
Accept: application/json
Content-Length: 52

{"content":"帮我查一下今天的日程","msg_type":"text"}

Request body

FieldTypeRequiredMeaning
contentstringYesMessage content, e.g. "帮我查一下今天的日程"
msg_typestringYesMessage type. Currently only text is allowed; permission_response is explicitly rejected (tool approval remains with the local user)

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 87

{"code":0,"msg":"success","request_id":"a1b2c3d4e5","data":{"message_id":"msg-001"}}

Response data

FieldTypeMeaning
message_idstringID of the newly created message, e.g. msg-001

Query Local Assistant Message History

Query the current user's local assistant message history, with support for pagination and incremental queries.

ItemContent
HTTP URLGET https://www.workbuddy.cn/openapi/v2/localassistant/message
HTTP MethodGET
Permission Requirementsuser.localassistant.readable

Request (pagination mode)

GET /openapi/v2/localassistant/message?limit=20&offset=0 HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Request (incremental mode)

GET /openapi/v2/localassistant/message?message_id=msg-001 HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Query Parameters

ParameterTypeMeaning
limitintPagination mode: page size; default 20; max 100
offsetintPagination mode: offset; default 0
message_idstringIncremental mode: return only messages produced after this message (for polling assistant replies)

When message_id is provided, incremental mode is used; otherwise pagination mode is used.

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 396

{"code":0,"msg":"success","request_id":"a1b2c3d4e5","data":{"messages":[{"message_id":"msg-001","role":"user","content":["帮我查一下今天的日程"],"msg_type":"text","created_at":"2026-07-30T10:00:00Z","attachments":[],"metadata":{"msgType":"text"}},{"message_id":"msg-002","role":"assistant","content":["你今天有3个日程..."],"msg_type":"text","created_at":"2026-07-30T10:00:05Z","attachments":[],"metadata":{"msgType":"text"}}]}}

Response data

FieldTypeMeaning
messagesarrayMessage list

messages[] single message element

FieldTypeMeaning
message_idstringMessage ID
rolestringRole: user (user) / assistant (assistant)
contentarrayMessage content; always an array (use [] when empty; do not omit the key)
msg_typestringMessage type, extracted from downstream metadata msgType
created_atstringCreation time (ISO8601, e.g. 2026-07-30T10:00:00Z)
attachmentsarrayAttachment list; always an array (use [] when empty)
metadataobjectMetadata; always an object (use {} when empty)

Cloud Task API

Overview

The Cloud Task API is used to create and query cloud tasks, and returns the ACP connection URL and auth token for establishing real-time communication with the cloud session.

Create Cloud Task

Create a cloud task. Supports interconnection with WorkBuddy mobile or mini-program sessions. Returns task_id, ACP link, and token.

ItemContent
HTTP URLPOST https://www.workbuddy.cn/openapi/v2/tasks
HTTP MethodPOST
Permission Requirementsuser.task.invokable
Content-Typeapplication/json

Request

POST /openapi/v2/tasks HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json

{
  "prompt": "帮我看下明天的天气如何",
  "name": "明天天气"
}

Request Body

ParameterTypeRequiredMeaning
promptstringYesInitial task instruction, used to create the session, generate the title, and set the initial status
namestringNoTask name; if omitted, the server generates one from prompt

Response

HTTP/1.1 201 Created
Content-Type: application/json

{
  "task_id": "2076261663968759808",
  "status": "working",
  "name": "明天天气",
  "link": "https://acp.workbuddy.cn/sessions/2076261663968759808",
  "token": "sk-sandbox-xxxxxxxxxxxxxxxxxxxx",
  "expire_at": 1786087200,
  "sandboxLink": "https://sandbox.example.com/e2b/abc123",
  "sandboxDataLink": "https://sandbox-data.example.com/e2b/abc123"
}

Response Body

FieldTypeAlways ReturnedMeaning
task_idstringYesTask ID; actually corresponds to the agentserver conversation ID
statusstringYesCurrent task/session status
namestringNoTask or session name
linkstringNoACP connection URL for connecting to the task sandbox
tokenstringNoACP gateway authentication credential
expire_atintegerNotoken expiration time; Unix timestamp in seconds
sandboxLinkstringNoSandbox control-plane access URL
sandboxDataLinkstringNoSandbox data-plane access URL

status field enum

StatusMeaning
CREATINGCreating the task and sandbox
idleIdle, waiting to execute
planningPlanning in progress
workingExecuting
pendingPaused or waiting for external input
completedCompleted
failedExecution failed
archivedArchived
deletedDeleted

Query Cloud Task List

Query the list of cloud tasks created by the current user, with pagination support. Returns basic task information and ACP Link; does not return ACP Token or its expiration time.

ItemContent
HTTP URLGET https://www.workbuddy.cn/openapi/v2/tasks
HTTP MethodGET
Permission Requirementsuser.task.readable

Request

GET /openapi/v2/tasks?page=1&size=20 HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Query Parameters

ParameterTypeRequiredDefaultMeaning
pageintegerNo1Page number; treated as 1 if not an integer or less than 1
sizeintegerNo20Page size; treated as 20 if not an integer or less than 1; max 100; treated as 100 if greater than 100

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "tasks": [
    {
      "task_id": "2076261663968759808",
      "status": "working",
      "name": "明天天气",
      "link": "https://acp.workbuddy.cn/sessions/2076261663968759808",
      "created_at": "2026-08-04T10:30:00Z",
      "updated_at": "2026-08-04T10:35:00Z"
    },
    {
      "task_id": "2076261663968759809",
      "status": "completed",
      "name": "日程整理",
      "link": "https://acp.workbuddy.cn/sessions/2076261663968759809",
      "created_at": "2026-08-03T08:00:00Z",
      "updated_at": "2026-08-03T09:00:00Z"
    }
  ],
  "total": 2,
  "pagination": {
    "page": 1,
    "size": 20,
    "total": 2
  }
}

Response Fields

FieldTypeAlways PresentMeaning
tasksarrayYesTask list for the current page
tasks[].task_idstringYesTask ID; corresponds to the cloud session ID
tasks[].statusstringYesCurrent task status
tasks[].namestringNoTask name
tasks[].linkstringNoACP direct connection URL
tasks[].created_atstringNoCreation time in ISO 8601 format
tasks[].updated_atstringNoLast update time in ISO 8601 format
totalintegerYesTotal number of matching tasks
paginationobjectYesPagination information
pagination.pageintegerYesCurrent page number
pagination.sizeintegerYesCurrent page size
pagination.totalintegerYesTotal number of matching tasks

Note: The list API does not return token or expire_at. To obtain a task's ACP Token, call GET /openapi/v2/tasks/{task_id}.

Query Cloud Task

Query task status and obtain a new ACP link/token. Responds with 200 OK. After creating a task, if the response temporarily lacks link or token, poll this API until they are populated.

ItemContent
HTTP URLGET https://www.workbuddy.cn/openapi/v2/tasks/{task_id}
HTTP MethodGET
Permission Requirementsuser.task.readable

Request

GET /openapi/v2/tasks/2076261663968759808 HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Accept: application/json

Path Parameters

ParameterTypeRequiredMeaning
task_idstringYestask_id returned when creating the task

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "task_id": "2076261663968759808",
  "status": "working",
  "name": "明天天气",
  "link": "https://acp.workbuddy.cn/sessions/2076261663968759808",
  "token": "sk-sandbox-xxxxxxxxxxxxxxxxxxxx",
  "expire_at": 1786087200,
  "sandboxLink": "https://sandbox.example.com/e2b/abc123",
  "sandboxDataLink": "https://sandbox-data.example.com/e2b/abc123"
}

Response Body

FieldTypeAlways ReturnedMeaning
task_idstringYesTask ID; actually corresponds to the agentserver conversation ID
statusstringYesCurrent task/session status
namestringNoTask or session name
linkstringNoACP connection URL for connecting to the task sandbox
tokenstringNoACP gateway authentication credential
expire_atintegerNotoken expiration time; Unix timestamp in seconds
sandboxLinkstringNoSandbox control-plane access URL
sandboxDataLinkstringNoSandbox data-plane access URL

status field enum

StatusMeaning
CREATINGCreating the task and sandbox
idleIdle, waiting to execute
planningPlanning in progress
workingExecuting
pendingPaused or waiting for external input
completedCompleted
failedExecution failed
archivedArchived
deletedDeleted

ACP Usage Notes

Start a Conversation

Use the ACP channel to start a conversation. After creating or querying a task to obtain link and token, use them to communicate with the cloud session. ACP (Agent Client Protocol) is based on SSE long connections + JSON-RPC 2.0 and uses a dual-channel model: one GET SSE long connection for receiving server pushes (streaming answers, notifications), and POST requests for sending JSON-RPC calls. Both are associated via the same connection identifier.

Connection and Authentication

  1. Receive channel: GET {link}, with request headers Authorization: Bearer {token} and Accept: text/event-stream, to establish an SSE long connection for receiving server messages. The Acp-Connection-Id in the response headers is the identifier for this connection.
  2. Send channel: POST {link}, with request headers Authorization: Bearer {token}, Content-Type: application/json, and the Acp-Connection-Id echoed to associate with the SSE connection above; Body is a JSON-RPC request. Call results (including streaming answers) are pushed back asynchronously via the SSE channel.
  3. token: Used only for ACP channel authentication. Due to differences in the underlying Agent sandbox environment, token validity varies—typically 3 days, but it may also be much shorter. If the caller receives a 401 on an ACP request, use GET /tasks/{task_id} to obtain a new token.

Conversation Flow (JSON-RPC)

  1. initialize: Negotiate protocol version and client capabilities; call once immediately after connecting.
  2. session/load: Load the created session; pass the task_id returned when creating the task as params.sessionId.
  3. session/prompt: Send a question; params.prompt is a ContentBlock array (each element contains type=text and a text field; see example below). For follow-ups, reuse the same sessionId and call again.

Complete call example (send in order after connecting; results and streaming answers are pushed back via the SSE channel):

// 1) initialize — 协商协议版本与客户端能力,建连后先调用一次
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": 1,
    "clientCapabilities": {
      "fs": { "readTextFile": false, "writeTextFile": false }
    }
  }
}

// 2) session/load — 加载已创建的会话,sessionId 传创建任务返回的 task_id
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "session/load",
  "params": {
    "sessionId": "2076261663968759808",
    "cwd": "/workspace",
    "mcpServers": []
  }
}

// 3) session/prompt — 发送提问,prompt 为 ContentBlock 数组;追问时复用同一 sessionId 再次调用
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "session/prompt",
  "params": {
    "sessionId": "2076261663968759808",
    "prompt": [{ "type": "text", "text": "帮我看下明天的天气如何" }]
  }
}

Receiving Server Messages

The server pushes two types of JSON-RPC messages via the SSE channel:

  • Notification (no id): One-way push for streaming answers, status changes, extension events, etc. The client does not need to reply.
  • Server-to-Client Request (with id): The client must return a response via the SSE-associated Acp-Connection-Id before timeout. Used for interactions that require user participation (tool permission confirmation, AskUserQuestion, etc.).
TypeMethodPurpose
Notificationsession/updateStreaming increments: conversation content, tool calls, task planning, session status
Request (requires reply)session/request_permissionConfirmation requiring user interaction: tool execution authorization, AskUserQuestion
Response (to session/prompt)Final end marker for one prompt round: stopReason + usage

Task completion determination: The session/prompt response is the authoritative signal for "this round ended"; result.stopReason indicates the end reason (end_turn / max_tokens / max_turn_requests / refusal / cancelled).

Extension Method Notes

In addition to standard ACP methods, the server also pushes extension JSON-RPC notifications prefixed with _codebuddy.ai/ via the SSE channel to carry session assets not defined by the ACP standard protocol (such as artifacts, breakpoints, commands, etc.). These messages:

  • Follow the JSON-RPC 2.0 specification (no id; no reply required)
  • Methods unrecognized by the client can be safely ignored without affecting the standard protocol flow
  • Are not defined in the official ACP protocol (agentclientprotocol.com); they are WorkBuddy cloud private extensions to ACP

Extension methods that integrators most need to pay attention to:

MethodPurpose
_codebuddy.ai/artifactArtifact (plan / task list / media / summary) incremental push

Artifact notification example:

{
  "jsonrpc": "2.0",
  "method": "_codebuddy.ai/artifact",
  "params": {
    "sessionId": "2076261663968759808",
    "event": "created",
    "artifact": {
      "type": "media",
      "uri": "agent:///artifacts/output.png",
      "mimeType": "image/png",
      "size": 102400
    }
  }
}

Three event values:

  • created: New artifact added; artifact is the full object.
  • updated: Artifact changed; artifact is the full object (full overwrite, not a diff).
  • deleted: Artifact removed; artifact guarantees only the type and uri fields.

Clients should use artifact.uri as the primary key for local upsert / delete; receiving a duplicate created should be treated as equivalent to updated.

Artifact List API

The SSE channel pushes incremental events. To fetch all historical artifacts in a session at once (e.g. first-screen rendering, state recovery), use the REST API GET /api/session/artifacts. SSE and REST share the same data source and can be combined (REST for full load on first screen + SSE for subsequent increments).

ItemContent
HTTP URLGET {sandbox_url}/api/session/artifacts
Request MethodGET
AuthenticationHeader: Authorization: Bearer {task_ticket}
Content-Typeapplication/json

sandbox_url is obtained by removing the trailing /acp path segment from the link field returned by the "Create Cloud Task" / "Query Cloud Task" APIs. For example, if link = "https://65225-xxx.ap-guangzhou.agentos-run.net/acp", then sandbox_url = "https://65225-xxx.ap-guangzhou.agentos-run.net".

The authentication credential task_ticket is the same one shared with the ACP channel. If task_ticket is expired, HTTP 401 is returned; call the "Query Cloud Task" API to obtain a new task_ticket and retry.

Query Parameters

ParameterTypeRequiredDescription
sessionIdstringNoTarget session ID. Can be omitted for single-session sandboxes (automatically uses the current active session); required in multi-session scenarios.
typestringNoFilter by artifact type; allowed values: plan / tasks / media / overview. If omitted, all types are returned.
startMsint64NoReturn only records with updatedAt >= startMs (epoch milliseconds). Omitted or 0 means no lower bound.
endMsint64NoReturn only records with updatedAt <= endMs (epoch milliseconds). Omitted or 0 means no upper bound.
limitintNoPage size; range [1, 500]. Omitted or 0 means no pagination; return all at once.
offsetintNoPage offset; >= 0; default 0.

Request Example

# 拉取当前会话的全部产物
curl -H "Authorization: Bearer {task_ticket}" \
     "{sandbox_url}/api/session/artifacts"

# 仅拉取媒体类产物,分页
curl -H "Authorization: Bearer {task_ticket}" \
     "{sandbox_url}/api/session/artifacts?type=media&limit=50&offset=0"

# 增量拉取(配合本地记录的 lastUpdatedAt)
curl -H "Authorization: Bearer {task_ticket}" \
     "{sandbox_url}/api/session/artifacts?startMs=1730000000000"

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "code": 0,
  "msg": "success",
  "data": {
    "sessionId": "2076261663968759808",
    "artifacts": [
      {
        "sessionId": "2076261663968759808",
        "event": "created",
        "artifact": { /* Artifact 对象,见下方字段说明 */ },
        "md5": "3f2a...",
        "url": "https://.../artifacts/output.png"
      }
    ],
    "pagination": {
      "total": 123,
      "returned": 50,
      "limit": 50,
      "offset": 0,
      "hasMore": true
    },
    "filter": { "type": "media", "startMs": 0, "endMs": 0 }
  }
}

Response Fields (top level)

FieldTypeDescription
codeintBusiness status code; 0 means success.
msgstringBusiness status description.
data.sessionIdstringSession ID matched by this query.
data.artifactsarrayArtifact record array; elements are Entry.
data.paginationobjectPagination information.
data.filterobjectFilter conditions applied for this request (echo).

Entry Fields (data.artifacts[])

FieldTypeDescription
sessionIdstringOwning session ID.
eventstringMost recent artifact change event; values: created / updated / deleted.
artifactobjectArtifact body (structure: Artifact fields below).
md5stringArtifact content md5 (optional; for deduplication / instant upload).
urlstringDirect access URL for media artifacts (optional; returned only when artifact.type = media).

Artifact Common Fields

FieldTypeDescription
typestringDiscriminator; values: plan / tasks / media / overview.
uristringUnique artifact identifier. Cloud form: agent:///artifacts/plan.md; local form: file:///…. Use as primary key across messages.
namestringResource name (e.g. file name).
titlestringDisplay title.
descriptionstringDescription text.
mimeTypestringMIME type.
createdAtint64Creation time (epoch milliseconds).
updatedAtint64Last update time (epoch milliseconds).

Artifact Type-Specific Fields

type = plan (plan document, Markdown):

FieldTypeDescription
textstringFull current Markdown text.
versionintVersion number (increments on each update).
previousTextstringPrevious full text; can be used to display a diff.
enableEditboolWhether frontend edit write-back is allowed.

type = tasks (task list):

FieldTypeDescription
tasksarrayTask array; elements contain id / content / status (pending / in_progress / completed / cancelled) / order.
enableEditboolWhether frontend edit write-back is allowed.

type = media (media file):

FieldTypeDescription
mimeTypestringFile MIME type, e.g. image/png / video/mp4 / audio/mpeg.
sizeint64File size in bytes.
contentTypestringCoarse category: image / video / audio / document, etc.
widthintImage / video width (pixels).
heightintImage / video height (pixels).

Downloading media files: Prefer the url field at the Entry level; if not provided, replace agent:/// in uri with {sandbox_url}/ and request (reuse the same task_ticket for authentication).

type = overview (task summary, Markdown):

FieldTypeDescription
textstringFull summary Markdown text.

Error Responses

HTTPcodeTypical Scenario and Description
2000Success.
4001Invalid parameters. Typical messages: sessionId is required (multi-session without specification); invalid type (outside whitelist); startMs / endMs / limit / offset out of range or wrong type.
401task_ticket missing, invalid, or expired. Call the "Query Cloud Task" API for a new one and retry.
4041Session does not exist (session ended or sessionId incorrect).

Error response body format:

{
  "code": 1,
  "msg": "invalid type: xxx (allowed: plan|tasks|media|overview)"
}

Usage recommendations

  • First-screen rendering: Call the REST API once when entering a session to fetch all artifacts, and build a local index by artifact.uri.
  • Incremental updates: Subscribe to SSE _codebuddy.ai/artifact notifications and upsert / delete in the local index by event.
  • Session recovery: The REST first-screen + SSE incremental combination is naturally idempotent; no special "recovery branch" is needed—simply overwrite by the same uri.

Redemption Code Redemption API

Overview

Redeem a redemption code or voucher to issue credits to the currently authorized user. The API supports single-code mode and dual-code mode.

Redeem Redemption Code

ItemContent
HTTP URLPOST https://www.workbuddy.cn/openapi/v2/redemptions
HTTP MethodPOST
Permission Requirementsuser.credit.exchange
Content-Typeapplication/json

Request (Scenario A: redemption code)

POST /openapi/v2/redemptions HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
Accept: application/json
Content-Length: 78

{"code":"CODE-OPER-8888","request_id":"550e8400-e29b-41d4-a716-446655440000"}

Request (Scenario B: pickup voucher)

POST /openapi/v2/redemptions HTTP/1.1
Host: www.workbuddy.cn
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
Accept: application/json
Content-Length: 102

{"gift_key":"GK-000001","gift_code":"CODE-XXX","request_id":"550e8400-e29b-41d4-a716-446655440000"}

Request body

FieldTypeRequiredMeaning
codestringRequired in single-code modeOperations platform redemption code, e.g. CODE-OPER-8888; 1-64 characters
gift_keystringRequired in dual-code modeCloud platform card number (card key), e.g. GK-000001; 6-64 characters
gift_codestringRequired in dual-code modeCloud platform card secret; 8-64 characters
request_idstringYesIdempotent / anti-duplicate request ID; length 8-64 (example is a UUID)

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 158

{"status":"success","flow_no":"flow-2026072912345","credits":100,"open_id":"pairwise-open-id-xxx"}

Response Fields

FieldTypeMeaning
statusstringRedemption result status, e.g. success
flow_nostringRedemption flow number, e.g. flow-2026072912345
creditsint64Credits issued by this redemption
open_idstringopen_id of the receiving user (pairwise; isolated per application)

Return codes

Status CodeDescription
200Redemption successful

Return Code Specification

All Open APIs follow a unified return code specification. When an API call fails, use the HTTP status code, business code, and troubleshooting suggestions to locate the issue.

HTTP Status CodeBusiness CodeDescriptionTroubleshooting Suggestions
200successRequest succeededNone
201successRequest succeededNone
400invalid_requestInvalid request parameters (missing params / illegal format / body parse failure / unauthorized parameter combination)Confirm parameters are valid and required fields are present
400unsupported_grant_typeUnsupported grant_typeUse a supported grant_type
400unsupported_response_typeresponse_type is not codeAlways use response_type=code
400invalid_grantAuthorization code / refresh_token invalid or mismatched; redemption code already used / expired / exhaustedRe-run the authorization flow for a new code; treat redemption as terminal—do not retry
400invalid_scopeApplication has no bound scope or requested scope exceeds boundsBind scopes to the application; constrain requested scopes to the bound set
400authorization_pendingDevice authorization polling in progress; user has not acted yetContinue polling normally at the interval
400slow_downDevice authorization polling too frequentIncrease polling interval by 5 seconds and retry
400expired_tokendevice_code expired / already consumedRe-initiate device_auth to obtain a new device_code
401invalid_tokenAuthentication failed (missing Bearer / signature verification failed / missing subject·client)Confirm the auth triad is valid and the token has not expired
401invalid_clientApplication credentials invalid or status is not activeVerify client_id/client_secret and application status
401unauthorized_clientApplication status is not active (device_auth scenario)Confirm the application is enabled
401Unauthorizedpaysign missing login state (uid is empty)Confirm the user is signed in with a valid login state
403access_deniedAccess to the resource is not allowed (unauthorized / application not active / downstream 403)Confirm legitimate permissions exist and the user has authorized the application
403insufficient_scopeToken scope does not meet endpoint requirementsSupplement scopes as indicated by WWW-Authenticate
403forbiddenLocalAssistant identity missing or downstream 401/403Check the token; if still 403 after confirmed authorization, report with request_id
403PermissionDeniedpaysign X-Service-Id is not on the whitelistUse a registered X-Service-Id or contact the platform to whitelist
404not_found / not foundAccessed resource does not exist (application / session / batch / redemption code / message)Confirm the resource identifier is correct and has not been deleted
409invalid_requestResource state conflict (device user_code already processed; anti-duplication)This request has already been processed; do not submit again
412invalid_requestPrecondition not met (scene=client but user has no active authorization)Complete user authorization for the application before obtaining a code
429rate_limitedRequest count exceeded limit; on 429 retry with exponential backoff (1s → 2s → 4s)Request rate too high; reduce call frequency and retry with backoff
500server_error / server error / InternalServerErrorInternal server errorServer error; contact developers with request_id
502server errorLocalAssistant downstream exception (not 401/403/404)Server/downstream issue; retry and report request_id
503server_error / temporarily unavailable / InternalServerErrorService unavailable (dependent client not configured / business temporarily unavailable)Server configuration missing or temporarily unavailable; contact developers