Skip to content

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

@anotherRedbeard

Description

@anotherRedbeard
  • 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:
pip install azure-ai-projects==2.0.0b2
  1. Create an AIProjectClient and call get_openai_client with api_version:
from azure.identity import AzureCliCredential
from azure.ai.projects import AIProjectClient

credential = AzureCliCredential(tenant_id="<your-tenant-id>")
client = AIProjectClient(
    endpoint="https://<your-foundry-resource>.services.ai.azure.com/api/projects/<project-name>",
    credential=credential
)

# This fails with TypeError
aoai_client = client.get_openai_client(api_version="2024-10-21")
  1. Observe the error:
TypeError: OpenAI.__init__() got an unexpected keyword argument 'api_version'

Expected behavior
According to the official API documentation, the method should return xref:openai.AzureOpenAI 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 (version 2.0.0b2):

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:

======================================================================
✅ 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

Metadata

Metadata

Assignees

Labels

AI ProjectsService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions