Skip to content

Bug: Python SDK Gradient spans record no prompt-cache tokens and the cost ignores them #2005

Backlog

Description

@basil-k-aji-dev

Component

OpenLIT Python SDK (sdk/python, DigitalOcean Gradient instrumentation)

What happened?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions