AI & LLM

OpenAI Chat Completion Response JSON Example

A real-world JSON example of an OpenAI Chat Completions API response — choices, message content, finish reason, and token usage. Copy-ready for building LLM integrations and cost tracking.

{
  "id": "chatcmpl-9kZpQ2rXvL8mNwT4hY6jK",
  "object": "chat.completion",
  "created": 1752134400,
  "model": "gpt-4o-2024-08-06",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The three primary colors are red, blue, and yellow."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 12,
    "total_tokens": 30
  },
  "system_fingerprint": "fp_a1b2c3d4e5"
}

Field Reference

idrequiredstringUnique identifier for this completion, prefixed chatcmpl- — useful for logging and support requests
choicesrequiredarrayOne entry per requested completion (n parameter) — usually a single-element array unless multiple completions were requested
choices[].finish_reasonrequiredstringWhy generation stopped: 'stop' (natural end), 'length' (hit max_tokens), 'tool_calls', or 'content_filter'
choices[].message.contentrequiredstring | nullThe generated text — null when the model instead returned a tool_calls array
usage.total_tokensrequirednumberprompt_tokens + completion_tokens — the number billing is based on
modelrequiredstringThe exact model version that served the request, useful since 'latest' aliases can change silently

Variants

Tool Callfinish_reason is 'tool_calls' instead of 'stop', and content is null — the model wants to call a function.
{
  "id": "chatcmpl-9kZqR3sYwM9nOx5iZ7kL",
  "object": "chat.completion",
  "created": 1752134500,
  "model": "gpt-4o-2024-08-06",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_8mKzQ2vXpL9wRfT",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\":\"Ahmedabad\",\"unit\":\"celsius\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 62,
    "completion_tokens": 21,
    "total_tokens": 83
  }
}

Common Use Cases

  • Parsing the assistant's reply out of an LLM API integration
  • Tracking per-request token usage for cost monitoring and rate limiting
  • Building a mock LLM response for frontend development against a chat UI before wiring up the real API
openaillmchat completiongptAItokens

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

A finish_reason of 'length' means the response was truncated mid-thought because it hit the max_tokens limit — the content you got back may be an incomplete sentence or a cut-off JSON object, and you should either increase max_tokens or treat it as incomplete rather than a finished answer.

From usage.prompt_tokens and usage.completion_tokens separately, since input and output tokens are usually priced differently (output tokens typically cost more per token than input tokens).

In this specific example it can't — content is only null when the model is making a tool call (finish_reason: 'tool_calls'). A 'stop' finish_reason with null content would indicate a malformed or unexpected API response worth logging.

Related JSON Examples