Azure / Azure/azure-sdk-for-python

AIProjectClient.get_openai_client() returns OpenAI instead of AzureOpenAI in version 2.0.0b2

Open
#44,218 3 comments 1 reaction 1 assignee Claimed by @dargilco View on GitHub
AI Projects customer-reported needs-team-attention question Service Attention
Dominant language
Python
Stars
5.6k
Forks
3.4k
Avg merge
1d 21h
Merged PRs (30d)
193

Description

- **Package Name**: azure-ai-projects
- **Package Version**: 2.0.0b2
- **Operating System**: macOS (also affects Linux/Windows)
- **Python Version**: 3.13

**Describe the bug**

The `AIProjectClient.get_openai_client()` method returns an instance of `openai.OpenAI` instead of `openai.AzureOpenAI`, violating the documented API contract. This causes `TypeError` when using Azure-specific parameters like `api_version` or `connection_name`.

**To Reproduce**

Steps to reproduce the behavior:

1. Install the beta package:

```bash
pip install azure-ai-projects==2.0.0b2
```

2. Create an AIProjectClient and call get_openai_client with api_version:

```bash
from azure.identity import AzureCliCredential
from azure.ai.projects import AIProjectClient

credential = AzureCliCredential(tenant_id="")
client = AIProjectClient(
endpoint="https://.services.ai.azure.com/api/projects/",
credential=credential
)

# This fails with TypeError
aoai_client = client.get_openai_client(api_version="2024-10-21")
```

3. Observe the error:

```bash
TypeError: OpenAI.__init__() got an unexpected keyword argument 'api_version'
```

**Expected behavior**
According to the [official API documentation](https://learn.microsoft.com/en-us/python/api/azure-ai-projects/azure.ai.projects.aiprojectclient?view=azure-python#azure-ai-projects-aiprojectclient-get-openai-client), the method should return and accept the api_version parameter.

Microsoft Learn code samples also demonstrate this usage:

The method should:
- Return an AzureOpenAI instance (not OpenAI)
- Accept api_version parameter without error
- Work with Azure-specific configurations

**Screenshots**
Source code evidence from [azure/ai/projects/_patch.py line 259](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py#L244-L253) (version 2.0.0b2):

```bash
client = OpenAI( # ❌ Should be AzureOpenAI
azure_ad_token_provider=get_bearer_token_provider(
credential, "https://cognitiveservices.azure.com/.default"
),
organization=organization,
project=project,
base_url=base_url,
timeout=timeout,
max_retries=max_retries,
default_headers=default_headers,
default_query=default_query,
http_client=http_client,
api_version=api_version, # ❌ Not supported by OpenAI class
)
```
Another test:

```bash
======================================================================
✅ Testing azure-ai-projects 1.0.0 (WORKING)
======================================================================
✅ Client created successfully!
Type: AzureOpenAI
Module: openai.lib.azure
✅ Chat completion successful!
Response: Test passed.

======================================================================
Expected behavior: Returns AzureOpenAI, accepts api_version parameter
======================================================================

======================================================================
❌ Testing azure-ai-projects 2.0.0b2 (BROKEN)
======================================================================
❌ TypeError: OpenAI.__init__() got an unexpected keyword argument 'api_version'

Reason: OpenAI class doesn't accept 'api_version' parameter
Expected: AzureOpenAI class (which does accept api_version)

======================================================================
Bug: Returns OpenAI instead of AzureOpenAI, causing TypeError
======================================================================
```

**Additional context**
- Version 1.0.0 works correctly: Downgrading to azure-ai-projects==1.0.0 resolves the issue, as it properly returns AzureOpenAI
- Regression in beta: This appears to be a regression introduced in the 2.0.0b2 beta release
- Impact: Blocks users from using the documented API pattern for chat completions with Azure AI Foundry projects
- Workaround: Temporarily downgrade to version 1.0.0 or use `azure.ai.agents.AgentsClient` instead

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.