OpenAI cache costs not tracked #5189
-
Hi all! I log my requests to Openai as follows:
There is currently no information regarding cached tokens in the user interface, and I have a suspicion that they are not being taken into account. I attempted to review the documentation, however, I was unable to determine how to include information regarding the composition of the price and total cost of a cache. To verify my findings, I executed the same query both in the absence of a cache (first attempt) and subsequent attempts in which approximately 70% of all tokens were cached. The price remained unchanged. Please help me, how can I enable the accounting of cached tokens when using OpenAI? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey there, @LordMoon1337! I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together! To enable the accounting of cached tokens when using OpenAI with Langfuse, you need to include the generation = langfuse.generation(
# ...
usage={
# usage
"prompt_tokens": int,
"completion_tokens": int,
"total_tokens": int,
"prompt_tokens_details": {
"cached_tokens": int,
"audio_tokens": int,
},
"completion_tokens_details": {
"reasoning_tokens": int,
},
},
# ...
) In this setup, To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
Langfuse supports tracking cached tokens in both the native OpenAI integration and server-side. Based on the screenshot, I assume you are running a self-hosted version of Langfuse that is not the latest. If that’s the case, please upgrade, as this should resolve the issue. If you are not using a self-hosted version or the upgrade does not fix it, please create an issue or bug report. This functionality is essential, and we are happy to help you resolve it.