Skip to content

docs: document usage.completion_tokens_details.reasoning_tokens - #56

Merged
PierreLeGuen merged 1 commit into
mainfrom
docs/reasoning-tokens-completion-tokens-details
Oct 2, 2026
Merged

PierreLeGuen merged 1 commit into
mainfrom
docs/reasoning-tokens-completion-tokens-details

Conversation

@PierreLeGuen

@PierreLeGuen PierreLeGuen commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

OpenAI-compatible clients (the Vercel AI SDK `@ai-sdk/openai-compatible`, OpenCode, OpenRouter tooling) read the reasoning token count from `usage.completion_tokens_details.reasoning_tokens`. Our responses only carried SGLang's top-level `usage.reasoning_tokens`, and streams carried no count at all, so those clients showed zero reasoning tokens for GLM 5.3 Flash. The gateway and proxy are being changed to emit the standard field on every path while keeping the top-level field as a deprecated alias.

What

  • `cloud/reasoning-models.mdx`: describe `completion_tokens_details.reasoning_tokens` as the canonical location, note it is a subset of `completion_tokens`, say when it appears in streams (`stream_options.include_usage`), and mark the top-level field deprecated. Update the example response.
  • `cloud/quickstart.mdx`: same change to the example response and note.

Merge after

Both code changes are merged but not yet in production. Merge this PR once both are live:

Follow-up outside this PR: the quickstart still uses the retired `zai-org/GLM-5.1-FP8` id in its examples.

The reasoning token count now also appears in
usage.completion_tokens_details.reasoning_tokens, the location OpenAI
uses and OpenAI-compatible SDKs read. Update the reasoning-models guide
and the quickstart example, and mark the top-level usage.reasoning_tokens
as a deprecated alias.
@PierreLeGuen
PierreLeGuen marked this pull request as ready for review October 2, 2026 13:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T13:20:29.016968Z 08f724b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08f724bd1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


- `reasoning_content` — the model's internal thinking (streamed as `delta.reasoning_content` chunks when `stream: true`)
- `usage.reasoning_tokens` — how many completion tokens were spent thinking
- `usage.completion_tokens_details.reasoning_tokens` — how many of the completion tokens were spent thinking. It is present in non-streaming responses and in the final usage chunk of a stream when you set `stream_options: {"include_usage": true}`. The top-level `usage.reasoning_tokens` carries the same number and is deprecated.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update Best Practices to use the canonical token field

This declares the top-level usage.reasoning_tokens alias deprecated, but the Best Practices checklist at line 215 still tells readers to monitor that alias. Readers following the checklist will therefore build new monitoring against the field this change is trying to retire; update that item to recommend usage.completion_tokens_details.reasoning_tokens as well.

Useful? React with 👍 / 👎.

@PierreLeGuen
PierreLeGuen merged commit ed0fb3e into main Oct 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming usage omits reasoning_tokens even when the stream delivered reasoning deltas

1 participant