docs(examples): add mTLS and custom TLS configuration example#1280
Open
JakeBx wants to merge 1 commit intoanthropics:mainfrom
Open
docs(examples): add mTLS and custom TLS configuration example#1280JakeBx wants to merge 1 commit intoanthropics:mainfrom
JakeBx wants to merge 1 commit intoanthropics:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1279
What
Adds
examples/mtls.pydemonstrating how to use the SDK with mTLS client certificate authentication and custom CA bundles.Why
mTLS is becoming an industry standard for API access in regulated environments. OpenAI recently launched an mTLS beta program for their API, and enterprise users are increasingly expecting the same capability from Anthropic deployments.
Common use cases include:
This is a recurring question across the ecosystem:
The underlying SDK already supports this via the
http_clientparameter, but there is no example or documentation showing the pattern.How
Uses the existing
http_clientparameter withDefaultHttpxClient/DefaultAsyncHttpxClient. No SDK code changes required — this is purely documentation of existing capability.The example builds an
ssl.SSLContextwith the CA bundle and client certificate, then passes it asverify=toDefaultHttpxClient. This preserves all SDK defaults (connection limits, timeouts, TCP keepalive, proxy detection) while enabling mTLS:Covers three scenarios:
Anthropic+DefaultHttpxClient)AsyncAnthropic+DefaultAsyncHttpxClient)Testing
Verified locally against an nginx mTLS reverse proxy with self-signed certificates. The TLS handshake completes successfully and the SDK correctly processes the upstream response.