Skip to content

feat(openai-completions): add Azure OpenAI support#2525

Closed
pyrotank41 wants to merge 1 commit intoearendil-works:mainfrom
pyrotank41:feat/azure-openai-chat-completions
Closed

feat(openai-completions): add Azure OpenAI support#2525
pyrotank41 wants to merge 1 commit intoearendil-works:mainfrom
pyrotank41:feat/azure-openai-chat-completions

Conversation

@pyrotank41
Copy link
Copy Markdown

Summary

  • Adds Azure OpenAI support to the openai-completions provider by detecting Azure providers and using the AzureOpenAI SDK client instead of the standard OpenAI client
  • The AzureOpenAI client correctly appends the required ?api-version= query parameter and uses header-based api-key authentication
  • Without this change, Azure cognitiveservices Chat Completions endpoints return HTTP 404 because the standard OpenAI client doesn't include the api-version query parameter

Problem

When configuring openai-completions API with an Azure OpenAI provider (azure-openai), the standard OpenAI client constructs URLs like:

https://{resource}.openai.azure.com/openai/deployments/{model}/chat/completions

But Azure requires:

https://{resource}.openai.azure.com/openai/deployments/{model}/chat/completions?api-version=2025-01-01-preview

The AzureOpenAI SDK client handles this automatically via its apiVersion parameter.

Changes

  • packages/ai/src/providers/openai-completions.ts:
    • Import AzureOpenAI from the openai package (already a dependency)
    • In createClient(), detect Azure providers by model.provider === "azure-openai" or baseUrl containing .openai.azure.com
    • Use AzureOpenAI client with apiVersion from AZURE_OPENAI_API_VERSION env var (defaults to 2025-01-01-preview)
    • Set api-key header for Azure's header-based authentication

Test plan

  • Tested with Azure OpenAI model-router deployment via OpenClaw gateway
  • Verify no regression for standard OpenAI, OpenRouter, and other providers (detection is provider-specific, falls through to existing OpenAI client)

🤖 Generated with Claude Code

…ient

The openai-completions provider uses the standard OpenAI client which
doesn't append the required `api-version` query parameter for Azure
OpenAI endpoints. This causes HTTP 404 errors when using Azure
cognitiveservices Chat Completions API.

This change detects Azure OpenAI providers (by provider name or baseUrl)
and uses the AzureOpenAI SDK client instead, which correctly handles
api-version query parameters and header-based authentication.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Hi @pyrotank41, thanks for your interest in contributing!

We ask new contributors to open an issue first before submitting a PR. This helps us discuss the approach and avoid wasted effort.

Next steps:

  1. Open an issue describing what you want to change and why (keep it concise, write in your human voice, AI slop will be closed)
  2. Once a maintainer approves with lgtm, you'll be added to the approved contributors list
  3. Then you can submit your PR

This PR will be closed automatically. See https://github.com/badlogic/pi-mono/blob/main/CONTRIBUTING.md for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

possibly-openclaw-clanker User has activity on openclaw/openclaw

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants