API docs · Chat & images
OpenAI-compatible API
POST /v1/chat/completions: request fields, streaming, usage and errors.
POST https://api.aitoken.tools/v1/chat/completions is compatible with the OpenAI Chat Completions API. For most models the request body is passed to the upstream as is (with model mapped to the upstream model ID). Some models (such as Claude and GPT) use the Anthropic Messages or OpenAI Responses API upstream: the platform converts the common fields, drops fields the upstream doesn't support, and caps max_tokens at the model's limit. Responses always come back in Chat Completions format (with model mapped back to this site's name).
Request fields
| Field | Description |
|---|---|
model | Required. A chat model name from this site |
messages | Required, non-empty array. Supports system / user / assistant / tool messages and images (when the capabilities include image) |
max_tokens / max_completion_tokens | Optional. The most tokens this request may output; without it the hold uses the model's max output, so setting it holds less. If your balance or key limit can't cover the hold, the output limit for this request is lowered (see chat pricing) |
stream | Optional. true returns an SSE stream |
stream_options.include_usage | Optional. When streaming, returns usage in the last chunk |
tool_choice | Optional. none / auto / required, or {"type":"function","function":{"name":…}}. Requiring a tool call needs top-level tools or in-message tools (Kimi dynamic tools) to be non-empty; an invalid value or missing tools returns 400 |
temperature, top_p, presence_penalty, frequency_penalty, n | Optional. Kimi models follow the official constraints: temperature 0-1, top_p 0.95, both penalties 0, n 1; values outside them return 400 (param names the field), and valid values take effect as the official defaults. Other models are forwarded to the upstream; if the upstream only accepts defaults, the platform drops them before forwarding |
tools, stop, other fields… | Passed through and validated by the upstream's rules; when the request is converted, unsupported fields are dropped |
Reasoning models (Kimi, DeepSeek and others)
- The thinking is returned in
message.reasoning_content(delta.reasoning_contentwhen streaming) and the answer incontent; tokens used for thinking count towardcompletion_tokens(seecompletion_tokens_details.reasoning_tokens) and are billed at the output price. - Give
max_tokensenough room (1024 or more recommended): if it is too small, all of it goes to thinking and you getfinish_reason: "length"with an empty answer. - Thinking is always on: passing
enable_thinking: false,thinking: { "type": "disabled" },reasoning_effort: "none"or similar to these models does not error but is ignored, and the model still thinks (consistent with the official API). For faster replies, setreasoning_efforttolow.
Streaming
With stream: true the response is text/event-stream, one data: {…} per event, ending with data: [DONE]. The platform always asks the upstream for usage to settle the bill; the final chunk carrying usage is forwarded to you only if you also sent stream_options.include_usage.
Failures and retries
- If the upstream fails before sending the first byte (timeout, 5xx, rate limit), the platform retries automatically, up to 3 attempts in total; you only see the final result.
- If the upstream rejects the request as invalid (400): the platform first retries without optional parameters such as
temperature/top_p; if the request is still not accepted, the error status and the reason are returned in the platform's standard format, free of charge. - If a stream breaks after it has started, it is not retried; you pay for what was already output (see chat billing).
Error format
Errors use the OpenAI shape { "error": { "message", "type", "code", "param" } }, which the official SDKs recognize. Common statuses:
| Status | type / code | Cause |
|---|---|---|
| 401 | invalid_api_key | Missing, wrong or disabled key |
| 402 | quota_exceeded | The account can't cover even the minimum output (1,024 tokens); the message states the minimum amount to hold and the amount available (exact values in error.details). When the balance is only short of the full output limit there is no error: the output limit for this request is lowered instead (worked out from 90% of the available amount; see chat billing for which requests this applies to. Requests that are not lowered return 402 as soon as the hold for the full output limit cannot be covered) |
| 402 | key_limit_exceeded | The key's total or daily limit can't cover even the minimum output; the message states the amount to hold, what the key has left, and its limit |
| 403 | permission_denied | The key lacks chat:create, or the model isn't enabled / isn't on the key's allowlist |
| 404 | not_found | The model name doesn't exist or isn't a chat model |
| 400 | invalid_parameter | Invalid request body (for example empty messages, an invalid tool_choice, Kimi sampling parameters outside the official range); param names the field |
| 429 | rate_limited | Over an RPM limit set on the account or the key, or chat and image requests in flight exceed a concurrency limit set on the account or the key, or the model is busy (upstream rate limiting); wait for Retry-After |
| 400 | invalid_request_error | The model rejected the request parameters; message is an explanation written by the platform in the request language. For common cases it states the specific reason (which parameter, the limit or the allowed values, e.g. "parameter max_tokens exceeds the maximum output length this model allows; limit 16384 tokens"): fix the request accordingly and resend. Otherwise it only asks you to check the request parameters against the parameter reference. The model-side wording is never passed through. When the input exceeds the model context length, message always ends with the fixed English marker "(context_length_exceeded: maximum context length exceeded, prompt is too long)": this text is stable and safe to match in code to detect context overflow (identical in every language; error events inside a stream carry it too, and in-stream OpenAI-format errors use code context_length_exceeded) |
| 400 | content_filter | The request content did not pass content safety review; revise the content before resending, as the same content will fail again |
| 503 | no_available_channel | The model is temporarily unavailable or has no route right now: retry later or use another model. message is returned in the language given by Accept-Language; when a streamed response fails midway, the error event in the stream is also a platform explanation |
An invalid key (401) and an exceeded RPM limit (429) are rejected during authentication, so their body uses the platform's general shape { "error": { "code", "message", "retryable", "request_id" } }. It still carries error.message, so SDKs raise a normal exception.
curl https://api.aitoken.tools/v1/chat/completions \
-H "Authorization: Bearer $AITOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{ "role": "user", "content": "Hello" }]
}'