API reference
Messages
POST /v1/messages takes a request in the Anthropic Messages format and answers in the same format, whole or streamed.
https://gateway.kalsenti.ai/v1/messagesOn this page
Headers
curl https://gateway.kalsenti.ai/v1/messages \
-H "x-api-key: $KALSENTI_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017-raw",
"max_tokens": 1024,
"system": "You are a concise assistant.",
"messages": [{ "role": "user", "content": "Name three sea birds." }]
}'| Header | Notes |
|---|---|
x-api-key | Your key. Authorization: Bearer … works too. |
anthropic-version | Required. Any date written as YYYY-MM-DD, such as 2023-06-01. Without it you get a 400. The Anthropic SDK sends it for you. |
Content-Type | application/json |
Idempotency-Key | Optional. See Idempotency keys. |
Request body
modelstringrequired- A model id from GET /v1/models.
max_tokensintegerrequired- The most tokens the reply may use, at least 1. Asking for more than the model allows gives you the model’s maximum, without an error.
messagesarrayrequired- Alternating
userandassistantmessages, each with stringcontentor a list of content blocks. systemstring or array- Instructions for the whole conversation: a string, or a list of
textblocks, which can carrycache_control. streamboolean- Send the reply as server-sent events. See Streaming.
temperaturenumber- Passed to the model as given.
top_pnumber- Passed to the model as given.
stop_sequencesarray- Up to 4 strings that end the reply when the model writes them.
toolsarray- Tools with a
name, adescriptionand aninput_schema. Built-in tool types work on some models only, and others refuse them with a400and the codeunsupported_tool_type. tool_choiceobject{ "type": "auto" },any,none, or{ "type": "tool", "name": "…" }.disable_parallel_tool_useis honoured.thinkingobject- Lets the model reason before it answers. See Thinking.
Other fields, such as top_k, metadata and output_config.effort, are ignored. Structured output is refused: see Not supported.
Content blocks
| Block | Notes |
|---|---|
text | Can carry cache_control, for prompt caching on models that support it. |
image | A source of base64 data with its media_type, or a url. |
tool_use | A tool call from an earlier reply. |
tool_result | Your answer to a tool_use, by tool_use_id, with string content or text blocks and an optional is_error. Images inside a tool result are dropped. |
thinking, redacted_thinking | Reasoning from an earlier reply. Signed thinking is passed back to models that use it. |
Other block types, such as document, are refused with a 400.
Thinking
{ "type": "enabled", "budget_tokens": 4000 } lets the model think before answering, with a budget of at least 1,024 tokens. A budget as large as max_tokens is trimmed to fit inside it. { "type": "adaptive" } lets the model decide, and { "type": "disabled" } turns it off.
{
"model": "deepseek-v4.1-flash-1017-raw",
"max_tokens": 8000,
"thinking": { "type": "enabled", "budget_tokens": 4000 },
"messages": [{ "role": "user", "content": "How many weekdays are there in March 2027?" }]
}The reply then starts with a thinking block. Models that don’t support thinking answer without one. Thinking counts towards the reply’s output tokens, and is charged at the output price.
Response
{
"id": "msg_7e2a90c41f5d3b68a0c9e127",
"type": "message",
"role": "assistant",
"model": "deepseek-v4.1-flash-1017-raw",
"content": [
{ "type": "text", "text": "Puffin, gannet and kittiwake." }
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 18,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 0,
"output_tokens": 9
}
}contentarraythinkingblocks with asignature,textblocks, andtool_useblocks with anid,nameand parsedinput.stop_reasonstringend_turn,max_tokens,stop_sequence,tool_useorrefusal.stop_sequencemeans one of yourstop_sequencesended the reply. Some models don’t say which sequence matched, and then such a reply readsend_turn.stop_sequencestring or null- The stop sequence that ended the reply, when
stop_reasonisstop_sequence. Otherwisenull. usageobjectinput_tokens,cache_creation_input_tokens,cache_read_input_tokensandoutput_tokens. Hereinput_tokensdoesn’t include tokens read from or written to the cache. The cache counts are0when the cache wasn’t used, or the model doesn’t report it.
Streaming
With "stream": true, events come in this order: message_start, then for each block content_block_start, its content_block_delta events and content_block_stop, then message_delta with the stop_reason, and message_stop.
event: message_start
data: {"type":"message_start","message":{"id":"msg_7e2a90c41f5d3b68a0c9e127","type":"message","role":"assistant","model":"deepseek-v4.1-flash-1017-raw","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":18,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":1}}}
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Puffin, gannet"}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" and kittiwake."}}
event: content_block_stop
data: {"type":"content_block_stop","index":0}
event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":18,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":9}}
event: message_stop
data: {"type":"message_stop"}- Deltas are
text_delta,thinking_delta,signature_deltaand, for tool calls,input_json_delta. - After 15 seconds with nothing to send, a
pingevent keeps the connection open. - If the model fails part way through, an
errorevent is the last thing sent, with nomessage_stop.
The final message_delta carries the reply’s full usage, input and cache counts included. Some models report the input in message_start too, and on others it’s 0 there. The Anthropic SDK reads the final counts from message_delta, so finalMessage() in JavaScript and get_final_message() in Python have the right usage. If you read the events yourself, take usage from message_delta.
Not supported
| What | What happens |
|---|---|
Roles other than user and assistant | Refused with a 400. Put instructions in system. |
document and other block types | Refused with a 400. |
Structured output: output_format or output_config.format | Refused with a 400 invalid_request_error, rather than ignored. Use response_format on chat completions. |
| Message batches, files and other endpoints | Not available. Only /v1/messages and /v1/messages/count_tokens are served. |