logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Cache tokens in Logfire

Open anuar12 opened this issue 1 month ago • 3 comments

Description

We are using Pydantic AI (1.0.7) with Logfire (4.7.0) with OpenAI chat completions API. Currently can't see cached tokens in Logfire, and it would be very helpful for us to track it to make sure we can hit the cache most times, and also track costs better.

Would it be in Logfire anytime soon?

anuar12 avatar Nov 19 '25 16:11 anuar12

i think you should be able to see that info in the attributes if you're using logfire.instrument_pydantic_ai()

alexmojaki avatar Nov 19 '25 18:11 alexmojaki

We have instrument_pydantic_ai() enabled but can only see input and output tokens

Image

(I will check maybe i need to pass instrument=True to agent, but i do think it works)

anuar12 avatar Nov 19 '25 19:11 anuar12

Ah, try upgrading pydantic-ai

alexmojaki avatar Nov 19 '25 19:11 alexmojaki