mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix(ui): read reasoning tokens from Responses API output_tokens_details (#37952)
This commit is contained in:
parent
ece03ceafe
commit
27ca05a707
2 changed files with 16 additions and 2 deletions
|
|
@ -400,4 +400,16 @@ describe("responses_api prompt cache usage", () => {
|
|||
expect(usageData).not.toHaveProperty("cacheCreationTokens");
|
||||
expect(usageData.promptTokens).toBe(5000);
|
||||
});
|
||||
|
||||
it("surfaces reasoning tokens from Responses-shape output_tokens_details", async () => {
|
||||
await expect(captureUsage({ output_tokens_details: { reasoning_tokens: 42 } })).resolves.toMatchObject({
|
||||
reasoningTokens: 42,
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to completion_tokens_details reasoning tokens when output_tokens_details is absent", async () => {
|
||||
await expect(captureUsage({ completion_tokens_details: { reasoning_tokens: 17 } })).resolves.toMatchObject({
|
||||
reasoningTokens: 17,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -295,8 +295,10 @@ export async function makeOpenAIResponsesRequest(
|
|||
};
|
||||
|
||||
// Add reasoning tokens if available
|
||||
if (usage.completion_tokens_details?.reasoning_tokens) {
|
||||
usageData.reasoningTokens = usage.completion_tokens_details.reasoning_tokens;
|
||||
const reasoningTokens =
|
||||
usage.output_tokens_details?.reasoning_tokens ?? usage.completion_tokens_details?.reasoning_tokens;
|
||||
if (reasoningTokens) {
|
||||
usageData.reasoningTokens = reasoningTokens;
|
||||
}
|
||||
|
||||
if (usage.cost !== undefined && usage.cost !== null) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue