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.
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
Base URL and authentication
Send model requests to /v1/... paths on the Gateway at https://api.51cowork.com. Manage your account in Dashboard.
bashexport COWORK_GATEWAY_URL="https://api.51cowork.com"
export COWORK_API_KEY="<key-from-dashboard>"
export COWORK_MODEL="<model-from-gateway>"| Client | Base URL | Path appended by the client |
|---|---|---|
| Direct HTTP | https://api.51cowork.com | Use the full /v1/... path |
| OpenAI SDK / OpenCode / Cursor | https://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/completions | Full URL; no appended path |
| Anthropic SDK / Claude Code | https://api.51cowork.com | /v1/messages |
| Codex | https://api.51cowork.com | wire_api = responses |
| Method | Header |
|---|---|
| Recommended | Authorization: Bearer <API_KEY> |
| Anthropic compatible | x-api-key: <API_KEY> |
| Gemini compatible, when enabled | x-goog-api-key: <API_KEY> |
GET /v1/models
Read the models currently exposed to the Key's assigned group.
bashcurl "$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.
POST /v1/messages
Anthropic Messages-compatible endpoint.
bashcurl "$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.
bashcurl "$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"}]
}'| Field | Requirement |
|---|---|
| model | An ID returned by /v1/models |
| max_tokens | Positive integer, bounded by client and model support |
| messages | At least one valid message |
| stream | Optional; true returns an event stream |
POST /v1/chat/completions
OpenAI Chat Completions-compatible endpoint.
bashcurl "$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.
POST /v1/responses
OpenAI Responses-compatible endpoint and the wire API used by Codex.
bashcurl "$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."
}'Streaming
Set stream to true and process server-sent events incrementally. cURL uses -N to disable output buffering.
bashcurl -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.
HTTP status and error handling
| Status | Typical meaning | Action |
|---|---|---|
| 400 | Invalid JSON, field, or model parameter | Fix the request; do not retry unchanged |
| 401 | Missing, invalid, or disabled Key | Reload configuration; replace a rotated Key |
| 402 / 403 | Insufficient credit or access | Check Key quota and account status |
| 404 | Endpoint, model, or group capability not found | Refresh models and verify the path |
| 429 | Rate limited or upstream temporarily unavailable | Honor Retry-After and back off with jitter |
| 5xx | Temporary gateway or upstream failure | Record context and retry only a few times |
