Skip to content

Commit 6858399

Browse files
authored
Add parsing for detailed token usage information (#282)
This update adds functionality to parse the detailed token usage data returned by the OpenAI API. Reference: https://platform.openai.com/docs/api-reference/chat/object#chat/object-usage
1 parent d080708 commit 6858399

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

async-openai/src/types/chat.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@ pub struct CompletionUsage {
9393
pub completion_tokens: u32,
9494
/// Total number of tokens used in the request (prompt + completion).
9595
pub total_tokens: u32,
96+
/// Breakdown of tokens used in the prompt.
97+
pub prompt_tokens_details: PromptTokenDetails,
98+
/// Breakdown of tokens used in a completion.
99+
pub completion_tokens_details: CompletionTokenDetails,
100+
}
101+
102+
/// Breakdown of tokens used in a completion.
103+
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
104+
pub struct PromptTokenDetails {
105+
/// Audio input tokens present in the prompt.
106+
#[serde(default)]
107+
pub audio_tokens: u32,
108+
/// Cached tokens present in the prompt.
109+
#[serde(default)]
110+
pub cached_tokens: u32,
111+
}
112+
113+
/// Breakdown of tokens used in a completion.
114+
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
115+
pub struct CompletionTokenDetails {
116+
/// Audio input tokens generated by the model.
117+
#[serde(default)]
118+
audio_tokens: u32,
119+
/// Tokens generated by the model for reasoning.
120+
#[serde(default)]
121+
reasoning_tokens: u32,
96122
}
97123

98124
#[derive(Debug, Serialize, Deserialize, Default, Clone, Builder, PartialEq)]

0 commit comments

Comments
 (0)