Chat Completions
The OpenAI-compatible Chat Completions endpoint.
OpenAI-compatible endpoint
Chat Completions is suitable for existing OpenAI-compatible clients. It uses a Bearer user API Key and settles charges from the OpenAI usage fields.
Paths
| Purpose | Method and path |
|---|---|
| Model request | POST /v1/chat/completions |
| Compatible path | POST /chat/completions |
| Model list | GET /v1/models, GET /v1/models/, GET /models, GET /models/ |
Request example
curl https://dingjiai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_USER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "A_MODEL_NAME_COPIED_FROM_THE_OPENAI_CHAT_MODEL_LIST",
"messages": [
{ "role": "user", "content": "Introduce yourself in one sentence" }
]
}'Streaming
curl -N https://dingjiai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_USER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "A_MODEL_NAME_COPIED_FROM_THE_OPENAI_CHAT_MODEL_LIST",
"stream": true,
"messages": [
{ "role": "user", "content": "Explain the integration in three points" }
]
}'The gateway prefers valid upstream stream usage. When final usage is missing or invalid, a token-priced stream can use a conservative output estimate only if the gateway can extract generated output. Heartbeats, empty events, and raw chunks are not sufficient evidence. An upstream disconnect, client cancellation, or delivery failure may still settle trusted partial usage or extractable output already observed by the gateway; successful chunk delivery is not required. A truly blank or malformed non-stream response fails for the client as usage_missing or usage_invalid, releases the reservation, and is charged zero.
For a stream, the gateway commits response headers after the upstream returns 2xx. If the stream ends without trusted usage or extractable output, the gateway releases the reservation, charges zero, and records the failure. The client may still receive a 2xx response with an empty body or only SSE keepalives; the gateway cannot rewrite it as an error body. This differs from the client-visible result of a blank or malformed non-stream response.
Request fields
Prop
Type
Usage and billing
Settlement reads usage.prompt_tokens, usage.completion_tokens, and the optional usage.prompt_tokens_details.cached_tokens field from the response body.
Upstream explicit usage data remains the preferred and most accurate settlement source.
Real usage takes priority
The server never trusts client-supplied token estimates. For token-priced products, a valid non-stream success JSON object with missing or invalid usage may use an output estimate with a one-output-token minimum, even with no extractable output (including {}). Stream estimates require extractable generated output; heartbeats, empty events, and raw chunks are insufficient. An upstream disconnect, client cancellation, or delivery failure may still settle trusted partial usage or extractable output already observed by the gateway; successful chunk delivery is not required.
Last updated on