Skip to content

Azure OpenAI Cognitive Services endpoint: Responses API does not append ?api-version=, cannot use gpt-5.x-codex models #13999

Description

@kpasechnikov

Description

Summary:

When using OpenCode with Azure OpenAI Cognitive Services endpoints (i.e. https://<resource>.cognitiveservices.azure.com/openai), the Responses API (/responses) requests are missing the required ?api-version=... query parameter. This causes all requests to /openai/responses to return 404, even though the same endpoint works with tools like curl.

Impact:

  • Cannot use models that require the Responses API (e.g. gpt-5.2-codex) on Azure Cognitive Services endpoints.
  • Azure returns 404 Resource not found when ?api-version= is missing from the request URL.
  • The same request succeeds via curl when ?api-version=2025-04-01-preview is included manually.

Working curl example:

curl -X POST "https://<resource>.cognitiveservices.azure.com/openai/responses?api-version=2025-04-01-preview" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $AZURE_API_KEY" \
    -d '{
        "messages": [{"role": "user", "content": "hello"}],
        "max_completion_tokens": 16384,
        "model": "gpt-5.2-codex"
    }'

Config attempts and results:

Attempt 1: Standard @ai-sdk/azure with resourceName

{
  "provider": {
    "azure": {
      "npm": "@ai-sdk/azure",
      "options": {
        "apiKey": "<REDACTED>",
        "resourceName": "<REDACTED>",
        "apiVersion": "2025-04-01-preview"
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "GPT 5.2 Codex",
          "provider": { "npm": "@ai-sdk/azure" }
        }
      }
    }
  }
}

Result: SDK constructs URL with .openai.azure.com hostname (wrong — Cognitive Services uses .cognitiveservices.azure.com), and hits /v1/chat/completions instead of /responses. Error: The chatCompletion operation does not work with the specified model, gpt-5.2-codex.

Attempt 2: @ai-sdk/azure with baseURL override

{
  "provider": {
    "azure": {
      "npm": "@ai-sdk/azure",
      "options": {
        "apiKey": "<REDACTED>",
        "baseURL": "https://<resource>.cognitiveservices.azure.com/openai",
        "apiVersion": "2025-04-01-preview"
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "GPT 5.2 Codex",
          "provider": { "npm": "@ai-sdk/azure" }
        }
      }
    }
  }
}

Result: URL hits /openai/responses (correct path) but ?api-version= query parameter is dropped. Error: 404 Resource not found.

Attempt 3: @ai-sdk/openai with api URL including query param

{
  "provider": {
    "azure": {
      "api": "https://<resource>.cognitiveservices.azure.com/openai?api-version=2025-04-01-preview",
      "npm": "@ai-sdk/openai",
      "options": {
        "apiKey": "<REDACTED>",
        "headers": {
          "api-key": "<REDACTED>"
        }
      },
      "models": {
        "gpt-5.2-codex": { "name": "GPT 5.2 Codex" }
      }
    }
  }
}

Result: SDK appends /responses after the query string, producing a malformed URL: https://<resource>.cognitiveservices.azure.com/openai/responses?api-version=2025-04-01-preview/responses. Error: 404.

Attempt 4: @ai-sdk/openai with clean api URL (no query param)

{
  "provider": {
    "openai": {
      "api": "https://<resource>.cognitiveservices.azure.com/openai",
      "npm": "@ai-sdk/openai",
      "options": {
        "apiKey": "<REDACTED>",
        "headers": {
          "api-key": "<REDACTED>"
        }
      },
      "models": {
        "gpt-5.2-codex": { "name": "GPT 5.2 Codex" }
      }
    }
  }
}

Result: URL hits /openai/responses (correct path) but ?api-version= is missing. Error: 404 Resource not found.

Attempt 5: Custom provider ID to bypass Azure custom loader

{
  "provider": {
    "azure-responses": {
      "name": "Azure OpenAI",
      "npm": "@ai-sdk/azure",
      "options": {
        "apiKey": "<REDACTED>",
        "baseURL": "https://<resource>.cognitiveservices.azure.com/openai",
        "apiVersion": "2025-04-01-preview"
      },
      "models": {
        "gpt-5.2-codex": { "name": "GPT 5.2 Codex" }
      }
    }
  }
}

Result: Same as Attempt 2 — ?api-version= is dropped when baseURL is provided. Error: 404 Resource not found.


Root cause analysis:

The issue is an architectural mismatch across three layers:

  1. @ai-sdk/azure URL construction: When using resourceName, the SDK hardcodes the hostname as {resourceName}.openai.azure.com. Cognitive Services endpoints use {resourceName}.cognitiveservices.azure.com instead. When baseURL is provided to bypass this, the SDK stops appending ?api-version= to requests — this is a known limitation.

  2. OpenCode's Azure custom loader (provider.ts L178-191): Correctly calls sdk.responses(modelID) by default, but has no mechanism to handle the Cognitive Services endpoint variant.

  3. OpenCode's getSDK (provider.ts L1041-1117): Passes config options through to createAzure(), but there's no way for users to configure both a custom base hostname AND retain the ?api-version= query parameter behavior.

Note: The bundled @ai-sdk/azure version (2.0.91) is not obsolete — it does support the Responses API. The issue is specifically about how it constructs URLs when baseURL is overridden.

Suggested fix:

  • Allow OpenCode's Azure provider to accept a full custom base URL while preserving ?api-version= injection (e.g. via a custom fetch wrapper, or by patching URL construction in the Azure loader).
  • Alternatively, add explicit support for the cognitiveservices.azure.com hostname pattern in the azure-cognitive-services custom loader.

References:

Plugins

None

OpenCode version

Latest stable (2026-02-17)

Steps to reproduce

  1. Deploy a model requiring the Responses API (e.g. gpt-5.2-codex) on an Azure Cognitive Services resource
  2. Configure opencode.json with provider azure, pointing at https://<resource>.cognitiveservices.azure.com/openai
  3. Set "model": "azure/gpt-5.2-codex" and provide your API key
  4. Launch opencode and send any message
  5. Observe error: 404 Resource not found — the request URL is /openai/responses without ?api-version=
  6. Verify the same request works via curl with ?api-version=2025-04-01-preview appended

Screenshot and/or share link

Error from OpenCode logs:

AI_APICallError: Resource not found
url: "https://<resource>.cognitiveservices.azure.com/openai/responses"
statusCode: 404
responseBody: {"error":{"code":"404","message": "Resource not found"}}

Expected URL (works via curl):

https://<resource>.cognitiveservices.azure.com/openai/responses?api-version=2025-04-01-preview

Operating System

Windows 11

Terminal

Windows Terminal

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions