Microsoft Foundry in Practice

Using the Anthropic SDK with Foundry in TypeScript

Node.js teams get first-class Foundry support from Anthropic — through a dedicated package rather than the base SDK. Here's how the pieces fit.

Claude 3P 101 · Updated July 2026 · Unofficial guide

If your backend is Node.js or TypeScript, calling Claude on Microsoft Foundry is officially supported — Foundry is covered by Anthropic's TypeScript, Python, C#, Java, and PHP SDKs (though not currently Go or Ruby). The one wrinkle that trips people up: unlike Python, where the Foundry client ships inside the base anthropic package, TypeScript uses a separate package.

Install the Foundry package

npm install @anthropic-ai/foundry-sdk

The package exports an AnthropicFoundry client that you construct with an options object: new AnthropicFoundry({ apiKey, resource }). The two options mirror the Python constructor exactly — an Azure-issued API key, and the name of your Foundry resource. From the resource name the SDK derives the endpoint, https://<resource-name>.services.ai.azure.com/anthropic; alternatively you can supply the full base URL (the Target URI shown on your deployment's Details tab in the Foundry portal) instead of the resource name. Resource and base URL are two ways of expressing the same thing, so provide one or the other, not both.

As with the other Anthropic SDKs, configuration can come from the environment instead of code: the SDKs auto-read ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE, and ANTHROPIC_FOUNDRY_BASE_URL. In a containerized Node service, setting those three variables and constructing the client with no arguments keeps credentials out of the codebase entirely.

Requests look like normal Claude code

Once constructed, the client speaks the standard Claude Messages API: you call the messages-create method with model, max_tokens, and a messages array, and you get back the standard Claude response shape, including the usage object — consistent across platforms, so response-handling code ports cleanly from first-party API projects. Streaming works the same way it does against the first-party API and is generally available on Foundry, which matters for chat-style UX where you want tokens flowing to the browser as they're generated.

The important Foundry-specific habit is what you pass as model: it's your deployment name, not a catalog lookup. Deployment names default to bare model IDs like claude-sonnet-5 or claude-opus-4-8 (no anthropic. prefix), but they're set — permanently — at deployment time. See deploying Claude models in Foundry for how names, hosting versions, and updates work.

If you skip the SDK and call the REST endpoint directly (POST https://<resource-name>.services.ai.azure.com/anthropic/v1/messages), note that REST and JavaScript clients send the anthropic-version: 2023-06-01 header, and the API key goes in the api-key or x-api-key header.

Authentication choices

API keys are the fast path for development. For production services running inside Azure — App Service, Container Apps, AKS — prefer Microsoft Entra ID tokens: a bearer token in the Authorization header, minted by the Azure Identity library from a managed identity, with access governed by Azure RBAC instead of a shared secret. The scopes, role assignments, and 403 troubleshooting are covered in authenticating with Microsoft Entra ID, and the credential trade-offs in managing API keys.

Rule of thumb: handle 429s yourself. Foundry does not return Anthropic's standard anthropic-ratelimit-* response headers, so a Node service can't read remaining-quota hints from responses. Use exponential backoff with jitter on 429, and watch consumption through Azure monitoring — details in understanding Foundry quota types.

Production notes

Log the request-id and apim-request-id response headers on every call; Anthropic and Azure support use the pair to trace a request across both systems. And before you commit to a feature list, check Foundry beta caveats: core Messages, streaming, tool use, PDF input, prompt caching, extended thinking, and 1M context are GA, but some features are beta on Foundry, and some — like structured outputs and server-side tools — require a Hosted on Anthropic deployment rather than a Hosted on Azure one; requests for those against an Azure-hosted deployment return 400 Bad Request by design.

Where to go next

The Python, .NET, and Java guides cover the same ground for other stacks; the quickstart has the fastest end-to-end path.

Sources