Repository navigation
Azure OpenAi generated URL is wrong? (/v1/) added in between #1508
Copy link
Copy link
Closed as not planned
Description
It seems that the generated URL for the Azure OpenAI service is adding a /v1/ in between. If I'm wrong and it has something todo with my config, I'm sorry then please point me to the problem and close the issue.
using opencode version 0.3.110
my custom provider config:
{
"$schema": "https://opencode.ai/config.json",
"model": "Foundry/o3-mini",
"provider": {
"Foundry": {
"npm": "@ai-sdk/azure",
"name": "Foundry",
"options": {
"baseURL": "https://<removed>.openai.azure.com/openai/deployments/o3-mini",
"apiKey": "{env:AZURE_KEY_O3MINI}",
"apiVersion": "2025-01-01-preview"
},
"models": {
"o3-mini": {
"name": "o3-mini"
}
}
}
}
}
Accual used URL
Expected URL (as by Azure OpenAi
the error message where you can see that the used url was wrong
{
"error": {
"name": "AI_APICallError",
"url": "https://<removed>.openai.azure.com/openai/deployments/o3-mini/v1/chat/completions?api-version=2025-01-01-preview",
"requestBodyValues": {
"model": "o3-mini",
"max_completion_tokens": 32000,
"messages": [
{
"role": "developer",
"content": "<removed>"
},
{
"role": "developer",
"content": "<removed>"
},
{
"role": "user",
"content": "write bash hello world"
}
],
"tools": ["<removed>"],
"tool_choice": "auto",
"stream": true,
"stream_options": {
"include_usage": true
}
},
"statusCode": 404,
"responseHeaders": {
"apim-request-id": "3b1a9292-9501-4f88-9389-38613332b4e7",
"content-length": "56",
"content-type": "application/json",
"date": "Fri, 01 Aug 2025 12:11:05 GMT",
"strict-transport-security": "max-age=31536000; includeSubDomains; preload",
"x-content-type-options": "nosniff"
},
"responseBody": {
"error": {
"code": "404",
"message": "Resource not found"
}
},
"isRetryable": false,
"data": {
"error": {
"message": "Resource not found",
"code": "404"
}
}
}
}
Azure OpenAi curl example example
curl -X POST "https://<removed>.openai.azure.com/openai/deployments/o3-mini/chat/completions?api-version=2025-01-01-preview \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AZURE_API_KEY" \
-d '{
"messages": [
{
"role": "user",
"content": "I am going to Paris, what should I see?"
}
],
"max_completion_tokens": 100000,
"model": "o3-mini"
}'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
mhumphriestx commentedon Aug 8, 2025
To me, it looks like ai-sdk updated to the more current Azure API which includes /v1/ in the path:
vercel/ai#7372
For me, in my opencode/config.json, I changed my "baseURL" from:
"https:<url>/openai/deployments"to:
"https:<url>/openai/"I also deleted the apiVersion as it seemed to not be supported now.
alexhupfer commentedon Aug 12, 2025
No every Azure OpenAI endpoint supports the /v1 - this needs to be optional
meanderix commentedon Aug 12, 2025
ISTM that Azure does not provide great documentation of the new API when you're adding a new deployment.
AFAICT it is mostly possible to exchange the following (i.e. the "old style"):
with
(The model name should be provided in the json body.)
enlilz commentedon Aug 13, 2025
I tried to create a new model but at the creation process i did not get any opportunity to select the API type also not when i try to edit them after the creation.
after some Microsoft doc digging i found this.
Azure OpenAI in Azure AI Foundry Models v1 REST API reference
Azure OpenAI in Azure AI Foundry Models REST API v1 preview reference
so i guess, "some" party have already adopted the v1 API but i guess mostly there eval and grading endpoints
tbrandenburg commentedon Aug 15, 2025
+1 for making it optional.
In my company we also have endpoints like:
and it gets generated by opencode like:
I had to add LiteLLM in between with such
opencode.json:Can I help providing a fix?
rekram1-node commentedon Aug 15, 2025
@tbrandenburg I think a fix would be welcome, go ahead
tbrandenburg commentedon Aug 16, 2025
Hej guys,
I found this setting in Vercel's AI SDK:
https://github.com/vercel/ai/blob/main/content/providers/01-ai-sdk-providers/04-azure.mdx?plain=1#L89
I would probably go down this way.
Other ideas?
enlilz commentedon Aug 16, 2025
my thoughts:
if that could be configurable via the provider configuration in opencode that might be nice, since we will not know when Microsoft decides to switch complete to the new API or old deployments might keep using the old style even after.
alexhupfer commentedon Aug 19, 2025
This seems to work for chat completions, but not the responses API
tbrandenburg commentedon Aug 19, 2025
Stupid question (currently travelling just with my mobile): Is opencode using the Azure responses API?
rekram1-node commentedon Aug 19, 2025
@tbrandenburg yes:
https://github.com/sst/opencode/blob/40bdbf92a368952812954f512b8ded56fc5cb1dd/packages/opencode/src/provider/provider.ts#L48-L56
tbrandenburg commentedon Aug 20, 2025
Hej guys,
diving deeper I realized that the JSON-options are actually passed to the provider creation method. So I tried running with:
And it worked! 🎉
Out of the logs I could see that the URL used is:
https://mycompany.azure-api.net/openai/deployments/gpt-5/chat/completions?api-version=2024-12-01-previewI also think that Responses API is supported looking at https://github.com/vercel/ai/blob/main/packages/azure/src/azure-openai-provider.ts#L153.
Can somebody else test as well?
alexhupfer commentedon Aug 20, 2025
we're not using deployments for the responses API just https://subdomain.openai.azure.com/openai/responses?api-version=2025-03-01-preview - so this does not work either.
1 remaining item
tbrandenburg commentedon Aug 20, 2025
Which results into a contribution to Vercel's SDK and how it is building the URL, right?
enlilz commentedon Aug 24, 2025
using the config flag, changes the url back from v1 to deployments
"useDeploymentBasedUrls": true,but now i can see that the url that is generated is a "responses" not chat completion
so the newly generated URL is
but should be
is there another flag i can set in the config to make it aware that the model is chat completion not responses?
not sure if that is the correct code part
azure: async () => { return { autoload: false, async getModel(sdk: any, modelID: string) { return sdk.responses(modelID) }, options: {}, } },and if i understand the VercelAI code correctly there should also be the option to load
completion(deploymentId: string): LanguageModelV2;instead of
responses(deploymentId: string): LanguageModelV2;so that this should be like that?
azure: async () => { return { autoload: false, async getModel(sdk: any, modelID: string) { return sdk.completion(modelID) }, options: {}, } },now if we should have something in the config file that lets us decide if we want/need completion or responses for the model, that might do the trick?
apology if i hallucinate a solution here that might not be as easy as i think
enlilz commentedon Sep 8, 2025
i gave it a try for a fix, feedback would be appreciated. not sure if i got the "correct" solution for the issue, but at least it worked in my tests that the URL is generated correctly and opencode (in the dev Version) was able to use my Azure OpenAi models now.
provider.ts update for issue anomalyco#1508
this might be a possible solution for the issue anomalyco#1508
enlilz commentedon Oct 8, 2025
just wanted to see if there is any update? would my pr be an acceptable solution for the issue ?
rekram1-node commentedon Oct 8, 2025
I will take a look at it when I get a chance today or tmr, if I don't have feedback for you soon just @ me and i will get to it
currently wrapping up work at my day job but i will have a lot more bandwidth to be able to review and help very soon
enlilz commentedon Oct 13, 2025
added a PR for updating the docs with additional information on azure provider configuration - including the changes made in the PR to this issue.
brokenbyte commentedon Jan 7, 2026
After spending a couple days poking at this, I managed to get the
/deployments/%Model%/chat/completionsAPI working as described in this comment: #1508 (comment), but due to my company's API deployment not using/v1/responses(just/responses) I was failing to get any of the non-deployment endpoints to work.Based on the table from this PR updating the documentation, it looks like the only two options directly supported for endpoints are
/v1/...or/deployments/..., which tracks with what seems to be the only two options@ai-sdk/azurewill give you fromcreateAzure.urlshown here.I eventually managed to solve this with a short custom opencode plugin that just patches the URL before each request on the fly, which seems to work pretty well from my short testing so far. A couple of caveats with this approach:
azureprovider, I haven't managed to create a custommyproviderthat achieves the same resultsgpt-5-codexdidn't seem to work, butgpt-5.1-codex,gpt-5.1-codex-mini,gpt-5.1, andgpt-5seem to work fine (these are the only ones I have access to on our instance so that's all I could test)~/.config/opencode/auth.jsonfile:authconfig hereproviderIDfield fromauth.jsonhereThe plugin to patch the urls is just this file placed at
~/.config/opencode/plugin/patch_endpoint.ts:(I know basically no typescript/javascript, so bear with me here and make suggestions if you have them)
~/.local/share/opencode/auth.json:{ "azure": { "type": "api", "key": "file:~/.config/opencode/my_custom_ai.key" }~/.config/opencode/opencode.jsonc:{ "$schema": "https://opencode.ai/config.json", "enabled_providers": ["azure"], "share": "disabled", "autoupdate": "notify", "provider": { "azure": { "name": "MyCustomAI", "whitelist": ["gpt-5.1-codex", "gpt-5", "gpt-5.1-codex-mini", "gpt-5.1"], // These are the models that seemed to work for me, YMMV "options": { "baseURL": "https://api.my_custom_ai.com/openai", "useDeploymentBasedUrls": false, "apiVersion": "2025-03-01-preview", "headers": { "api-key": "{file:~/.config/opencode/my_custom_ai.key}" } } }, } }then after making any request with one of the models I get this in my log file:
Hope this is helpful to anyone else trying this.
loganankarbergmdu commentedon Feb 12, 2026
I'm curious if we've made any progress on this, I'm also getting the same issue. on the responses api, need to consume with simply /openai/responses?api-version=2025-04-01-preview
no v1.
bakaburg1 commentedon Apr 9, 2026
I confirmed opencode’s azure-cognitive-services provider is building the wrong host. The bundled code hardcodes https://${AZURE_COGNITIVE_SERVICES_RESOURCE_NAME}.cognitiveservices.azure.com/openai, which makes it try .../openai/v1/responses.
My working endpoint is:
https://.api.cognitive.microsoft.com/openai/responses?api-version=2025-04-01-preview
So the bug is twofold:
Suggested fix:
feat(den): let users name their LLM providers explicitly (anomalyco#1508
github-actions commentedon Jul 3, 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.