dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

fix(llmobs): api_key can be Callable

Open niw opened this issue 4 weeks ago • 0 comments

Description

Problem

Since openai-python v1.106.0, api_key can be callable or awaitable callable for async client not only str.

Currently if callable api_key is passed, TypeError is raised.

TypeError: 'function' object is not subscriptable

Solution

Check if api_key is str or not and only format it if it is str.

Testing

Run following code with ddtrace-run to ensure no exception raised.

from openai import AsyncOpenAI

async def api_key() -> str:
    return "test"

openai = AsyncOpenAI(api_key=api_key)

Risks

None

Additional Notes

None

niw avatar Dec 04 '25 02:12 niw