Unable to Retrieve total_tokens in ai_assistant_api

Created on 4 March 2025, 2 months ago

Since integrating ai_assistant_api, it is no longer possible to retrieve total_tokens from the OpenAI response.
Previously, when using ChatOutput::getRawOutput(), it was possible to access usage.total_tokens, but this is no longer the case with this module. OpenAI Model Used: [GPT-4 / GPT-3.5]

Steps to reproduce
1️⃣ Execute an OpenAI request via ai_assistant_api.
2️⃣ Try to extract total_tokens using:
$rawOutput = $response->getRawOutput();
$usedTokens = (int) ($rawOutput['usage']['total_tokens'] ?? 100);

Expected Result:
total_tokens should be available in $rawOutput['usage']['total_tokens'].

Actual Result:
total_tokens is always NULL or missing from the response;

Additional Notes / Debugging Attempts:
✅ We have confirmed that total_tokens is not present in:
$response->getRawOutput()
$response->getNormalized()
✅ We suspect the issue might be related to how ChatOutput is constructed inside AiAssistantApiRunner.
✅ The next step would be to verify whether total_tokens is actually returned by OpenAI before being processed by ai_assistant_api.

Question / Help Needed:
🔹 Is total_tokens intentionally omitted by ai_assistant_api?
🔹 If not, where in the processing chain could it be getting lost?
🔹 What would be the best way to retrieve it with this module?

Any insights or guidance from maintainers or users who have faced a similar issue would be greatly appreciated! 🚀

💬 Support request
Status

Active

Version

1.0

Component

AI Assistants API

Created by

🇵🇫French Polynesia laurentb Tahiti

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024