Skip to content
Docs

API reference

Messages

POST /v1/messages speaks the Anthropic Messages format, so the Anthropic SDKs and the tools built on them work with Libremodel models.

curl https://api.libremodel.ai/v1/messages \
  -H "x-api-key: $LIBREMODEL_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash-1017",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello, Libremodel"}]
  }'

Headers

Request headers
HeaderDescription
x-api-keyYour Libremodel key. Authorization: Bearer works too. See Authentication.
anthropic-versionOptional. The SDKs send it; without it, 2023-06-01 is used.
anthropic-betaOptional. It is not always passed on: don't rely on it.

Request body

Request parameters
ParameterTypeDescription
modelstring, requiredA Libremodel model ID, from Models or GET /v1/models.
messagesarray, requiredThe conversation, in the Messages format.
systemstring or arrayThe system prompt.
max_tokensintegerCap on output tokens. Optional here, unlike in the Anthropic API: the same rules as in Chat completions apply.
streambooleanSend the response as Server-Sent Events. See Streaming.

Other Messages fields: see what works in each format. With a model that does not take one, the answer is 400 invalid_request, and the message names the field.

Request
{
  "model": "deepseek-v4.1-flash-1017",
  "system": "You are a concise assistant.",
  "max_tokens": 512,
  "messages": [
    { "role": "user", "content": "Explain SSE in one sentence." }
  ]
}

Response

A Messages object. model is always the Libremodel ID you asked for, id is always a Libremodel ID (msg_…), and the response carries an x-request-id header. A response that reaches max_tokens ends with stop_reason: "max_tokens".

Response
{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "model": "deepseek-v4.1-flash-1017",
  "content": [{ "type": "text", "text": "Server-Sent Events is ..." }],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 21,
    "cache_read_input_tokens": 0,
    "output_tokens": 23
  }
}
Usage fields
FieldWhat it counts
usage.input_tokensInput tokens that were neither read from nor written to cache.
usage.cache_read_input_tokensInput tokens read from cache, billed at the cached price.
usage.cache_creation_input_tokensInput tokens written to cache, billed at the input price.
usage.output_tokensOutput tokens, billed at the output price.

Errors

Errors come in the Anthropic format: {"type": "error", "error": {"type", "message"}}, with the HTTP status telling them apart. The full list is in Limits and errors.