Chat Completions
An OpenAI-compatible chat completion endpoint, including request parameters, billing rules, and error reference.
Request
- Authentication: request header
Authorization: Bearer sk-tp-...(create an API Key in the Console) - Content-Type:
application/json
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Platform model name; see Model list or Models |
| messages | array | Yes | An OpenAI-format message array; must not be empty |
| stream | boolean | No | When true, returns an SSE stream; see Advanced usage |
| Other parameters | - | No | temperature, top_p, max_tokens, tools, response_format, and others are passed through per the OpenAI protocol; whether they take effect depends on the model called |
Response
Non-streaming responses return OpenAI ChatCompletion JSON (choices + usage). The response headers carry billing information for this call:
| Header | Description |
|---|---|
| X-Cost-Yuan | Cost of this call (yuan, 6 decimal places) |
| X-Usage-Tokens | Total tokens for this call |
Streaming (stream=true) returns SSE with the same event format as OpenAI, ending with data: [DONE]. The platform automatically injects stream_options.include_usage, so the final chunk carries usage. Streaming response headers don't include X-Cost-Yuan; calculate the cost from usage yourself or check the billing ledger.
Billing
- Settled by the
usagereturned by the model, in "yuan per million tokens", with input and output priced separately. See Billing. - Cached-hit / cache-write tokens in
usage.prompt_tokens_detailsare priced separately at the cache price; if a model has no cache price configured, the input price applies. - Costs are deducted from the account balance; every quota-limited key node along the request chain accumulates its subtree consumption.
Pre-checks
Before the call, the platform validates in order; if any step fails, an error is returned:
- Key valid and not revoked (including all parents), account status normal → otherwise
401 - Model exists and is available (
LIVE) and is token-billed → otherwise400 messagesis not empty → otherwise400- Account balance greater than 0, key chain quota not exhausted → otherwise
402
Errors
For the error response body format and troubleshooting, see FAQ · Error codes. Errors returned by the upstream model service are passed through verbatim (status code and response body unchanged).