How do I use the Leiolai Chat Completions API?

Send a Chat Completions request to /v1/chat/completions with the model ID leiolai-1, a messages array, and an API key. Use the mode permitted by the key and choose reasoning_effort for the task. A non-streaming response returns the answer in choices[0].message.content; a stream returns content deltas and ends with [DONE]. The format supports images, inline text files, client-defined function tools, structured JSON, and usage reporting through the documented fields.

What does a basic Chat Completions request contain?

Send model: leiolai-1 and a messages array of role/content pairs. Include mode: private or non-private when using an Unrestricted key. Private-only and Research-only keys can omit mode because the key has one permitted access mode.

{
  "model": "leiolai-1",
  "messages": [
    {
      "role": "user",
      "content": "Summarize the main point in one sentence."
    }
  ],
  "mode": "private",
  "reasoning_effort": "low",
  "max_completion_tokens": 256
}

Which roles can I send in messages?

Leiolai Chat Completions accepts system, user, assistant, and tool roles. Content can be a string or an array of supported typed parts. To continue a conversation, include the relevant earlier turns in messages with the new question.

Where is the answer in a JSON response?

Read choices[0].message.content from a non-streaming response. Leiolai returns one choice. For a tool response, read the assistant message’s tool_calls and continue with results in tool messages that include the matching tool_call_id.

Tool-call conversation flow

How do I stream the answer?

Set stream: true in the Leiolai request and append choices[0].delta.content from each text chunk. data: [DONE] ends the stream. For function calls, collect arguments by tool-call index and parse the completed JSON after finish_reason: tool_calls.

Streaming response handling

Which field chooses thinking depth?

Set reasoning_effort to low, medium, high, or xhigh in your Leiolai request. The default is low. The selected effort and mode determine the input and output token rates.

Effort by request format

How do I set an output-token cap?

Use max_completion_tokens. max_tokens is a compatibility alias. When an optional cap is omitted, the Leiolai API derives a ceiling from available balance and budget.

Can I send an image or text file?

Yes. Send base64 image data or supported inline UTF-8 text and code files through the Leiolai Chat Completions typed content parts. Files may contain up to 2 MiB per file. Remote image URLs, file-ID references, and binary PDFs are outside this input contract.

Images and files

Can the response be schema-valid JSON?

Yes. Set response_format in your Leiolai request to json_object or json_schema. Use json_schema when the JSON result must match specified fields and types. Do not combine structured output with function tools in the same request.

JSON output fields

How do I receive billed token counts?

Set stream_options.include_usage: true in a streaming Leiolai request. The final usage chunk has an empty choices array and arrives before [DONE]. When available, usage reports prompt_tokens, completion_tokens, and total_tokens used for billing.

Usage fields