51cowork APIDocs
Open docs navigation

API Reference

Model Gateway API Reference

The current public gateway https://api.51cowork.com supports GPT, Claude, Grok, DeepSeek, GLM, and Kimi through Anthropic- and OpenAI-compatible endpoints. API Keys come from Dashboard.

Quick answer

Send model requests directly to https://api.51cowork.com. Prefer Authorization: Bearer; Anthropic clients may use x-api-key. Discover exact model IDs with GET /v1/models.

Gateway
https://api.51cowork.com
Auth
Bearer / x-api-key
Content type
application/json
Models
GET /v1/models
01

Base URL and authentication

Send model requests to /v1/... paths on the Gateway at https://api.51cowork.com. Manage your account in Dashboard.

Environmentbash
export COWORK_GATEWAY_URL="https://api.51cowork.com"
export COWORK_API_KEY="<key-from-dashboard>"
export COWORK_MODEL="<model-from-gateway>"
ClientBase URLPath appended by the client
Direct HTTPhttps://api.51cowork.comUse the full /v1/... path
OpenAI SDK / OpenCode / Cursorhttps://api.51cowork.com/v1/chat/completions or /responses
Cherry Studio (OpenAI)https://api.51cowork.com/v1/chat/completions
WorkBuddy (Custom Protocol)https://api.51cowork.com/v1/chat/completionsFull URL; no appended path
Anthropic SDK / Claude Codehttps://api.51cowork.com/v1/messages
Codexhttps://api.51cowork.comwire_api = responses
MethodHeader
RecommendedAuthorization: Bearer <API_KEY>
Anthropic compatiblex-api-key: <API_KEY>
Gemini compatible, when enabledx-goog-api-key: <API_KEY>
02

GET /v1/models

Read the models currently exposed to the Key's assigned group.

cURLbash
curl "$COWORK_GATEWAY_URL/v1/models" \
  -H "Authorization: Bearer $COWORK_API_KEY"
  • Supported model families include GPT, Claude, Grok, DeepSeek, GLM, and Kimi.
  • Use an exact returned model ID; do not send a family name or infer an ID from a product name.
  • If the list is empty or a model is missing, check the Key, group, and operator configuration.
  • Cache briefly and provide a manual refresh path.
03

POST /v1/messages

Anthropic Messages-compatible endpoint.

Anthropic Messagesbash
curl "$COWORK_GATEWAY_URL/v1/messages" \
  -H "x-api-key: $COWORK_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "'"$COWORK_MODEL"'",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Before generating, send the same model and messages to POST /v1/messages/count_tokens to estimate input tokens.

Count tokensbash
curl "$COWORK_GATEWAY_URL/v1/messages/count_tokens" \
  -H "x-api-key: $COWORK_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "'"$COWORK_MODEL"'",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
FieldRequirement
modelAn ID returned by /v1/models
max_tokensPositive integer, bounded by client and model support
messagesAt least one valid message
streamOptional; true returns an event stream
04

POST /v1/chat/completions

OpenAI Chat Completions-compatible endpoint.

Chat Completionsbash
curl "$COWORK_GATEWAY_URL/v1/chat/completions" \
  -H "Authorization: Bearer $COWORK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$COWORK_MODEL"'",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Common fields include model, messages, stream, and model-supported sampling or tool fields. Unsupported upstream fields may be rejected or handled by compatibility rules, so do not assume identical behavior across models.

05

POST /v1/responses

OpenAI Responses-compatible endpoint and the wire API used by Codex.

Responsesbash
curl "$COWORK_GATEWAY_URL/v1/responses" \
  -H "Authorization: Bearer $COWORK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$COWORK_MODEL"'",
    "input": "Explain this repository in three bullets."
  }'
06

Streaming

Set stream to true and process server-sent events incrementally. cURL uses -N to disable output buffering.

Streaming requestbash
curl -N "$COWORK_GATEWAY_URL/v1/chat/completions" \
  -H "Authorization: Bearer $COWORK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$COWORK_MODEL"'",
    "stream": true,
    "messages": [{"role": "user", "content": "Count to five"}]
  }'
  • Use a read timeout long enough for first-token and long-response latency.
  • Close the response body when the client cancels.
  • An error after streaming starts may not be rewritten as a normal JSON error; retain received events for diagnosis.
07

HTTP status and error handling

StatusTypical meaningAction
400Invalid JSON, field, or model parameterFix the request; do not retry unchanged
401Missing, invalid, or disabled KeyReload configuration; replace a rotated Key
402 / 403Insufficient credit or accessCheck Key quota and account status
404Endpoint, model, or group capability not foundRefresh models and verify the path
429Rate limited or upstream temporarily unavailableHonor Retry-After and back off with jitter
5xxTemporary gateway or upstream failureRecord context and retry only a few times