opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: Add support for Anthropic models in Azure AI Foundry

Open CarlosGtrz opened this issue 2 months ago • 22 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Anthropic models are now available in Azure AI Foundry. Reference: https://code.claude.com/docs/en/azure-ai-foundry

CarlosGtrz avatar Nov 19 '25 02:11 CarlosGtrz

Yep we should do that, basically just means updating: https://github.com/sst/models.dev

rekram1-node avatar Nov 19 '25 06:11 rekram1-node

Looking into this now - added support in sst/models.dev#405 but unable to use the claude models yet. Wondering if we should wait for ai-sdk/azure support for @anthropic-ai/foundry-sdk or just add a switch for the time being.

cau1k avatar Nov 20 '25 01:11 cau1k

u can override the npm package per model if u need to:

[provider] npm = “…”

rekram1-node avatar Nov 20 '25 01:11 rekram1-node

u can override the npm package per model if u need to:

[provider] npm = “…”

Thanks - fixed in sst/models.dev#409

cau1k avatar Nov 20 '25 01:11 cau1k

is this available with latest opencode version 1.0.80

krishna1s avatar Nov 20 '25 06:11 krishna1s

@krishna1s should be you just need to restart opencode a couple of times to refresh ur cache

rekram1-node avatar Nov 20 '25 06:11 rekram1-node

@rekram1-node I can see now azure/claude-sonnet-4-5, is there any way to clean the cache. Also would opencode auth login with azure, going to support foundry key or we need to set env as suggested here

krishna1s avatar Nov 20 '25 06:11 krishna1s

is there any way to clean the cache

rm ~/.cache/opencode/models.json

Uh idk I didn't set it up but i can take a look when I get a chance

rekram1-node avatar Nov 20 '25 06:11 rekram1-node

I tried configuring anthropic env variable but it doesn't seems to be working

krishna1s avatar Nov 20 '25 10:11 krishna1s

@krishna1s this works, just set the envs to your foundry creds (base url: https://{resource-name}.services.ai.azure.com/anthropic/v1)

{
  "provider": {
    "azure": {
      "models": {
        "claude-haiku-4-5": {
          "id": "claude-haiku-4-5",
          "provider": {
            "npm": "@ai-sdk/anthropic",
            "options": {
              "apiKey": "{env:ANTHROPIC_FOUNDRY_API_KEY}",
              "baseURL": "{env:ANTHROPIC_FOUNDRY_BASE_URL}"
            }
          }
        }
      }
    }
  }
}

cau1k avatar Nov 21 '25 01:11 cau1k

This is very important :)

edisonpaul4 avatar Nov 21 '25 14:11 edisonpaul4

@krishna1s this works, just set the envs to your foundry creds (base url: https://{resource-name}.services.ai.azure.com/anthropic/v1)

{ "provider": { "azure": { "models": { "claude-haiku-4-5": { "id": "claude-haiku-4-5", "provider": { "npm": "@ai-sdk/anthropic", "options": { "apiKey": "{env:ANTHROPIC_FOUNDRY_API_KEY}", "baseURL": "{env:ANTHROPIC_FOUNDRY_BASE_URL}" } } } } } } }

Didnt work for me.

Image

` INFO 2025-11-21T14:49:36 +0ms service=session.prompt sessionID=ses_5591ba16affeJMoRrZpI0kg4cr cancel INFO 2025-11-21T14:49:36 +1ms service=bus type=session.status publishing INFO 2025-11-21T14:49:36 +0ms service=bus type=session.idle publishing 68 | autoload: false, 69 | async getModel(sdk: any, modelID: string, options?: Record<string, any>) { 70 | if (options?.["useCompletionUrls"]) { 71 | return sdk.chat(modelID) 72 | } else { 73 | return sdk.responses(modelID) ^ TypeError: sdk.responses is not a function. (In 'sdk.responses(modelID)', 'sdk.responses' is undefined) at (src/provider/provider.ts:73:24) at getModel (src/provider/provider.ts:69:34) at getModel (src/provider/provider.ts:584:26)

INFO 2025-11-21T14:49:36 +0ms service=provider status=completed duration=43 providerID=azure getSDK ERROR 2025-11-21T14:49:36 +1ms service=acp-command promise={} reason=sdk.responses is not a function. (In 'sdk.responses(modelID)', 'sdk.responses' is undefined) Unhandled rejection ERROR 2025-11-21T14:49:36 +0ms service=default e=sdk.responses is not a function. (In 'sdk.responses(modelID)', 'sdk.responses' is undefined) rejection INFO 2025-11-21T14:49:36 +3ms service=default directory=/home/edisonpaul4 disposing instance INFO 2025-11-21T14:49:36 +0ms service=state key=/home/edisonpaul4 waiting for state disposal to complete INFO 2025-11-21T14:49:36 +1ms service=state key=/home/edisonpaul4 state disposal completed `

edisonpaul4 avatar Nov 21 '25 14:11 edisonpaul4

@edisonpaul4 try using the anthropic provider with the same env. Had the same issue on my system but it works fine in a fresh environment https://github.com/cau1k/anthropic-foundry-opencode

cau1k avatar Nov 21 '25 15:11 cau1k

@edisonpaul4 try using the anthropic provider with the same env. Had the same issue on my system but it works fine in a fresh environment https://github.com/cau1k/anthropic-foundry-opencode

Not working

INFO 2025-11-24T12:38:57 +0ms service=provider providerID=azure-custom pkg=@ai-sdk/anthropic using preinstalled provider INFO 2025-11-24T12:38:57 +43ms service=provider status=completed duration=43 providerID=azure-custom getSDK INFO 2025-11-24T12:38:57 +0ms service=provider status=completed duration=43 providerID=azure-custom getSDK INFO 2025-11-24T12:38:57 +0ms service=provider providerID=azure-custom modelID=claude-haiku-4-5 found INFO 2025-11-24T12:38:57 +0ms service=provider providerID=azure-custom modelID=claude-haiku-4-5 found INFO 2025-11-24T12:38:57 +7ms service=bus type=message.updated publishing ERROR 2025-11-24T12:38:57 +3ms service=session.prompt error=Anthropic API key is missing. Pass it using the 'apiKey' parameter or the ANTHROPIC_API_KEY environment variable. model=claude-haiku-4-5 failed to generate title INFO 2025-11-24T12:38:57 +6ms service=bash-tool shell=/bin/bash bash tool using shell INFO 2025-11-24T12:38:57 +5ms service=session.processor process INFO 2025-11-24T12:38:57 +3ms service=bus type=session.status publishing ERROR 2025-11-24T12:38:57 +1ms service=session.prompt error={"error":{"name":"AI_LoadAPIKeyError"}} stream error ERROR 2025-11-24T12:38:57 +2ms service=session.processor error=Anthropic API key is missing. Pass it using the 'apiKey' parameter or the ANTHROPIC_API_KEY environment variable. process INFO 2025-11-24T12:38:57 +0ms service=bus type=session.error publishing INFO 2025-11-24T12:38:57 +1ms service=bus type=message.updated publishing INFO 2025-11-24T12:38:57 +0ms service=session.compaction pruning Error: Anthropic API key is missing. Pass it using the 'apiKey' parameter or the ANTHROPIC_API_KEY environment variable. INFO 2025-11-24T12:38:57 +4ms service=session.prompt sessionID=ses_54a20280cffeTuZLqvjlf6Crcw cancel INFO 2025-11-24T12:38:57 +0ms service=bus type=session.status publishing INFO 2025-11-24T12:38:57 +0ms service=bus type=session.idle publishing INFO 2025-11-24T12:38:57 +2ms service=bus type=message.updated publishing ERROR 2025-11-24T12:38:57 +1ms service=acp-command promise={} reason=Anthropic API key is missing. Pass it using the 'apiKey' parameter or the ANTHROPIC_API_KEY environment variable. Unhandled rejection ERROR 2025-11-24T12:38:57 +0ms service=default e=Anthropic API key is missing. Pass it using the 'apiKey' parameter or the ANTHROPIC_API_KEY environment variable. rejection INFO 2025-11-24T12:38:57 +0ms service=bus type=session.updated publishing INFO 2025-11-24T12:38:57 +0ms service=bus type=session.diff publishing INFO 2025-11-24T12:38:57 +0ms service=session.compaction pruned=0 total=0 found

and this is my opencode.json (took your and just kept what i needed)

{ "$schema": "https://opencode.ai/config.json", "provider": { "azure-custom": { "models": { "claude-haiku-4-5": { "id": "claude-haiku-4-5", "provider": { "npm": "@ai-sdk/anthropic", "options": { "apiKey": "{env:ANTHROPIC_FOUNDRY_API_KEY}", "baseURL": "{env:ANTHROPIC_FOUNDRY_BASE_URL}" } }, "options": { "thinking": { "type": "enabled", "budgetTokens": 16000, } }, }, "claude-sonnet-4-5": { "id": "claude-sonnet-4-5", "provider": { "npm": "@ai-sdk/anthropic", "options": { "apiKey": "{env:ANTHROPIC_FOUNDRY_API_KEY}", "baseURL": "{env:ANTHROPIC_FOUNDRY_BASE_URL}" } }, "options": { "thinking": { "type": "enabled", "budgetTokens": 16000, } }, }, } }, } }

edisonpaul4 avatar Nov 24 '25 12:11 edisonpaul4

Hello, this configuration works according to my tests

Image
{
	"$schema": "https://opencode.ai/config.json",
	"provider": {
		"azure-anthropic": {
			"name": "Azure AI Foundry (Anthropic)",
			"npm": "@ai-sdk/anthropic",
			"api": "{env:ANTHROPIC_FOUNDRY_BASE_URL}",
			"env": ["ANTHROPIC_FOUNDRY_API_KEY"],
			"models": {
				"claude-sonnet-4-5": {
					"id": "claude-sonnet-4-5",
					"name": "Claude Sonnet 4.5",
					"tool_call": true,
					"attachment": true,
					"reasoning": true,
					"temperature": true,
					"options": {
						"thinking": {
							"type": "enabled",
							"budgetTokens": 16000
						}
					}
				},
				"claude-haiku-4-5": {
					"id": "claude-haiku-4-5",
					"name": "Claude Haiku 4.5",
					"tool_call": true,
					"attachment": true,
					"reasoning": true,
					"temperature": true,
					"options": {
						"thinking": {
							"type": "enabled",
							"budgetTokens": 16000
						}
					}
				}
			}
		}
	}
}

niusnet avatar Nov 24 '25 17:11 niusnet

Hello, this configuration works according to my tests [...]

I can confirm. Worked for me.

cloonix avatar Nov 25 '25 11:11 cloonix

Does it work irrespective of foundry deployment name ?

krishna1s avatar Nov 25 '25 14:11 krishna1s

Yes, it works regardless of the Foundry deployment name.

The resource URL is configured through an environment variable like ANTHROPIC_FOUNDRY_BASE_URL, where you set the full URL of your resource:

https://[RESOURCE_NAME].services.ai.azure.com/anthropic/v1

So the deployment name itself doesn't matter what matters is that the base URL points to your specific Azure AI Foundry resource.

niusnet avatar Nov 25 '25 17:11 niusnet

do we need to update models.dev was it incorrect?

rekram1-node avatar Nov 25 '25 20:11 rekram1-node

The resource name can also be provided in opencode.json. The API-Key can be set in auth.json as well. That's my current setup. Thanks to the comment before.

  "provider": {
    "azure-anthropic": {
      "name": "Azure AI Foundry (Anthropic)",
      "npm": "@ai-sdk/anthropic",
      "api": "https://<RSN>.ai.azure.com/anthropic/v1",
      "models": {
        "claude-opus-4-5": {
          "id": "claude-opus-4-5",
          "name": "Claude Opus 4.5",
          "tool_call": true,
          "attachment": true,
          "reasoning": true,
          "temperature": true
        },
        "claude-sonnet-4-5": {
          "id": "claude-sonnet-4-5",
          "name": "Claude Sonnet 4.5",
          "tool_call": true,
          "attachment": true,
          "reasoning": true,
          "temperature": true
        }
      }

auth.json:

{
  "azure-anthropic": {
    "type": "api",
    "key": "xyz"
  }
}

cloonix avatar Nov 27 '25 09:11 cloonix

The resource name can also be provided in opencode.json. The API-Key can be set in auth.json as well. That's my current setup. Thanks to the comment before.

"provider": { "azure-anthropic": { "name": "Azure AI Foundry (Anthropic)", "npm": "@ai-sdk/anthropic", "api": "https://<RSN>.ai.azure.com/anthropic/v1", "models": { "claude-opus-4-5": { "id": "claude-opus-4-5", "name": "Claude Opus 4.5", "tool_call": true, "attachment": true, "reasoning": true, "temperature": true }, "claude-sonnet-4-5": { "id": "claude-sonnet-4-5", "name": "Claude Sonnet 4.5", "tool_call": true, "attachment": true, "reasoning": true, "temperature": true } }

auth.json:

{ "azure-anthropic": { "type": "api", "key": "xyz" } }

This works great in the Terminal but not on the Web UI for some reason. Has anybody found a workaround for that?

lasficw avatar Jan 05 '26 12:01 lasficw

I'm having the issue with OpenCode 1.1.16 , is that opencode need to dump version of dependency, or this need to be configured manually?

bluet avatar Jan 13 '26 13:01 bluet