Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions async-openai/src/types/responses/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@ pub struct ResponseLogProb {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct OutputTextContent {
/// The annotations of the text output.
#[serde(default)]
pub annotations: Vec<Annotation>,
pub logprobs: Option<Vec<LogProb>>,
/// The text output from the model.
Expand Down Expand Up @@ -2349,6 +2350,35 @@ pub struct MCPApprovalRequest {
pub server_label: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct InputTokenDetails {
/// The number of tokens that were retrieved from the cache.
/// [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).
pub cached_tokens: u32,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct OutputTokenDetails {
/// The number of reasoning tokens.
pub reasoning_tokens: u32,
}

/// Usage statistics for a response.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(default)]
pub struct ResponseUsage {
/// The number of input tokens.
pub input_tokens: u32,
/// A detailed breakdown of the input tokens.
pub input_tokens_details: InputTokenDetails,
/// The number of output tokens.
pub output_tokens: u32,
/// A detailed breakdown of the output tokens.
pub output_tokens_details: OutputTokenDetails,
/// The total number of tokens used.
pub total_tokens: u32,
}

Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

These structs (InputTokenDetails, OutputTokenDetails, and ResponseUsage) already exist in async-openai/src/types/shared/response_usage.rs and are re-exported by the responses module in mod.rs (lines 23-24, 29).

The duplicate definitions should be removed to avoid:

  1. Maintenance issues with two versions of the same types
  2. Potential type conflicts and compilation errors
  3. Confusion about which version to use

Instead, you should use the existing shared types that are already imported at the top of this file (line 5: ResponseUsage).

Suggested change
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct OutputTokenDetails {
/// The number of reasoning tokens.
pub reasoning_tokens: u32,
}
/// Usage statistics for a response.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(default)]
pub struct ResponseUsage {
/// The number of input tokens.
pub input_tokens: u32,
/// A detailed breakdown of the input tokens.
pub input_tokens_details: InputTokenDetails,
/// The number of output tokens.
pub output_tokens: u32,
/// A detailed breakdown of the output tokens.
pub output_tokens_details: OutputTokenDetails,
/// The total number of tokens used.
pub total_tokens: u32,
}

Copilot uses AI. Check for mistakes.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum Instructions {
Expand Down