Skip to content

fix: preserve URL query params for Azure OpenAI and custom endpoints#8766

Closed
pein892 wants to merge 1 commit into
NousResearch:mainfrom
pein892:fix/azure-openai-query-params
Closed

fix: preserve URL query params for Azure OpenAI and custom endpoints#8766
pein892 wants to merge 1 commit into
NousResearch:mainfrom
pein892:fix/azure-openai-query-params

Conversation

@pein892

@pein892 pein892 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Azure OpenAI endpoints require an api-version query parameter on every API request. When users configure this in base_url (e.g. https://resource.openai.azure.com/openai?api-version=2025-04-01-preview), the OpenAI Python SDK silently drops query parameters during URL construction, resulting in HTTP 404 errors.

This is the same class of issue as #4599 (Azure Anthropic), but affecting the OpenAI SDK path used by custom providers.

Root Cause

The OpenAI SDK stores base_url as an httpx.URL and joins API paths (e.g. /responses, /chat/completions) onto it. During this join, any query parameters in the original URL are discarded — Azure never receives api-version and returns 404.

Fix

Extract query parameters from base_url before passing it to the OpenAI SDK, and forward them via the SDK's default_query parameter. This ensures they are appended to every outgoing request.

Files changed:

  • run_agent.py — main agent client creation
  • agent/auxiliary_client.py — auxiliary client creation (added _extract_url_query_params() helper, applied to all custom endpoint paths)

Backward Compatibility

  • URLs without query params → default_query is None, original behavior unchanged
  • URLs with query params → params extracted and forwarded correctly
  • No hardcoded values — works for any provider requiring query parameters, not just Azure

Example Configuration

model:
  default: gpt-5.4  # Azure deployment name
  provider: custom
  base_url: https://your-resource.openai.azure.com/openai?api-version=2025-04-01-preview
  api_key: your-azure-key
  api_mode: codex_responses

Test Plan

  • Azure OpenAI endpoint with api-version in base_url returns successful responses
  • Standard OpenAI / OpenRouter / other providers without query params work unchanged
  • Custom endpoints with arbitrary query params preserve them in requests

Azure OpenAI requires an `api-version` query parameter on every request.
When users include it in the base_url (e.g. `?api-version=2025-04-01-preview`),
the OpenAI SDK silently drops it during URL construction, causing 404 errors.

Extract query params from base_url and pass them via `default_query` so the
SDK appends them to every request. This is a generic solution that works for
any custom endpoint requiring query parameters, not just Azure.

No-op for URLs without query params — fully backward compatible.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #15845 along with the other open Azure PRs as one consolidated salvage + an auto-detection feature on top (URL sniff + /models probe + Anthropic Messages fallback + context-length resolution).

Your commits were cherry-picked with authorship preserved (24b4b24d7 on main). Thanks @pein892 — this landed because of your work.

@teknium1 teknium1 closed this Apr 26, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels Apr 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Superseded by #15845 which merged — consolidates fixes from #9029, #4599, #10086, and #8766.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants