Skip to content
Docs

Completions

Create a chat completion

The OpenAI Chat Completions format. With "stream": true the answer arrives as Server-Sent Events (data: {...} lines that end with data: [DONE]).

POST / v1 / chat / completions
POST / v1 / chat / completions

Create a chat completion

The OpenAI Chat Completions format. With "stream": true the answer arrives as Server-Sent Events (data: {...} lines that end with data: [DONE]).

Authorizations

Authorizationstring<bearer>required

Bearer authentication header of the form Bearer <token>, where <token> is your API key.

Your key stays in this page and is only sent with this request. Get an API key

Body

application/json

Up to 1,000 characters and 256 output tokens, to try the API. For more, use the API from your code, the Chat or an agent.

Create a chat completion
curl --request POST \
  --url https://api.libremodel.ai/v1/chat/completions \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "deepseek-v4.1-flash-1017",
  "messages": [
    {
      "role": "user",
      "content": ""
    }
  ],
  "max_tokens": 256
}'
{
  "id": "chatcmpl-01a22df8502973a9957575e4c07311be",
  "object": "chat.completion",
  "created": 1796067577,
  "model": "deepseek-v4.1-flash-1017",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop",
      "logprobs": null
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 10,
    "total_tokens": 19,
    "prompt_tokens_details": {
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    },
    "cost": 0.0000132
  }
}

Authorizations

Authorizationstringheaderrequired

Bearer authentication header of the form Bearer <token>, where <token> is your API key.

Body

application/json
  • modelstringrequired

    A Libremodel model ID, from Models or GET /v1/models.

  • messagesobject[]required

    The conversation, oldest first.

    Show child attributes
    • rolestringrequired

      Who says it.

      Allowed values:"system""user""assistant""tool"

    • contentstring | object[]required

      Text, or a list of parts: text, image_url (Vision) and file (Files).

    • tool_callsobject[]

      In an assistant message: the calls it made. Send them back as they came.

    • tool_call_idstring

      In a tool message: the call it answers.

  • max_completion_tokensinteger

    Cap on output tokens, reasoning included. max_tokens also works; if you send both, this one wins. See Output limit.

  • streambooleandefault: false

    Send the answer as Server-Sent Events, as it is generated. See Streaming.

  • stream_optionsobject

    With stream, {"include_usage": true} adds a last chunk with the token count and the cost.

  • reasoning_effortstring

    How much the model thinks before answering. Each model has its own levels and default: see Reasoning.

    Allowed values:"low""high""max""off"

  • toolsobject[]

    Functions the model can call. See Tool calling.

  • tool_choicestring | object

    auto, none, required, or one function. required and a function are only always followed on models that list tool_choice in supported_parameters.

  • temperaturenumber

    Sampling temperature.

  • top_pnumber

    Nucleus sampling.

  • stopstring | string[]

    Text that ends the answer.

Response

application/json

The answer. With stream, a text/event-stream instead.

  • idstringrequired

    The ID of the answer.

    Example: "chatcmpl-01a22df8502973a9957575e4c07311be"

  • objectstringrequired

    Always "chat.completion".

  • createdintegerrequired

    Unix time, in seconds.

  • modelstringrequired

    The model you asked for.

  • choicesobject[]required

    One answer.

    Show child attributes
    • messageobjectrequired

      role, content, and reasoning_content and tool_calls when there are any.

    • finish_reasonstringrequired

      Why it stopped.

      Allowed values:"stop""length""tool_calls"

  • usageobjectrequired

    Tokens and cost.

    Show child attributes
    • prompt_tokensintegerrequired

      Input tokens, cached ones included.

    • completion_tokensintegerrequired

      Output tokens, reasoning included.

    • prompt_tokens_detailsobjectrequired

      cached_tokens: input read from cache, billed at the cached price.

    • completion_tokens_detailsobjectrequired

      reasoning_tokens: the part of the output spent thinking.

    • costnumberrequired

      What the request cost, in dollars.

      Example: 0.0001605