How do I measure token usage in the Leiolai API?
Use the token counts returned with a Leiolai API response when available. Chat Completions reports prompt_tokens, completion_tokens, and total_tokens. For a streamed chat response, request the final usage chunk. Combine the input and output counts with the rate for the request’s mode and effort.
Read the Leiolai API reference
What do prompt_tokens and completion_tokens count?
Leiolai Chat Completions reports input as prompt_tokens and generated output as completion_tokens. total_tokens is their combined count. To calculate the charge, apply the selected input rate to prompt_tokens and output rate to completion_tokens.
How do I receive usage in a Chat Completions stream?
Set stream_options.include_usage: true alongside stream: true in the Leiolai request. The usage-only chunk has an empty choices array and arrives immediately before [DONE]. Earlier chunks have usage: null.
Parse text and usage eventsAre the returned counts the counts used for billing?
Yes, when present, Leiolai’s usage counts are the counts used for billing. Keep the input and output counts with the mode and effort selected for that request. Non-streaming responses include usage when counts are available.
How do I turn token counts into a dollar estimate?
Divide each count by one million, multiply by its corresponding per-million rate, then add input and output costs. For Leiolai Research low, 100,000 input tokens and 2,000 output tokens cost $0.00104 at the published launch rates.
Use the token cost calculatorWhy should I track input and output separately?
Leiolai has separate input and output rates. A long document followed by a short answer can cost differently from a short prompt followed by a long answer. Tracking both counts shows whether sent history, supplied text, or generated output accounts for your usage.
Can an output cap help control request length?
Yes. Use max_completion_tokens in Leiolai Chat Completions, max_output_tokens in Responses, or max_tokens in Messages and text Completions. A finite response that reaches its cap can end with a length-related finish reason or an incomplete status.
Understand the response capWhere do Messages streams report usage?
Messages includes input usage in message_start and reports output usage in message_delta. Keep these values with the response’s stop reason. This event shape differs from Leiolai Chat Completions’ final usage-only chunk.
Messages response and streaming fieldsHow is a continuous session charged?
Leiolai API input and output tokens are billed at separate rates for the session’s selected mode and effort. Stop the session when finished. The continuous session also ends if the available balance or API budget is exhausted.
Continuous generation controls