Skip to content

Make sure caller can get an OpenAI client from get_openai_client() with a custom http_client#45028

Merged
dargilco merged 4 commits intofeature/azure-ai-projects/2.0.0b4from
dargilco/fix-get-openai-client
Feb 5, 2026
Merged

Make sure caller can get an OpenAI client from get_openai_client() with a custom http_client#45028
dargilco merged 4 commits intofeature/azure-ai-projects/2.0.0b4from
dargilco/fix-get-openai-client

Conversation

@dargilco
Copy link
Member

@dargilco dargilco commented Feb 5, 2026

Current implementation: The method get_openai_client() implemented console logging of OpenAI client network calls, by using a custom httpx.Client (from the httpx package). This happens if you define the environment variable AZURE_AI_PROJECTS_CONSOLE_LOGGING=true. This http client is passed into the constructor of the OpenAI client by setting the input argument http_client. If the environment variable is not defined (or does not have a value "true") we pass in http_client=None to the OpenAI client constructor.

The problem with this implementation: It prevents the caller from defining their how http_client and passing it into the get_openai_client() method, with the intention that that keyword argument will be passed into the OpenAI client constructor (as the doc string suggests).

The fix is to make sure that if the logging environment variable is not defined, which is the common case, and the caller supplied their own "http_client", we pass it as-is to the constructor of the OpenAI client.

Add a test for this for the sync and async versions.

Thank you Sashank for calling out this bug!

@dargilco dargilco self-assigned this Feb 5, 2026
@dargilco dargilco changed the title Make sure caller can pass their own http_client into get_openai_client() Make sure caller can get an OpenAI client from get_openai_client() with a custom http_client Feb 5, 2026
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-ai-projects

@dargilco dargilco merged commit c69cb98 into feature/azure-ai-projects/2.0.0b4 Feb 5, 2026
18 of 21 checks passed
@dargilco dargilco deleted the dargilco/fix-get-openai-client branch February 5, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants