You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Python SDK Gradient spans record no prompt-cache tokens and the cost ignores them #2005
Gradient chat spans never record prompt-cache token counts, and the cost calculation ignores them. instrumentation/gradient/utils.py reads only prompt_tokens and completion_tokens (process_chat_response and process_chunk), calls get_chat_model_cost(...) without any cache arguments, and never sets gen_ai.usage.cache_read_input_tokens or gen_ai.usage.cache_creation_input_tokens.
The sibling instrumentation/pydo/utils.py instruments the same DigitalOcean inference endpoint (both use the DigitalOcean system value) and handles all three: it reads cache_read_input_tokens and prompt_tokens_details.cached_tokens for streaming and non-streaming responses, passes cache_read_tokens, cache_creation_tokens and prompt_tokens_include_cache=True to get_chat_model_cost, and sets both span attributes. get_chat_model_cost already supports those arguments.
Steps to reproduce
Feed gradient.utils.process_chunk a final streaming chunk whose usage carries prompt_tokens_details.cached_tokens. The scope has no cache count afterwards, and the span has no cache attribute.
Expected behavior
Cache-read and cache-creation counts on the span and in the cost, as pydo does.
Environment
main at the time of filing.
Additional context
Open PR #1807 changes Gradient span lifecycle only and does not touch this. I can send the fix.
Activity