Skip to content
Main Site News Console

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

ValueMeaningRecommended Handling
stopEnded normallyUse directly
lengthTruncated after reaching the max_tokens limitIncrease max_tokens or continue writing in segments
tool_callsThe model requested a function callReturn the result after executing the function, see FC Function Calling
content_filterContent was blocked by upstream safety policiesAdjust the prompt

usage Fields

  • usage is the basis for reconciliation: billing is charged separately by prompt_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_tokens marks the cached portion, which is billed at the cache rate, see Cache Billing.

Parsing Recommendations

  • Always read choices[0].message.content; do not assume choices has more than 1 item;
  • Reasoning models (-thinking tier) may include a reasoning_content field; 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.