Skip to content

[Feature][Response API] Support num_cached_tokens and num_reasoning_tokens in ResponseUsage #23363

@heheda12345

Description

@heheda12345

🚀 The feature, motivation and pitch

These attributes are important for monitoring model behavior. But both variables are set to 0 now.

# TODO(woosuk): Implement the following fields.
self.num_prompt_tokens = 0
self.num_cached_tokens = 0
self.num_output_tokens = 0
self.num_reasoning_tokens = 0

#22667 implements num_prompt_tokens and num_output_tokens, but we still need help for num_cached_tokens and num_reasoning_tokens.

When implementing this, please note that

  1. gpt-oss has built-in tool calls so one request can trigger multiple rounds of generation
    async def _generate_with_builtin_tools(
  2. For non_streaming case, Context.append_output is called for each round of generation, while for streaming case, append_output is called for each output token.

Alternatives

No response

Additional context

No response

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions