dd-trace-py
dd-trace-py copied to clipboard
fix(llmobs): api_key can be Callable
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