Skip to content

Conversation

@niw
Copy link

@niw niw commented Dec 4, 2025

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

**Problem**

Since openai 1.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`.
@niw niw requested a review from a team as a code owner December 4, 2025 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant