API Reference
Anthropic Messages API
The Messages endpoint keeps the Anthropic request shape while using a 51cowork API Key.
Use x-api-key and anthropic-version; model must come from /v1/models, and count_tokens can estimate input before generation.
- Generate
- POST /v1/messages
- Count
- POST /v1/messages/count_tokens
- Header
- x-api-key
- Stream
- stream: true
Generation request
Messages
bashcurl "https://api.51cowork.com/v1/messages" \
-H "x-api-key: <key-from-dashboard>" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "<model-from-v1-models>",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Hello"}]
}'| Field | Rule |
|---|---|
| model | ID returned by /v1/models |
| max_tokens | Positive integer within model support |
| messages | At least one valid message |
| stream | Optional event stream |
Estimate input tokens
count_tokens estimates input and does not generate a response. Use the same model and messages as the generation request.
Count tokens
bashcurl "https://api.51cowork.com/v1/messages/count_tokens" \
-H "x-api-key: <key-from-dashboard>" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"<model-from-v1-models>","messages":[{"role":"user","content":"Hello"}]}'Compatibility boundary
- Do not assume every model supports identical content, tools, or context fields.
- When upstream rejects a field, remove the smallest unsupported option and retry only when safe.
- Consume streaming events incrementally instead of buffering the full body.
