Microsoft Foundry in Practice

Calling Claude on Foundry from Java

Enterprise Java services can call Claude on Azure through an official Anthropic artifact — no hand-rolled HTTP client, no unofficial wrapper.

Claude 3P 101 · Updated July 2026 · Unofficial guide

Java remains the workhorse of enterprise backends, and Anthropic supports it as a first-class language for Microsoft Foundry. Foundry support ships in a dedicated Maven artifact, com.anthropic:anthropic-java-foundry — one of five SDKs with Foundry coverage (C#, Java, PHP, Python, and TypeScript; Go and Ruby are not currently supported). This article covers how the client is configured, what a request looks like, and how to slot it into a Spring Boot service cleanly.

Dependency and endpoint configuration

Add com.anthropic:anthropic-java-foundry to your Maven pom.xml or Gradle build. Configuration follows the same contract as every Anthropic Foundry SDK: the client needs to know your Foundry resource, expressed one of two mutually exclusive ways — the resource name, from which the SDK builds https://<resource-name>.services.ai.azure.com/anthropic/, or the full base URL (the Target URI shown on your deployment's Details tab in the Foundry portal under Build > Models).

Credentials and endpoint can come from the environment: the Anthropic SDKs auto-read ANTHROPIC_FOUNDRY_API_KEY, ANTHROPIC_FOUNDRY_RESOURCE, and ANTHROPIC_FOUNDRY_BASE_URL. That maps naturally onto a Spring Boot deployment: set the variables in your App Service or AKS manifest, build the client from the environment in a @Configuration class, and expose it as a singleton bean. The client is then injected wherever the application needs Claude, and rotating a key becomes a configuration change rather than a code change. For the exact builder methods and types, consult the artifact's documentation — Anthropic's platform docs describe the Java package at a higher level than the Python one.

Making requests

Requests use the standard Claude Messages API, and responses come back in the standard Claude format — including the usage object with token counts — identical in shape across platforms, so any response-handling or cost-metering code you wrote against the first-party API carries over. Streaming and tool use are generally available on Foundry, and there's a token-counting endpoint at POST /v1/messages/count_tokens for sizing prompts before you send them.

The model parameter takes your deployment name, fixed at deployment time and defaulting to a bare model ID such as claude-sonnet-5 or claude-opus-4-8 (Foundry never uses the anthropic. prefix you may know from Bedrock). Treat the deployment name as configuration too — a Spring property like claude.deployment-name — so switching models is an ops action, not a release. Deployment mechanics are covered in deploying Claude models in Foundry.

Authentication in a Spring Boot world

API keys (sent as the api-key or x-api-key header over REST) are fine for development. For production Java services on Azure, use Microsoft Entra ID: the Azure Identity library for Java provides DefaultAzureCredential, which picks up the managed identity of the hosting compute and yields bearer tokens for the Authorization header. Access is then an Azure RBAC decision — a 403 typically means the service's identity lacks a role such as Cognitive Services User on the Foundry resource. Scopes and troubleshooting are in the Entra ID article; the key-management trade-offs are in managing API keys.

Rule of thumb: configure your resilience layer (Resilience4j or similar) for exponential backoff on HTTP 429 without expecting quota hints — Foundry does not return Anthropic's anthropic-ratelimit-* response headers. Track consumption via Azure monitoring instead; see Foundry quota types.

Feature planning

Before the roadmap hardens, know that some Claude features are still beta on Foundry, the Message Batches API is not available there at all, and several capabilities — structured outputs, server-side tools, the Files API — require a Hosted on Anthropic deployment rather than Hosted on Azure, returning 400 Bad Request otherwise. Log the request-id and apim-request-id response headers on every call for traceability across Anthropic and Azure support systems.

Where to go next

Sibling guides: Python, TypeScript, and .NET. For an end-to-end first call, start at the quickstart.

Sources