Skip to content

TypeError: 'InputTokensDetails' object is not subscriptable when using Langtrace SDK with OpenAI Agents #511

@jdurago

Description

@jdurago

I’m encountering a TypeError when using the Langtrace SDK in combination with OpenAI Agents. The error occurs during response tracing, seemingly due to InputTokensDetails being treated as a dictionary instead of an object.

Here’s the relevant portion of the stack trace:

TypeError: 'InputTokensDetails' object is not subscriptable

File "langtrace_python_sdk/instrumentation/openai/patch.py", line 741, in _set_openai_agentic_response_attributes
"cached_tokens": response.usage.input_tokens_details["cached_tokens"],
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^

This suggests that input_tokens_details is an object, not a dictionary, and should likely be accessed via attributes, not keys.

I forked the langtrace sdk and patched up that line locally and it seemed to work.

Setup
• Python 3.12
• langtrace-python-sdk v3.8.9
• openai-agents v0.0.7
• exporting traces to locally hosted jaeger endpoint

Let me know if you need any further details or a minimal repro!

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