API reference

Messages

POST /v1/messages takes a request in the Anthropic Messages format and answers in the same format, whole or streamed.

POSThttps://gateway.kalsenti.ai/v1/messages
On 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." }]
  }'
HeaderNotes
x-api-keyYour key. Authorization: Bearer … works too.
anthropic-versionRequired. 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-Typeapplication/json
Idempotency-KeyOptional. 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 user and assistant messages, each with string content or a list of content blocks.
systemstring or array
Instructions for the whole conversation: a string, or a list of text blocks, which can carry cache_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, a description and an input_schema. Built-in tool types work on some models only, and others refuse them with a 400 and the code unsupported_tool_type.
tool_choiceobject
{ "type": "auto" }, any, none, or { "type": "tool", "name": "…" }. disable_parallel_tool_use is 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

BlockNotes
textCan carry cache_control, for prompt caching on models that support it.
imageA source of base64 data with its media_type, or a url.
tool_useA tool call from an earlier reply.
tool_resultYour 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_thinkingReasoning 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.

Request body
{
  "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

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
  }
}
contentarray
thinking blocks with a signature, text blocks, and tool_use blocks with an id, name and parsed input.
stop_reasonstring
end_turn, max_tokens, stop_sequence, tool_use or refusal. stop_sequence means one of your stop_sequences ended the reply. Some models don’t say which sequence matched, and then such a reply reads end_turn.
stop_sequencestring or null
The stop sequence that ended the reply, when stop_reason is stop_sequence. Otherwise null.
usageobject
input_tokens, cache_creation_input_tokens, cache_read_input_tokens and output_tokens. Here input_tokens doesn’t include tokens read from or written to the cache. The cache counts are 0 when 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.

Events
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_delta and, for tool calls, input_json_delta.
  • After 15 seconds with nothing to send, a ping event keeps the connection open.
  • If the model fails part way through, an error event is the last thing sent, with no message_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

WhatWhat happens
Roles other than user and assistantRefused with a 400. Put instructions in system.
document and other block typesRefused with a 400.
Structured output: output_format or output_config.formatRefused with a 400 invalid_request_error, rather than ignored. Use response_format on chat completions.
Message batches, files and other endpointsNot available. Only /v1/messages and /v1/messages/count_tokens are served.