Response Data Handling
This page explains how to correctly parse the response data returned by 4ALL API, and applies to all models called via Chat Completions.
Non-streaming Response Structure
{ "id": "chatcmpl-xxx", "object": "chat.completion", "model": "gpt-5.5", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "……" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 12, "completion_tokens": 46, "total_tokens": 58 }}finish_reason Handling
| Value | Meaning | Recommended Handling |
|---|---|---|
stop | Ended normally | Use directly |
length | Truncated after reaching the max_tokens limit | Increase max_tokens or continue writing in segments |
tool_calls | The model requested a function call | Return the result after executing the function, see FC Function Calling |
content_filter | Content was blocked by upstream safety policies | Adjust the prompt |
usage Fields
usageis the basis for reconciliation: billing is charged separately byprompt_tokens/completion_tokens;- The final data chunk of a streaming call also carries
usage(see Streaming Output); - When a prompt cache is hit,
prompt_tokens_details.cached_tokensmarks the cached portion, which is billed at the cache rate, see Cache Billing.
Parsing Recommendations
- Always read
choices[0].message.content; do not assumechoiceshas more than 1 item; - Reasoning models (
-thinkingtier) may include areasoning_contentfield; when displaying, distinguish it from the main body, see Reasoning Model Output; - When an error occurs, the response is in the
{"error": {...}}structure; see Error Codes and Retries for handling.