Skip to content
API reference

Create a message

Reference for POST /v1/messages, which generates a response in the Anthropic Messages format.

This page is the reference for the Anthropic-compatible messages endpoint. It is intended for developers who use Anthropic clients or send requests in the Anthropic Messages format.

Endpoint

POST https://api.engy.ai/v1/messages

Authentication

Send your API key in the x-api-key header, or in the Authorization header as a bearer token. For details, see Inference API overview.

Parameters

Body parameters

ParameterTypeRequiredDescription
modelStringYesThe model ID. A leading vendor/ segment is ignored.
messagesArrayYesThe conversation, as an array of messages with role (user or assistant) and content.
max_tokensIntegerNoThe maximum number of output tokens. If the prompt plus max_tokens exceeds the context window, Engy reduces max_tokens to fit.
systemString or arrayNoThe system prompt, as a string or an array of text blocks.
streamBooleanNoIf true, the response is streamed as server-sent events.
temperatureNumberNoThe sampling temperature.
top_pNumberNoThe nucleus sampling threshold.
top_kIntegerNoThe number of highest-probability tokens to sample from.
stop_sequencesArrayNoSequences at which generation stops.
toolsArrayNoThe tools that the model can call, each with name, description, and input_schema.
tool_choiceObjectNoauto, any, none, or tool with a name.
thinkingObjectNo{"type": "enabled"} or {"type": "disabled"}. The budget_tokens value is ignored.
providerObjectNoWorker requirements. For details, see The provider object.

Content blocks

Block typeSupported inDescription
textUser and assistant messagesText content.
imageUser messagesAn image with a base64 source. Images with a url source fail with status 400.
tool_useAssistant messagesA tool call that the model made.
tool_resultUser messagesThe result of a tool call, with tool_use_id.

Other block types, such as documents, are ignored. The cache_control and metadata fields are also ignored.

Response

Response fields

FieldTypeDescription
idStringThe message ID.
typeStringAlways message.
roleStringAlways assistant.
modelStringThe model ID, as sent in the request.
contentArrayThe text and tool_use blocks of the response.
stop_reasonStringend_turn, max_tokens, tool_use, or refusal.
stop_sequenceNullAlways null.
usage.input_tokensIntegerThe number of input tokens that were not read from the cache.
usage.cache_read_input_tokensIntegerThe number of input tokens read from the cache.
usage.cache_creation_input_tokensIntegerAlways 0. Engy does not charge for cache writes.
usage.output_tokensIntegerThe number of output tokens.

Non-streaming responses do not contain thinking blocks. Streaming responses contain thinking blocks unless thinking is disabled. For the event sequence, see Streaming.

Errors

Errors use the Anthropic format. For details, see Inference API overview.

StatusError typeCause
400invalid_request_errorThe request is invalid, or the prompt exceeds the context window. The message reads prompt is too long: N tokens > M maximum.
401authentication_errorThe API key is missing or invalid.
402api_errorThe available balance does not cover the request.
404not_found_errorThe model does not exist or is unavailable.
413request_too_largeThe images exceed the size or count limit.
429rate_limit_errorCapacity is exhausted, or a concurrency limit is reached.
503overloaded_errorNo worker meets the provider requirements.
504api_errorThe model server timed out.

Example

curl https://api.engy.ai/v1/messages \
  -H "x-api-key: $ENGY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kimi-k3",
    "max_tokens": 1024,
    "system": "You are a concise assistant.",
    "messages": [{"role": "user", "content": "What is the capital of France?"}]
  }'

Response:

{
  "id": "msg_5c7e2b9d1f3a4e6b8c0d2f4a",
  "type": "message",
  "role": "assistant",
  "model": "kimi-k3",
  "content": [{"type": "text", "text": "The capital of France is Paris."}],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 24,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 9
  }
}