Skip to content

feat: use standard Anthropic clients across SDK samples - #71

Open
Arun Sekhar (achandmsft) wants to merge 1 commit into
fix/industry-attestation-20261028from
feat/portable-anthropic-sdk-clients-20261029
Open

Arun Sekhar (achandmsft) wants to merge 1 commit into
fix/industry-attestation-20261028from
feat/portable-anthropic-sdk-clients-20261029

Conversation

@achandmsft

@achandmsft Arun Sekhar (achandmsft) commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

Use standard Anthropic SDK clients in Python, TypeScript, C#, Go, Java, PHP and Ruby, with small, generic authentication helpers rather than Foundry-specific client dependencies.

Why

Keep application Messages and streaming code portable between Anthropic and Microsoft Foundry. Endpoint, model, authentication source and optional header policy belong in configuration, not a different client type.

This PR is stacked on #70 to keep the SDK migration separate from the pending Industry-attestation change. Merge #70 first, then retarget/rebase this PR onto main. Because automatic PR runs currently filter to main, validation was manually dispatched against this SDK head: all 10 Linux jobs passed. After retargeting, dispatch validation again or push an update; changing the base alone does not retrigger this workflow.

Related SDK and service requests:

How

  • Return ordinary SDK clients; use public authentication hooks, not SDK subclasses or a new provider framework.
  • Separate token acquisition from client construction. The five supported Azure Identity SDK integrations select CLI, azd or managed identity explicitly; PHP/Ruby document a renewable callback with a CLI-only local fallback.
  • Resolve endpoint/model/key configuration as one profile to prevent accidental cross-provider credential mixing.
  • Preserve SDK timeouts, retries, status errors and streaming; retain Java's sync and async paths.
  • Bind credentials to the configured origin and cover authentication precedence, cancellation and diagnostic redaction with offline tests.
  • Keep Claude Code's separate built-in Foundry mode unchanged.
  • Add seven-language CI, documentation and upstream tracking links.

TypeScript is intentionally pinned to tested SDK 1.1.0: the configured package feed did not provide 1.3.0 and direct public-registry access failed TLS negotiation in the validation environment. Relevant 1.3.0 source was compared, but that package version was not executed.

Verification

  • azd up succeeded end-to-end on a fresh env (Bicep)
  • azd up succeeded end-to-end on a fresh env (Terraform)
  • python src/hello_claude.py returned a live model response
  • N/A — docs-only / CI-only change

Cloud verification was completed during implementation on 2026-10-28/29: one fresh Bicep environment, Haiku 5.5 model version 2, eastus2, in an authorized Claude-eligible test subscription. Subscription, tenant, principal, account and resource identifiers are intentionally omitted. All preflight/Industry/RBAC hooks remained enabled.

All seven languages passed live Messages, SSE streaming and resource-key authentication with native SDK defaults. Python, TypeScript, C#, Go and Java also passed a configuration-only switch from Azure CLI to Azure Developer CLI credentials. The repository verifier passed its required checks and a Python SDK round trip; its independent Claude Code round trip was deliberately skipped. Terraform was not provisioned for this SDK-only change; neither IaC variant's templates changed.

Native Anthropic endpoint routing is verified through offline recording transports, not a native-account live call. Windows PHP live tests used a trusted CA bundle with TLS verification enabled. No credentials or private deployment data are included in this PR.

Publication-time offline validation (2026-10-29), using the documented runners with machine-local runtime/package-cache configuration:

Scope Command Result
Python python -m unittest discover -s tests -v Passed: 61 tests
Python syntax python -m compileall -q src tests Passed
Python dependencies pip check Passed: no broken requirements
TypeScript, from samples/typescript npm run build; npm test Passed: build and 60 tests
Go, from samples/go go vet ./...; go test ./... Passed; one intentional skip
C# dotnet test samples\dotnet\AnthropicStandardSdk.sln --configuration Release --no-restore Passed: 120 tests
Java mvn -B -ntp -f samples\java\pom.xml test Passed: 125 tests; local Maven repository override used
PHP, from samples/php composer test (Composer PHAR invoked through PHP) Passed: 48 tests
Ruby, from samples/ruby bundle exec ruby test/run.rb with frozen lockfile Passed: 38 runs, 486 assertions
Candidate git diff --cached --check Passed

Java validation used JDK 25 with --release 17; CI uses JDK 21. C# validation targets .NET 8. TypeScript validation used Node 24, PHP used 8.5, and Ruby used 4.0; the implementation-time compatibility runs are documented in the language READMEs.

Sonnet 5.5 reviewed the staged publication candidate and found no other significant defects. Its publication recommendation was to exercise Linux CI explicitly for the stacked PR. Executed gh workflow run validate.yml --repo Azure-Samples/claude --ref feat/portable-anthropic-sdk-clients-20261029: passed, all 10 jobs on commit 116f2581eb6ce49844b2d82d364e2edac10a8da0, including the seven SDK paths, both static IaC validation jobs, and shell analysis.

Checklist

  • Mirrored the change across both infra-bicep/ and infra-terraform/ (if applicable) — N/A: no IaC template changes
  • No secrets / subscription IDs / tenant IDs / object IDs in commits, comments, or PR body
  • README updated if user-facing behavior changed
  • Conventional one logical change per PR

Use stock SDK clients and generic authentication helpers across seven languages. Preserve Claude Code wiring, add cross-provider configuration checks and regression coverage, and document upstream compatibility requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/client_auth.py
event_hooks={"request": [authorize]},
)
# Explicit credentials suppress SDK discovery; the public hook sets the real header.
return Anthropic(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought maybe they'd made it easier, per the comment here?
anthropics/anthropic-sdk-python#1496 (comment)
(Though that example uses their own credentials provider)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants