Messages API
Use a Messages-compatible client or estimate its input tokens before generation.
POST /v1/messages
curl "https://kavren.dev/v1/messages" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"messages": [
{
"role": "user",
"content": "Reply with the name of one planet."
}
],
"max_tokens": 64
}'Pass instructions as top-level system. Set max_tokens to cap the output. A streaming request emits named events such as content_block_delta.
Python SDK
import os
from anthropic import Anthropic
client = Anthropic(base_url="https://kavren.dev", api_key=os.environ["KAVREN_API_KEY"])
message = client.messages.create(
model="deepseek-v4.1-flash-fast", max_tokens=64,
messages=[{"role": "user", "content": "Reply with the name of one planet."}],
)
print("".join(block.text for block in message.content if block.type == "text"))The Anthropic SDK appends /v1/messages to the base URL. For OpenAI’s Python and Node clients, use the base URL ending in /v1. See client integrations for setup.
Send a plain-text document
curl "https://kavren.dev/v1/messages" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"max_tokens": 128,
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"title": "Meeting notes",
"source": {
"type": "text",
"media_type": "text/plain",
"data": "Delivery moved to Tuesday."
}
},
{
"type": "text",
"text": "When is delivery?"
}
]
}
]
}'Inline text documents or a content source containing text blocks are converted to text. This also works inside a user tool_result. Remote files and PDF sources are rejected.
Read content blocks
{
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Mars"
}
],
"stop_reason": "end_turn"
}Collect text blocks for display. A tool_use block requests a client action. Match its ID when sending a tool_result on the next turn.
Sampling and thinking
curl "https://kavren.dev/v1/messages" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"messages": [
{
"role": "user",
"content": "Reply with the name of one planet."
}
],
"max_tokens": 64,
"reasoning_effort": "low",
"temperature": 0.3,
"top_k": 30,
"stop_sequences": [
"<END>"
]
}'The Messages format accepts top_p, thinking and output_config.effort. When supplied, the explicit reasoning_effort takes precedence. Define client tools with name and input_schema. To require a specific tool, use tool_choice: {"type":"tool","name":"get_stock"}.
POST /v1/messages/count_tokens
curl "https://kavren.dev/v1/messages/count_tokens" \
-H "Authorization: Bearer $KAVREN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-fast",
"messages": [
{
"role": "user",
"content": "Reply with the name of one planet."
}
]
}'{
"input_tokens": 18
}Use the same system prompt, tools and messages you plan to send. This endpoint estimates input tokens without generating an assistant reply.