Repository navigation
Description
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 foundwhen?api-version=is missing from the request URL. - The same request succeeds via
curlwhen?api-version=2025-04-01-previewis 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:
-
@ai-sdk/azureURL construction: When usingresourceName, the SDK hardcodes the hostname as{resourceName}.openai.azure.com. Cognitive Services endpoints use{resourceName}.cognitiveservices.azure.cominstead. WhenbaseURLis provided to bypass this, the SDK stops appending?api-version=to requests — this is a known limitation. -
OpenCode's Azure custom loader (
provider.tsL178-191): Correctly callssdk.responses(modelID)by default, but has no mechanism to handle the Cognitive Services endpoint variant. -
OpenCode's
getSDK(provider.tsL1041-1117): Passes config options through tocreateAzure(), 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.comhostname pattern in theazure-cognitive-servicescustom loader.
References:
- Azure OpenAI Responses API docs
- Vercel AI SDK: Add baseURL and apiVersion to Azure provider (issue #2312)
- Vercel AI SDK: Azure calling wrong URL path (issue #4797)
Plugins
None
OpenCode version
Latest stable (2026-02-17)
Steps to reproduce
- Deploy a model requiring the Responses API (e.g.
gpt-5.2-codex) on an Azure Cognitive Services resource - Configure
opencode.jsonwith providerazure, pointing athttps://<resource>.cognitiveservices.azure.com/openai - Set
"model": "azure/gpt-5.2-codex"and provide your API key - Launch opencode and send any message
- Observe error:
404 Resource not found— the request URL is/openai/responseswithout?api-version= - Verify the same request works via curl with
?api-version=2025-04-01-previewappended
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
Activity
github-actions commentedon Feb 17, 2026
This issue might be related to existing issues. Please check:
These issues share similar root causes around Azure endpoint URL construction and query parameter handling.
mlanza commentedon Mar 6, 2026
I too encountered a terrible amount of friction, trying every conceivable combination of keys and values making incremental progress but eventually getting stuck on a series of "Resource not found" errors. This was all after registering the Azure Cognitive Services (A.K.A. AI Foundry) provider API key, which now appears in my
auth.json. I also set theAZURE_OPENAI_API_KEYenv var.In Foundry this was the endpoint for the one model:
https://XXXX.cognitiveservices.azure.com/openai/deployments/XXX_gpt-4.1-mini/chat/completions?api-version=2025-01-01-preview
I initially tried using the Desktop and CLI to update things, but eventually ended up poking at the
opencode.jsondirectly. This is the section which ultimately worked, with some redaction:This was several hours in the making, but I now have a working connection to the model in both the Desktop and CLI.
tmeckel commentedon Mar 6, 2026
@mlanza #14494 (comment)
Igor1788 commentedon Apr 25, 2026
Additional findings + workaround for Claude models via Azure AI Foundry
I ran into the same issue while trying to use
gpt-5.3-codexandclaude-opus-4-5deployed on Azure AI Foundry.Confirmed behavior
All attempts to use the
azureprovider withcognitiveservices.azure.comendpoint failed exactly as described — the?api-version=parameter is dropped and the Responses API returns errors. This was confirmed via curl comparison:Additional finding:
--pureflag as a diagnostic toolRunning OpenCode with
--pure(which disables the@opencode-ai/plugin) changes the error fromPermissionDeniedto the actual Azure API error, making it much easier to diagnose. Without--pure, the plugin seems to interfere with custom provider configurations.Workaround for Claude models via Azure AI Foundry
Claude models deployed on Azure AI Foundry use a different endpoint (
services.ai.azure.com) and the Anthropic native protocol — not the Azure OpenAI Responses API. This means they work correctly using theanthropicprovider with a custombaseURL:{ "$schema": "https://opencode.ai/config.json", "provider": { "anthropic": { "options": { "apiKey": "YOUR_AZURE_KEY", "baseURL": "https://<resource>.services.ai.azure.com/anthropic/v1" } } }, "model": "anthropic/claude-opus-4-5" }Confirmed working via curl:
This workaround does not solve the
gpt-5.x-codexissue since those models require the Responses API, but it may help others using Claude on AI Foundry while the fix is pending.Environment
cognitiveservices.azure.comandservices.ai.azure.comendpointsgpt-5.3-codex,claude-opus-4-5,gpt-4orekram1-node commentedon Apr 26, 2026
our azure support is so so bad and it's unacceptable doing a pass this week.
tmeckel commentedon Apr 26, 2026
@rekram1-node since I'm using my own Azure Foundry provider for OpenCode I never had any issues. Although I must admit that I don't use Anthropic via Azure Foundry because it's simply too expensive. So perhaps I'd face the same issue with Anthropic.
alex-pathcourse commentedon May 11, 2026
rekram1-node commentedon May 11, 2026
@alex-pathcourse stop spamming our issues or u will be banned
rickywck commentedon Jun 7, 2026
I followed this and I am using gpt-5.4, no luck, spent hours with opencode and Azure still can't make it work ... anything I could miss? my computer can definitely connect to the Foundry endpoint as the tested program suggested by Foundry can connect.
github-actions commentedon Aug 7, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.
Jandev commentedon Aug 7, 2026
I also ran into this issue with my 5.3-codex model hosted on AI Foundry.
I could copy-paste the comment with proposed fix from my coding agent over here, like the people above did already, but it wouldn't add much to the conversation.
They key point is the
?api-version=...needs to be appended to the URL when invoking the responses api.tmeckel commentedon Aug 7, 2026
@Jandev because Azure Foundry has special requirements we created our own Azure Foundry AI provider. https://github.com/ophiosdev/azure-foundry-provider
It's easy to use in OpenCode. We always use it our OpenCode container.
https://github.com/ophiosdev/opencode-cli-container
Jandev commentedon Aug 7, 2026
Wow, thanks for that!
Added this provider and it's working like a charm now.
For future reference/others, this is what I did.
First, extracted the (useful) code from the docker file of the mentioned repository.
Second, in my
opencode.jsonfile added this provider:tmeckel commentedon Aug 7, 2026
@Jandev when you look at the documentation (README.md) of the provider you can mix
reponsesandchat-completionmodels with ONE single provider definition. Aside the issues that Azure support was ever not ideal this was another fact that made us to create that provider. Before that you had to define TWO different providers in OpenCode. Even named the same (Display Name) and thus in the model selection in OpenCode this got merged it was always tedious.Example: https://github.com/ophiosdev/azure-foundry-provider#14-per-model-override-under-provider-options
Jandev commentedon Aug 7, 2026
I read that, indeed. A very nice addition, seeing some models don't work well with responses api or the completions api.
tmeckel commentedon Aug 7, 2026
@Jandev and you can use Bearer authentication instead of API-Key authentication. Typically you wouldn't provide models via Azure Foundry in a company using API-Key authentication.
https://github.com/ophiosdev/azure-foundry-provider#24-static-bearer-token
https://github.com/ophiosdev/azure-foundry-provider#25-token-provider-callback
Because we are utilizing
@azure/identitythe provider seamlessly integrates with the Entra ID and Azure Foundry authentication flow.rekram1-node commentedon Aug 7, 2026
Can someone give me a tldr of what sucks for azure rn? We wanna improve the UX but I dont use azure too much myself and it seems like every company has weird restrictions, some people have deployment urls, some cant use responses apis, some use responses api and it is completely fine out of the box, etc
Jandev commentedon Aug 10, 2026
I think I can come up with a list of issues/things that don't work.
Probably won't be today, but I'll try to get a list this week.
rekram1-node commentedon Aug 17, 2026
Just seeing this, thanks!