Skip to content

Conversation

@Chesars
Copy link

@ChesarsChesars commented Dec 4, 2025

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Add support for Azure OpenAI v1/preview/latest API versions.

Currently, when using api_version="v1", "preview", or "latest", the SDK generates incorrect URLs:

fromopenaiimportAzureOpenAIclient=AzureOpenAI( api_version="preview", # or "v1" or "latest"azure_endpoint="https://example-endpoint.openai.azure.com", ) # Both work with the fix:completion=client.chat.completions.create( model="deployment-name", messages=[{"role": "user", "content": "Hello!"}], ) response=client.responses.create( model="deployment-name", input="Hello!", ) print(response) print(completion)
URL Generated
❌ Before/openai/deployments/gpt-4o/chat/completions?api-version=preview
✅ After/openai/v1/chat/completions?api-version=preview

The new Azure OpenAI v1 API uses /openai/v1/ path and the model is passed in the request body, not in the URL.

Non breaking changes - the values "v1", "preview", and "latest" previously resulted in 404 errors, so no existing working code is affected.

Changes:

  • Add _is_v1_api flag to BaseAzureClient
  • Skip adding /deployments/{model}/ path for v1 API in _build_request
  • Use /openai/v1/ base URL for v1/preview/latest api_version values
  • Add comprehensive tests (23 new test cases)

Note: The ?api-version= query parameter is still included for compatibility, as shown in the
https://learn.microsoft.com/en-us/azure/ai-foundry/openai/reference-preview-latest.

Additional context & links

When using api_version="v1", "preview", or "latest", the Azure OpenAI client now correctly constructs URLs using the new /openai/v1/ path format instead of the legacy /openai/deployments/{model}/ format. The new Azure OpenAI v1 API uses a different URL structure: - Old: /openai/deployments/{model}/chat/completions?api-version=2024-10-21 - New: /openai/v1/chat/completions?api-version=v1 Changes: - Add _is_v1_api flag to BaseAzureClient - Skip adding /deployments/{model}/ path for v1 API in _build_request - Use /openai/v1/ base URL for v1/preview/latest api_version values - Add comprehensive tests for v1 API support
@ChesarsChesars requested a review from a team as a code ownerDecember 4, 2025 20:16
Copy link

@chatgpt-codex-connectorchatgpt-codex-connectorbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

ifself._azure_deploymentandself._azure_endpointandurlnotin_deployments_endpoints:
merge_url=httpx.URL(url)
ifmerge_url.is_relative_url:
merge_raw_path= (
self._azure_endpoint.raw_path.rstrip(b"/") +b"/openai/"+merge_url.raw_path.lstrip(b"/")

P1 Badge Keep v1 URLs when azure_deployment is supplied

For v1/preview/latest clients that still pass azure_deployment, _prepare_url rewrites any non-deployment endpoint to azure_endpoint/openai/<path> (lines 79-83) which drops the /v1 prefix set in the base URL. A call like AzureOpenAI(api_version="v1", azure_deployment="foo", ...).responses.create(...) will therefore hit /openai/responses?api-version=v1 and 404 instead of /openai/v1/responses. Because the constructor continues to store azure_deployment, this regression triggers whenever users reuse their old deployment parameter with the new v1 API.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

When azure_deployment is passed with v1/preview/latest API, the _prepare_url method was rewriting URLs and dropping the /v1/ prefix, causing 404 errors for non-deployment endpoints like /responses. Now _prepare_url skips URL rewriting entirely for v1 API since the base_url already contains /openai/v1/.
Sign up for freeto 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.

AzureOpenAi is unable to process chat.completions when the API version is set to preview.

2 participants

@Chesars@kmk142789