Struggling with connecting to Azure OpenAI deployment #313

Closed
opened 2026-02-16 17:26:10 -05:00 by yindo · 7 comments
Owner

Originally created by @FaresKi on GitHub (Jun 26, 2025).

Originally assigned to: @thdxr on GitHub.

Hi!

Super interesting tool!
However, struggling a lot with understanding which json file does what (config.json vs opencode.json), and how to pass my env vars:

➜ opencode auth login

┌  Add credential
│
◇  Select provider
│  Azure
│
◇  Enter your API key
│  ▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪
│
└  Done

I even setup the Azure env vars in the terminal, but when setting up the GPT-4o deployment (defined in AZURE_RESOURCE_NAME)

Image

I'm getting this error from Opencode CLI:

Image

And I do NOT know where to go next? what file should I create or edit? why aren't the env vars enough?
Thanks!

Originally created by @FaresKi on GitHub (Jun 26, 2025). Originally assigned to: @thdxr on GitHub. Hi! Super interesting tool! However, struggling a lot with understanding which json file does what (config.json vs opencode.json), and how to pass my env vars: ``` ➜ opencode auth login ┌ Add credential │ ◇ Select provider │ Azure │ ◇ Enter your API key │ ▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪ │ └ Done ``` I even setup the Azure env vars in the terminal, but when setting up the GPT-4o deployment (defined in AZURE_RESOURCE_NAME) ![Image](https://github.com/user-attachments/assets/8a2b78eb-274c-4b1e-ac5d-82c43ebd224b) I'm getting this error from Opencode CLI: <img width="763" alt="Image" src="https://github.com/user-attachments/assets/cb956f89-01fd-4833-ae92-dd933f565fca" /> And I do NOT know where to go next? what file should I create or edit? why aren't the env vars enough? Thanks!
yindo closed this issue 2026-02-16 17:26:11 -05:00
Author
Owner

@kfollesdal commented on GitHub (Jun 30, 2025):

@FaresKi, have you tried with AZURE_API_KEY insted of AZURE_OPENAI_API_KEY?

It works for me by setting env variables AZURE_API_KEY and AZURE_RESOURCE_NAME. Provider is looking for these variables in environment, take a look here

But opencode do not work with azure o4-mini for now #290 , try with GPT-4.1 for example.

@kfollesdal commented on GitHub (Jun 30, 2025): @FaresKi, have you tried with `AZURE_API_KEY` insted of `AZURE_OPENAI_API_KEY`? It works for me by setting env variables `AZURE_API_KEY` and `AZURE_RESOURCE_NAME`. Provider is looking for these variables in environment, take a look [here](https://github.com/sst/models.dev/blob/1f9b6fbd26b90fc23af537b6aa089ca7f2aee487/providers/azure/provider.toml#L2) But opencode do not work with azure `o4-mini` for now #290 , try with `GPT-4.1` for example.
Author
Owner

@FaresKi commented on GitHub (Jun 30, 2025):

Yeah, I read up on the ai sdk.
It works now :)
Thanks a lot!

@FaresKi commented on GitHub (Jun 30, 2025): Yeah, I read up on the ai sdk. It works now :) Thanks a lot!
Author
Owner

@ngocsanguit commented on GitHub (Jul 7, 2025):

hi @kfollesdal @FaresKi How do you handle deployment names variables?

@ngocsanguit commented on GitHub (Jul 7, 2025): hi @kfollesdal @FaresKi How do you handle deployment names variables?
Author
Owner

@kfollesdal commented on GitHub (Jul 7, 2025):

@ngocsanguit, what do you mean by deployment names? Have you used the AZURE_RESOURCE_NAME variable? That you set equal to the name of our deployed resource.

@kfollesdal commented on GitHub (Jul 7, 2025): @ngocsanguit, what do you mean by deployment names? Have you used the AZURE_RESOURCE_NAME variable? That you set equal to the name of our deployed resource.
Author
Owner

@ngocsanguit commented on GitHub (Jul 8, 2025):

@kfollesdal the URL for calling Azure constructed
https://AZURE_RESOURCE_NAME.openai.azure.com/openai/deployments/DEPLOYMENT_NAME/chat/completions?api-version=API_VERSION
so we need to define the AZURE_RESOURCE_NAME and DEPLOYMENT_NAME as well, tried to defined in .env but it didnt work

@ngocsanguit commented on GitHub (Jul 8, 2025): @kfollesdal the URL for calling Azure constructed https://**AZURE_RESOURCE_NAME**.openai.azure.com/openai/deployments/**DEPLOYMENT_NAME**/chat/completions?api-version=**API_VERSION** so we need to define the AZURE_RESOURCE_NAME and DEPLOYMENT_NAME as well, tried to defined in .env but it didnt work
Author
Owner

@kfollesdal commented on GitHub (Jul 8, 2025):

It works for me with the two env variables mention [here]. (https://github.com/sst/models.dev/blob/1f9b6fbd26b90fc23af537b6aa089ca7f2aee487/providers/azure/provider.toml#L2). There is not any env variable named DEPLOYMENT_NAME, it is only AZURE_RESOURCE_NAME and AZURE_API_KEY. I think deployment is set automatically when you choose model in the TUI (model = deployment). Have you tried with GPT-4.1

What error do you get?

@kfollesdal commented on GitHub (Jul 8, 2025): It works for me with the two env variables mention [here]. (https://github.com/sst/models.dev/blob/1f9b6fbd26b90fc23af537b6aa089ca7f2aee487/providers/azure/provider.toml#L2). There is not any env variable named `DEPLOYMENT_NAME`, it is only `AZURE_RESOURCE_NAME` and `AZURE_API_KEY`. I think deployment is set automatically when you choose model in the TUI (model = deployment). Have you tried with GPT-4.1 What error do you get?
Author
Owner

@ngocsanguit commented on GitHub (Jul 9, 2025):

I tried the 4o and got error. But 4.1 works for me. Thanks alot @kfollesdal
'DeploymentNotFound', 'message': 'The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

@ngocsanguit commented on GitHub (Jul 9, 2025): I tried the 4o and got error. But 4.1 works for me. Thanks alot @kfollesdal `'DeploymentNotFound', 'message': 'The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#313