API reference
Create a message (Anthropic Messages compatibility)
POST /v1/messages request, response, and error contract.
POST /v1/messages
Anthropic Messages API compatibility endpoint. Accepts Anthropic-format requests and returns Anthropic-format responses. Supports tools, system prompts, and streaming. Authenticate with either Authorization: Bearer or x-api-key header.
Authentication¶
Send Authorization: Bearer $KOSCOMPUTE_API_KEY.
Request¶
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | See the endpoint guide for behavior and model support. |
messages |
array | Yes | See the endpoint guide for behavior and model support. |
max_tokens |
integer | Yes | See the endpoint guide for behavior and model support. |
system |
string · array | No | See the endpoint guide for behavior and model support. |
temperature |
number | No | See the endpoint guide for behavior and model support. |
top_p |
number | No | See the endpoint guide for behavior and model support. |
top_k |
integer | No | See the endpoint guide for behavior and model support. |
stop_sequences |
array | No | See the endpoint guide for behavior and model support. |
tools |
array | No | See the endpoint guide for behavior and model support. |
tool_choice |
object | No | See the endpoint guide for behavior and model support. |
metadata |
object | No | See the endpoint guide for behavior and model support. |
Examples¶
cURL¶
curl https://api.koscompute.com/v1/messages \
-H "x-api-key: $KOSCOMPUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"qwen/qwen3.8-27b","max_tokens":120,"messages":[{"role":"user","content":"Reply with one sentence."}]}'
Python¶
import os
import requests
response = requests.post(
"https://api.koscompute.com/v1/messages",
headers={"Authorization": f"Bearer {os.environ['KOSCOMPUTE_API_KEY']}"},
json={
"model": "qwen/qwen3.8-27b",
"max_tokens": 120,
"messages": [
{
"role": "user",
"content": "Reply with one sentence."
}
]
},
)
print(response.json())
JavaScript¶
const response = await fetch("https://api.koscompute.com/v1/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.KOSCOMPUTE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"model":"qwen/qwen3.8-27b","max_tokens":120,"messages":[{"role":"user","content":"Reply with one sentence."}]}),
});
console.log(await response.json());
Responses¶
| Status | Meaning |
|---|---|
200 |
Successful response |
400 |
Bad request — invalid parameters or payload |
401 |
Invalid or missing API key |
403 |
Model not allowed for this API key |
404 |
Public model not found |
413 |
Request body exceeds the limit |
429 |
Rate limit or admission capacity is full. The message states when to retry; vision saturation also reports active/total vision concurrency. |
500 |
Internal server error |
529 |
Anthropic-compatible provider unavailable or upstream failure |
Next steps¶
Use the endpoint guide for complete workflows, model capability notes, streaming behavior, and retry advice.