Configure Azure AI Services (Cognitive Services or OpenAI) as a provider in OpenCode. USE FOR: setup azure opencode, connect azure models to opencode, azure cognitive services opencode, azure openai provider config, opencode.json azure, whitelist azure models, filter azure model list, AZURE_COGNITIVE_SERVICES_RESOURCE_NAME, AZURE_RESOURCE_NAME, azure /connect, azure 404 deployment, azure 401 auth opencode, troubleshoot azure opencode, az cognitiveservices opencode. DO NOT USE FOR: deploying Azure infrastructure (use azure-deploy), creating AI Foundry projects (use microsoft-foundry), general Azure resource lookup (use azure-resource-lookup), application deployment to Azure (use azure-prepare).
Install
npx skillscat add primeinc/azure-opencode-setup Install via the SkillsCat registry.
This skill configures Azure AI Services or OpenAI as a provider in OpenCode by scanning Azure subscriptions to find AI resources with deployments, building a model whitelist, and verifying the endpoint. It solves the manual setup process for connecting Azure models to OpenCode. Developers should use it when they need to integrate Azure Cognitive Services or OpenAI with OpenCode without deploying infrastructure.
Azure AI + OpenCode Setup
Quick path (one command)
Run the automation script. All params optional — with zero args it scans every subscription and picks the resource with the most deployments:
# PowerShell — dry run (prints JSON, changes nothing)
.\scripts\emit-opencode-azure-cogsvc-config.ps1
# PowerShell — apply (writes opencode.json, sets env var, verifies endpoint)
.\scripts\emit-opencode-azure-cogsvc-config.ps1 -Apply
# Target a specific resource
.\scripts\emit-opencode-azure-cogsvc-config.ps1 -Subscription "<SUB_ID>" -Resource "<RESOURCE>" -Apply# Bash (requires jq) — same flags
./scripts/emit-opencode-azure-cogsvc-config.sh # dry run
./scripts/emit-opencode-azure-cogsvc-config.sh --apply # apply
./scripts/emit-opencode-azure-cogsvc-config.sh --subscription "<SUB_ID>" --resource "<RESOURCE>" --applyWhat the script does (in order):
- Scans subscriptions → finds AI resources → picks the one with most deployments
- Lists deployments → builds whitelist (deployment names + model names when they differ)
- Verifies endpoint with a live API call
- With
-Apply: merges config intoopencode.json, sets env var persistently, prints the API key for/connect
Only manual step after -Apply: run /connect in OpenCode and paste the API key.
Manual path
| Step | Action | Reference |
|---|---|---|
| 1 | Discover resource | references/discovery-scripts.md |
| 2 | Match endpoint → provider | Table below |
| 3 | Verify endpoint | references/verify-endpoint.md |
| 4 | Set env var (persistent) | Platform commands below |
| 5 | /connect in OpenCode |
Paste API key (stored in auth.json, NOT env var) |
| 6 | Configure opencode.json |
Whitelist + disabled_providers |
| 7 | Validate quota | references/quota-validation.md |
Endpoint → provider mapping [MICROSOFT-NORMATIVE]
| Endpoint pattern | Provider | Env var |
|---|---|---|
*.cognitiveservices.azure.com |
azure-cognitive-services |
AZURE_COGNITIVE_SERVICES_RESOURCE_NAME |
*.openai.azure.com |
azure |
AZURE_RESOURCE_NAME |
Source of truth: az cognitiveservices account show -g <RG> -n <RES> --query properties.endpoint -o tsv
Set env var (persistent) [PROPOSED]
The env var holds the resource name only. API key goes through /connect.
Windows (PowerShell):
setx AZURE_COGNITIVE_SERVICES_RESOURCE_NAME "<RESOURCE>"
# Restart terminal for setx to take effectmacOS (zsh):
echo 'export AZURE_COGNITIVE_SERVICES_RESOURCE_NAME="<RESOURCE>"' >> ~/.zshrc
source ~/.zshrcLinux (bash):
echo 'export AZURE_COGNITIVE_SERVICES_RESOURCE_NAME="<RESOURCE>"' >> ~/.bashrc
source ~/.bashrcConfig template
{
"disabled_providers": ["azure"],
"provider": {
"azure-cognitive-services": {
"whitelist": [
"gpt-4o",
"gpt-5.2-chat",
"deepseek-v3.2",
"kimi-k2",
"kimi-k2-thinking",
"text-embedding-3-small"
],
"models": {
"kimi-k2": { "name": "Kimi-K2-Thinking (Azure)" }
}
}
}
}Whitelist rules [PROPOSED]
- Deployment name is truth. Every deployment name (lowercased) goes in the whitelist.
- Model name added when it differs. If Azure metadata shows
model.name≠deployment.name, add the model name (lowercased) too. Example: deploymentkimi-k2→ modelKimi-K2-Thinking→ whitelist gets bothkimi-k2andkimi-k2-thinking. - Include all deployments. Don't skip embeddings or utility models (
text-embedding-3-small,model-router). modelsblock only for deployments absent from the built-in catalog. Gives them a display name in/models.
Multi-resource constraint [PROPOSED]
One provider config = one Azure resource. AZURE_COGNITIVE_SERVICES_RESOURCE_NAME points to exactly one resource.
If you have multiple resources:
- Pick the one with most deployments (script auto-picks if
--resourceomitted) - To switch: change the env var and restart OpenCode
- OpenCode does not support multiple Azure resources in a single config
Self-check: diff deployments vs whitelist
# Compare Azure deployments to opencode.json whitelist
$deployed = az cognitiveservices account deployment list -g <RG> -n <RES> `
--query "[].name" -o json | ConvertFrom-Json | ForEach-Object { $_.ToLower() } | Sort-Object
$whitelist = (Get-Content ~/.config/opencode/opencode.json | ConvertFrom-Json).provider.'azure-cognitive-services'.whitelist | Sort-Object
$missing = $deployed | Where-Object { $_ -notin $whitelist }
if ($missing) { Write-Host "MISSING from whitelist: $($missing -join ', ')" -ForegroundColor Red }
else { Write-Host "Whitelist matches all deployments" -ForegroundColor Green }Troubleshooting
See references/troubleshooting.md — covers 404, 401, wrong endpoint, catalog still showing, quota exceeded, deployment/model name mismatch.