TIL: Setting up Claude Code with Azure Foundry models
Claude has documentation on this, but I find the Azure Foundry’s documentation more useful because the instructions are more up-to-date with their UI (currently changing once more).
The one thing I wasn’t so comfortable with is setting the keys and all in env vars. If any process has access to the environment, it can extricate these values, even by mistake, and that’s not desirable.
Luckily, the ~/.claude/settings.json file support settings these, so here’s my example:
{
"env": {
"CLAUDE_CODE_USE_FOUNDRY": 1,
"ANTHROPIC_FOUNDRY_BASE_URL": " https://<project-name>-resource.services.ai.azure.com/anthropic",
"ANTHROPIC_FOUNDRY_API_KEY": "<key>",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-6"
}
}
Couple of notes:
- You can set either
ANTHROPIC_FOUNDRY_RESOURCEorANTHROPIC_FOUNDRY_BASE_URL. It’s a bit confusing because you create a project, say namedfoo-barin Foundry, but the resource name isfoo-bar-resource.
At the end of the day copying the URL from the Foundry site seemed more straightforward. - I think it’s advisable to set names of the models deployed explicitly, hence
ANTHROPIC_DEFAULT_SONNET_MODELbecause Claude Code may have different defaults.
I got this message on my first run: “The model claude-sonnet-4-5 is not available on your foundry deployment. Try /model to switch to claude-sonnet-4, or ask your admin to enable this model.”, and, fair enough, I hadclaude-sonnet-4-6deployed.