docs
API

Chat Completions

Markdown

A model's response to a conversation in the OpenAI format. The most widely used format: almost all clients support it.

Full guide
POSThttps://api.ailoot.ai/v1/chat/completions
Chat Completions
curl https://api.ailoot.ai/v1/chat/completions \
  -H "Authorization: Bearer $AILOOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5-5",
    "messages": [
      {"role": "user", "content": "Explain what an API is in two sentences."}
    ]
  }' 
200 OK
{
  "id": "chatcmpl-8f2c…",
  "object": "chat.completion",
  "created": 1790812800,
  "model": "claude-sonnet-5-5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "An API is an agreement on how one program asks another to do something…"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 21,
    "completion_tokens": 48,
    "total_tokens": 69
  }
}

Authentication

  • Authorizationheaderrequired

    The key in the format Bearer sk-…. The following headers also work: x-api-key or x-goog-api-key.

Request body

  • modelstringrequired

    Model ID from the catalog, for example claude-sonnet-5-5. The model must support the OpenAI Chat format.

  • messagesarrayrequired

    Conversation history: objects with role (system, developer, user, assistant, tool) and content — a string or an array of parts (text, image_url).

  • streambooleanoptional

    A response in the Server-Sent Events format. Defaults to false. Billable text is delivered in a single block after the cost is calculated, rather than word by word.

  • stream_optionsobjectoptional

    {"include_usage": true} — include the final usage as the last event in the stream.

  • max_tokensintegeroptional

    Maximum response tokens. The newer name is max_completion_tokens. If no limit is set, Ailoot uses 4096 (or less if the model's response limit is lower; Grok has its own limit). For longer responses, set the limit explicitly; otherwise, the response stops at 4096 tokens with finish_reason: "length". The limit is included in the reserve: the higher it is, the more available balance you need.

  • temperaturenumberoptional

    Response randomness, usually from 0 to 2. Reasoning models may ignore it.

  • top_pnumberoptional

    An alternative to temperature: the fraction of probability mass used to select tokens.

  • stopstring | arrayoptional

    Strings that stop generation.

  • toolsarrayoptional

    Definitions of functions the model can call. Uses the OpenAI format: {"type": "function", "function": {...}}.

  • tool_choicestring | objectoptional

    auto, none, required or a specific function.

  • response_formatobjectoptional

    {"type": "json_object"} or {"type": "json_schema", ...} for a structured response, if the model supports it.

  • reasoning_effortstringoptional

    Reasoning depth for reasoning models: low, medium, high.

Other OpenAI parameters are passed through unchanged; support for each parameter is determined by the model's developer.

Response

  • choices[].messageobject

    Model response: content, or for tool calls — tool_calls.

  • choices[].finish_reasonstring

    stop — the response is complete; length — reached max_tokens (the response is still considered complete and billed for actual usage); tool_calls — the model is calling a tool.

  • usageobject

    prompt_tokens, completion_tokens, total_tokens — these are used to calculate the charge.

Still have questions? Send your Request ID and a description — we'll help you troubleshoot.Contact support