Python SDK

Install anonrouter-sdk and anonrouter-confidential from PyPI, verify the gateway, and configure connection-bound confidential inference.

Install AnonRouter's Python SDK to check attestation evidence and use confidential inference from your own application. Python 3.10 or newer is required.

Choose a package

PackageInstallPython import
anonrouter-sdkpython -m pip install "anonrouter-sdk==0.1.0"from anonrouter import create_client
anonrouter-confidentialpython -m pip install "anonrouter-confidential[connection-binding]==0.1.3.post1"from anonrouter_confidential import create_client

anonrouter-sdk exposes the main functions of anonrouter-confidential under import anonrouter. It installs the confidential package with the connection-binding extra, which pins the HTTPX and HTTPCore versions used for retained-connection verification. It is not a separate verification engine.

For routes using ML-KEM encryption, also install:

python -m pip install "anonrouter-confidential[connection-binding,mlkem]==0.1.3.post1"

Check the gateway without an API key

from anonrouter import verify_content_node

result = verify_content_node()
print(result["verdict"].verification_level)

This checks evidence without sending an inference request. Full hardware verification needs the separate anonrouter-dcap-verifier executable. Without it, the diagnostic reports unverified. Do not treat that as a passing hardware check.

Install the reviewed verifier from SDK release artifacts, or build it from the reviewed source. The supplied binary targets Linux amd64. Follow native verifier setup, then check your installation:

anonrouter-verify doctor --origin https://api.anonrouter.ai
anonrouter-verify gateway --origin https://api.anonrouter.ai --dcap --require hardware_verified

Configure strict verification

Load your inference key from ANONROUTER_API_KEY. Select a current confidential model and provider from the catalog, and set ANONROUTER_MODEL and ANONROUTER_PROVIDER accordingly.

import os
from anonrouter import create_client, create_anonrouter_dcap_verifier

with create_client(
    api_key=os.environ["ANONROUTER_API_KEY"],
    gateway_policy_updates=True,
    gateway_connection_binding={
        "mode": "required",
        "verification": {"chain_verifier": create_anonrouter_dcap_verifier()},
    },
) as client:
    verdict = client.verify_route(
        model=os.environ["ANONROUTER_MODEL"],
        provider=os.environ["ANONROUTER_PROVIDER"],
        gateway=True,
    )
    print(verdict.gateway.state, verdict.overall_state)

The gateway check uses the same retained TLS connection as the operation. Missing or invalid hardware evidence fails closed. A separate diagnostic run is not a substitute for this connection binding.

gateway.state describes AnonRouter's gateway. overall_state is the weakest result across the hops checked, so a verified gateway does not establish that the provider has the same assurance level. See the verification states.

Send encrypted chat

Use an E2EE-capable route and the strict client above. Inside its with block:

reply = client.chat(
    model=os.environ["ANONROUTER_MODEL"],
    provider=os.environ["ANONROUTER_PROVIDER"],
    messages=[{"role": "user", "content": "Hello"}],
    max_output_tokens=256,
    require_gateway=True,
)

The SDK verifies the route, encrypts the request in your process, and decrypts the reply locally. This sends a paid inference request. Keep the returned content out of application logs.

TEE routes and E2EE routes have different privacy properties. Images and speech use the ticket flow but are not E2EE. Read the confidential SDK guide and media guide before choosing a route.

Optional: install a checksummed release wheel

If you prefer a downloaded release artifact, obtain the wheel and SHA256SUMS from the same SDK release. Compare the wheel's SHA-256 with its exact entry before installing it:

# Example for the v0.1.3 GitHub release artifact:
shasum -a 256 anonrouter_confidential-0.1.3-py3-none-any.whl
# After matching that digest with SHA256SUMS:
python -m pip install "./anonrouter_confidential-0.1.3-py3-none-any.whl[connection-binding]"

The PyPI 0.1.3.post1 package and the v0.1.3 release wheel have different version identifiers and checksums. Match the checksum to the file you download.

Let your agent handle the setup

One prompt carries the entire setup.