Skip to content

The content of the api_key or default_headers of an AsyncOpenAI instance can be modified surreptitiously?  #1686

@chenk-gd

Description

@chenk-gd

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Deploying a local LLM. Create an instance of AsyncOpenAI called aclient, then call aclient.chat.completions.create and return an asynchronous iterator. When processing the chunks yielded by the iterator, it appears that the api_key in the aclient instance is continuously changing.

To Reproduce

Set the N in user_id to increment from 1 for each request, i.e. 'user_id_1', 'user_id_2', ... 'user_id_30' ... When the number of concurrent requests is greater than a certain number, the id(aclient) changes every time the for loop is entered, and user_id_from_header and user_id_from_api_key change, and the member variables of different AsyncOpenAI instances (aclient) are mixed together: the same aclient instance, e.g. user_id_from_header='user_id_20', user_id_from_api_key='user_id_15',

Code snippets

user_id = <user_id_N>
aclient = AsyncOpenAI(api_key= user_id, default_headers= {'user_id': user_id})
stream =  await aclient.chat.completions.create(...)
async for chunk in stream:
     do_something(...)
     logger.info(f'user_id_from_header={aclient.default_headers['user_id']}, user_id_from_api_key={aclient.api_key}, id={id(aclient)}')

OS

CentOS

Python version

Python 3.11.4

Library version

openai v1.43.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions