Chat Completion API
Chat Completion
This QAnswer endpoint is an OpenAI Compatible chat completion.
See the OpenAI documentation for the full request/response schema.
An API key is required to use this endpoint:
- Create one on your Profile Page
- Pass the API key as a Bearer token in the Authorization header.
An administrator must allocate credits to a user. New API keys have 0 credits by default.
Payload Example
/api/v1/{llm_id}/chat/completions
Token usage
Every response reports the tokens it used in usage: prompt_tokens, completion_tokens and total_tokens. When the model's provider reports a breakdown, QAnswer passes it on:
- prompt_tokens_details.cached_tokens: prompt tokens served from the provider's prompt cache.
- completion_tokens_details.reasoning_tokens: tokens a reasoning model spent before writing its answer.
- cache_creation_input_tokens and cache_read_input_tokens: the cache counters of Anthropic models, for tokens written to and read from the cache. Each appears only when it is not 0.
"usage": {
"prompt_tokens": 1250,
"completion_tokens": 310,
"total_tokens": 1560,
"prompt_tokens_details": { "cached_tokens": 1024 },
"completion_tokens_details": { "reasoning_tokens": 192 }
}The breakdown fields appear only when the provider reports them: check that a field exists before reading it.
In a streamed response, usage comes in the last chunk, whose choices list is empty.
To price cached tokens separately from other prompt tokens, set the model's Cached Input Token Cost, see LLM Providers.