Create Message
Send a list of messages and get back the next assistant turn as content blocks. Supports streaming, tool use, extended thinking, and image and document input.
Creates the next assistant turn for a conversation in the Anthropic Messages
format. Supports both streaming and non-streaming modes. Any Anthropic SDK
works out of the box - just point its base URL at https://api.aivene.com.
POST /v1/messagesAuthentication
x-api-keystringoptionalAPI key, as sent by the Anthropic SDKs. Either this header or
Authorization is required.
AuthorizationBeareroptionalAPI key as a bearer token. Takes precedence over x-api-key when both are
sent. Create keys at
Manage API Keys.
Headers
Content-TypestringrequiredMust be application/json.
anthropic-betastringoptionalComma-separated beta flags, as sent by the Anthropic SDKs. Flags that are not supported are ignored rather than rejected.
Body
modelstringrequiredModel id from GET /v1/models. Example: claude-sonnet-4-6,
claude-opus-4-7, gpt-5.4.
messagesMessage[]requiredConversation history, alternating user and assistant turns. Must
contain at least one message. See Message shape.
max_tokensintegerrequiredMaximum number of tokens to generate, thinking included. Must not exceed the model's output limit.
systemstring | TextBlock[]optionalSystem prompt. Pass an array of text blocks to put cache_control on
part of it.
streambooleanoptionalDefault falseStream the response as named server-sent events instead of returning a single JSON body. See Streaming events.
temperaturenumberoptionalDefault 1Between 0 and 1. Higher = more random.
top_pnumberoptionalBetween 0 and 1. Nucleus sampling. Use temperature or top_p,
not both.
top_kintegeroptionalSample only from the top K options for each token.
stop_sequencesstring[]optionalCustom sequences that stop generation. When one is hit, stop_reason is
stop_sequence and stop_sequence names it.
toolsTool[]optionalTools the model may call. See Tool use.
tool_choiceobjectoptionalHow the model uses tools:
{ type: 'auto' }- the model decides (default).{ type: 'any' }- the model must call one of the tools.{ type: 'tool', name }- the model must call the named tool.{ type: 'none' }- the model must not call a tool.
auto, any and tool also take disable_parallel_tool_use: true to
allow at most one tool call per turn.
thinkingobjectoptionalExtended thinking, on models that support it:
{ type: 'enabled', budget_tokens }- think with a token budget. The budget counts towardmax_tokens.{ type: 'adaptive' }- the model decides how much to think. Combine withoutput_config.effort.{ type: 'disabled' }- no thinking.
display (summarized or omitted) controls whether thinking text is
returned, on models that support it. See Reasoning.
output_configobjectoptionalOutput controls, on models that support them:
effort-low,medium,high,xhighormax. How much effort the model spends, thinking included.format-{ type: 'json_schema', schema }asks the model to return JSON that follows your schema. Validate the output if your app relies on it.
cache_controlobjectoptional{ type: 'ephemeral' } at the top level turns on automatic prompt
caching. You can also put cache_control on individual content blocks,
system blocks and tools. See Prompt caching.
context_managementobjectoptionalContext editing, for example clearing old tool results from long
conversations, on models that support it. Requires the matching
anthropic-beta flag.
metadataobjectoptional{ user_id } - an opaque identifier for your end user. Do not send names,
email addresses or other personal data.
Message shape
type Message =
| { role: 'user'; content: string | ContentBlock[] }
| { role: 'assistant'; content: string | ContentBlock[] };A string content is shorthand for a single text block:
[
{
"role": "user",
"content": [
{ "type": "image", "source": { "type": "url", "url": "https://example.com/cat.png" } },
{ "type": "text", "text": "What is in this image?" }
]
}
]Content block types
| Type | Used in | Description |
|---|---|---|
text | user, assistant | Plain text: { "type": "text", "text": "Hello" }. |
image | user | Image by source: base64 (media_type, data), url, or file (file_id from Files). |
document | user | Document by source: base64 PDF, url, plain text, or file (file_id). Optional title, context, and citations: { enabled: true }. |
tool_use | assistant | A tool call the model made: id, name, input. Send it back unchanged. |
tool_result | user | Your result for a tool call: tool_use_id, content (string or blocks), optional is_error. |
thinking | assistant | Thinking from an earlier turn, with its signature. Send it back unchanged. |
redacted_thinking | assistant | Encrypted thinking from an earlier turn. Send it back unchanged. |
Any block except thinking and redacted_thinking can carry
cache_control.
Images and documents
image and document blocks are only accepted by models with the matching
input capability. Check GET /v1/models. See
Image understanding and
Documents.
Response
idstringoptionalUnique message id, prefixed avn_.
type'message'optionalAlways message.
role'assistant'optionalAlways assistant.
modelstringoptionalThe model id you sent in the request.
contentContentBlock[]optionalThe reply as text, tool_use, thinking and redacted_thinking
blocks, in order. text blocks can carry citations when you enabled
them on a document.
stop_reasonstringoptionalWhy the model stopped: end_turn, max_tokens, stop_sequence,
tool_use, or refusal.
stop_sequencestring | nulloptionalThe custom stop sequence that was hit, if any.
usageobjectoptionalinput_tokens, output_tokens, cache_creation_input_tokens and
cache_read_input_tokens. input_tokens excludes cached tokens, so the
total input is the sum of the three input fields. Always present: on the
response, or on the stream's message_start and message_delta events.
Streaming
When stream: true, the response is text/event-stream with named events
(message_start, content_block_start, content_block_delta,
content_block_stop, message_delta, message_stop). There is no
[DONE] sentinel: the stream closes after message_stop. See
Streaming events.
Tool use
Provide a tools array. A custom tool has a name, a description and a
JSON Schema input_schema:
{
"name": "get_weather",
"description": "Get the current weather for a city.",
"input_schema": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}When the model calls a tool, the reply contains a tool_use block and
stop_reason is tool_use. Run the tool yourself, then send a new request
that appends the assistant turn unchanged and a user turn with a
tool_result block whose tool_use_id matches. The model then continues.
Custom tools work with every model that supports tool use. On Claude
models you can also use the Anthropic-defined client tools that your own code
executes: bash_*, text_editor_*, memory_* and computer_*. See
Tool calling.
Extended thinking
With thinking enabled, the reply starts with thinking blocks (or
redacted_thinking blocks) before the answer. When you continue the
conversation, for example after a tool call, send those blocks back
unchanged in the assistant turn so the model keeps its train of thought.
Don't edit them: the signature is checked. See
Reasoning.
Errors
Errors returned before the response starts share one shape:
{ "error": { "message": "...", "type": "invalid_request_error" } }| Status | error.type | Meaning |
|---|---|---|
400 | validation_error | The body failed schema validation. The message names the offending field. |
400 | invalid_request_error | Unknown model, content or a feature the model does not support (for example images, tools or output_config.format), or max_tokens above the model's limit. |
401 | authentication_error | Missing or invalid API key. |
402 | invalid_request_error | Not enough credit for the request, an unpaid balance, or a spend limit was reached. |
403 | permission_denied_error | The account is suspended, an Admin key was used, or the model isn't included in your organization's tier. |
404 | not_found_error | The model is deprecated. The message names its replacement. |
408 | timeout_error | The model did not finish before the request timed out (non-streaming requests). |
429 | rate_limit_error | Your organization hit its rate limit for this model. Back off and retry. |
500 | internal_server_error | Unexpected server error. |
502 / 503 | upstream_error | The model is temporarily unavailable. Safe to retry. |
When the model itself rejects a request, the response keeps the model's
4xx status with type upstream_error or invalid_request_error, and
error.code names the cause when it is known (context_length_exceeded,
content_filter, request_too_large). Errors after a stream has started
arrive as an error event.