### Python setup and checks Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Install the Python package with dev tools and the ML-KEM extra, then run tests, type checking, and linting. The ML-KEM extra is needed for the Chutes route. ```bash cd python pip install -e ".[dev,mlkem]" # dev tools + the ML-KEM extra for the Chutes route pytest -q mypy # no path: pyproject covers src and examples ruff check . ``` -------------------------------- ### Verify, then call (real gateway, your key, BILLABLE) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/examples/README.md The shape most applications want: gate before sending, re-verify hop 1 at send time with a fresh nonce, and say out loud what the verdict did not cover. Supplies the DCAP chain verifier unconditionally, so it reaches hardware_verified where an engine is installed and fails the chain check rather than downgrading where one is not. Makes one small real inference call. Env: everything from example 1, plus ANONROUTER_REQUIRE (default cryptographically_checked; try hardware_verified with an engine installed), PROMPT, MAX_TOKENS. ```bash ANONROUTER_API_KEY=ar_... python examples/verify_then_call.py ``` -------------------------------- ### Install and build @anonrouter/client Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Clones the repository and installs dependencies for the JavaScript workspace. Run from the js/ directory after cloning. ```bash cd anonrouter-sdk/js && npm ci && npm run build ``` -------------------------------- ### Install @anonrouter/confidential via npm or build from source Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Install the package with npm. To build from source, clone the repository, navigate to the js directory, install dependencies with npm ci, and run the build. Requires Node 22 or newer. ```bash npm install @anonrouter/confidential # To build from source instead: git clone https://github.com/anonrouter/anonrouter-sdk cd anonrouter-sdk/js && npm ci && npm run build ``` -------------------------------- ### Install @anonrouter/client from npm Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/client/README.md Install the client package from the npm registry. ```bash npm install @anonrouter/client ``` -------------------------------- ### Build from repository before registry propagation Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/client/README.md Clone the SDK repository, install dependencies, and build the JavaScript package when the npm package is not yet available. ```bash git clone https://github.com/anonrouter/anonrouter-sdk cd anonrouter-sdk/js && npm ci && npm run build ``` -------------------------------- ### Run self-test example Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md Runs the full flow (verify attestation + E2EE chat) against an in-process mock gateway backed by mock enclaves that speak the real provider crypto. Deterministic and safe to run anytime. ```bash npm run example:selftest ``` -------------------------------- ### Check media routes for FREE with live probes Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/examples/README.md Runs the live probes to confirm both media routes answer 401 ticket_required without a ticket and that the control origin serves no media content at all. No key and no spend. ```bash ANONROUTER_LIVE_GATEWAY_ORIGIN=https://api.anonrouter.ai \ ANONROUTER_LIVE_PUBLIC_ORIGIN=https://control.anonrouter.ai \ pytest tests/test_live_media.py ``` -------------------------------- ### Quickstart: create client and use chat Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/client/README.md Create a client with your API key, list models, and send a chat completion. The API key is only used for the ticket request; content is sent with a single-use ticket. This route is visible to the gateway, so use @anonrouter/confidential when content must not be visible. ```ts import { createClient } from "@anonrouter/client"; const client = createClient({ baseUrl: "https://api.anonrouter.ai", apiKey: process.env.ANONROUTER_API_KEY! }); const models = await client.models(); // Two-request ticketed flow. The API key authorizes the ticket; only the // single-use ticket accompanies the content. Content on this route is visible to // the gateway: use @anonrouter/confidential when it must not be. const completion = await client.chat({ model: "openai/gpt-oss-120b", messages: [{ role: "user", content: "Hello." }] }); ``` -------------------------------- ### Install dependencies and run checks in js/ Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Run these commands from the js/ directory to install dependencies and execute typecheck, tests, and build across all npm workspaces. ```bash cd js npm ci # or: npm install npm run typecheck # tsc across every workspace npm test # vitest across every workspace npm run build # tsc build across every workspace ``` -------------------------------- ### Install anonrouter-confidential from clone Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Install the Python package from a clone of the repository. The mlkem extra enables the Chutes route. Once on PyPI, use the commented alternative. ```bash # From a clone of this repo: git clone https://github.com/anonrouter/anonrouter-sdk cd anonrouter-sdk pip install "./python[mlkem]" # mlkem extra enables the Chutes route # Once it is on PyPI: # pip install "anonrouter-confidential[mlkem]" ``` -------------------------------- ### Run route-matrix and negative-controls example harnesses Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Run from `js/confidential` to check every confidential route in the live catalog. `--paid` makes real provider-pinned requests and spends money. `--env-file` reads one variable from an existing `.env`; `--key-file` is for a file whose whole contents are the key. ```bash cd js/confidential # Every callable tee/e2ee route in the live catalog, both hops, with the # reproducible DCAP engine on PATH so hop 1 can reach hardware_verified. npm run example:route-matrix -- --env-file ~/path/to/.env --out matrix.json # ...and one minimal real provider-pinned request per route, so the matrix says # the route RUNS rather than only that it verifies. This spends money. npm run example:route-matrix -- --env-file ~/path/to/.env --paid # The refusals: what the mint, the redemption, and this SDK must each reject. npm run example:negative-controls -- --env-file ~/path/to/.env --out controls.json ``` -------------------------------- ### Verify both hops and read the verdict (real gateway, your key, NOT billable) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/examples/README.md Runs verify_route() and prints what each hop established, what it did not, and why, then exits nonzero if the route did not reach the threshold. Attestation only, so it spends nothing. Env: ANONROUTER_BASE_URL (default https://api.anonrouter.ai), ANONROUTER_CONTROL_URL (default https://control.anonrouter.ai), ANONROUTER_MODEL, ANONROUTER_PROVIDER. ```bash ANONROUTER_API_KEY=ar_... python examples/verify_route.py ``` -------------------------------- ### Python verification and client setup Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/migrating-to-0.1.3.md Use this Python snippet to perform a read-only verification check and create a client with required gateway connection binding. Requires the native DCAP engine on PATH or in ANONROUTER_DCAP_VERIFIER_BIN; browsers cannot verify hop 1 for api.anonrouter.ai. ```Python from anonrouter_confidential import create_client, verify_content_node from anonrouter_confidential.gateway.dcap import create_anonrouter_dcap_verifier check = verify_content_node() assert check["verdict"].status == "ok", check["verdict"].reason client = create_client( api_key=KEY, gateway_connection_binding={"mode": "required", "verification": {"chain_verifier": create_anonrouter_dcap_verifier()}}, ) ``` -------------------------------- ### Quickstart: createClient, verifyRoute, and chat with required gateway binding Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Sets up the confidential client with required gateway connection binding using a DCAP verifier, verifies both hops with verifyRoute(), and sends an end-to-end-encrypted chat. Requires ANONROUTER_API_KEY and a hardware chain verifier. Throws if the route is not cryptographically checked; only ciphertext reaches the relay. ```TypeScript import { createClient, atLeast } from "@anonrouter/confidential"; import { createAnonRouterDcapVerifier } from "@anonrouter/confidential/dcap"; const client = createClient({ baseUrl: "https://api.anonrouter.ai", controlBaseUrl: "https://control.anonrouter.ai", apiKey: process.env.ANONROUTER_API_KEY!, gatewayPolicyUpdates: true, gatewayConnectionBinding: { mode: "required", verification: { chainVerifier: createAnonRouterDcapVerifier() } } }); // Verify BOTH hops, cross-bound to the route you asked for, and gate on it. const verdict = await client.verifyRoute({ model: "google/gemma-4-26b-a4b-uncensored", provider: "venice", gateway: true }); if (!atLeast(verdict.overallState, "cryptographically_checked")) { throw new Error(`route not established: ${verdict.reason}`); } // End-to-end-encrypted chat: keys and nonce are fresh per call, and only // ciphertext ever reaches AnonRouter's relay. Required connection binding obtains // fresh gateway evidence for this operation and checks the attested TLS key // before sending provider evidence or inference to the content origin. const reply = await client.chat({ model: "google/gemma-4-26b-a4b-uncensored", provider: "venice", messages: [{ role: "user", content: "Draft a private message." }], maxOutputTokens: 512, requireGateway: true }); console.log(reply.content); ``` -------------------------------- ### Run scripts for a single package Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Example for working on a single package, e.g., js/client, by running its typecheck, tests, and build directly. ```bash cd js/client npm run typecheck && npm test && npm run build ``` -------------------------------- ### Run live media probes (free, no key, no spend) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md Checks the same media routes for FREE, with no key and no spend. Confirms both media routes answer 401 ticket_required without a ticket and that the control origin serves no media content at all. ```bash ANONROUTER_LIVE_GATEWAY_ORIGIN=https://api.anonrouter.ai \ ANONROUTER_LIVE_PUBLIC_ORIGIN=https://control.anonrouter.ai \ npx vitest run test/live-media.test.ts ``` -------------------------------- ### Verify both hops and read the verdict (real gateway, your key, NOT billable) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md Runs verifyRoute() and prints what each hop established, what it did not, and why, then exits nonzero if the route did not reach the threshold. This is the smallest complete picture of the contract. ```bash ANONROUTER_API_KEY=ar_... npm run example:verify-route ``` -------------------------------- ### Verify, then call (real gateway, your key, BILLABLE) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md The shape most applications want: gate before sending, re-verify hop 1 at send time with a fresh nonce, and say out loud what the verdict did not cover. Supplies the DCAP chain verifier unconditionally, so it reaches hardware_verified where an engine is installed and fails the chain check rather than downgrading where one is not. ```bash ANONROUTER_API_KEY=ar_... npm run example:verify-then-call ``` -------------------------------- ### Verify a deployment without any key using anonrouter-verify Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/examples/README.md Checks a deployment without any key at all. Hop 1 is credential-free by design, because a client verifies the plane before it trusts the endpoint with anything. ```bash anonrouter-verify gateway --origin https://your-cvm.example --dcap ``` -------------------------------- ### Install published package with mlkem extra Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Once published on PyPI, install the package with the mlkem extra. This is a placeholder for the future package name. ```bash pip install "anonrouter-confidential[mlkem]" ``` -------------------------------- ### Run parity gate scripts Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Run the three parity gate scripts. The first checks that per-package pin copies match shared/, the second compares CLI behavior between built JS and installed Python, and the third builds, installs, and exercises every artifact. Run the first before pushing; if it fails, a per-package copy has drifted. ```bash node scripts/check-parity.mjs # pin copies match shared/ node scripts/check-cli-parity.mjs # needs a built js/ and an installed python package node scripts/smoke-artifacts.mjs # builds, installs and exercises every artifact ``` -------------------------------- ### Python: Verify route with DCAP connection binding Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Uses a context manager to create a client with a required gateway connection binding and verifies a route for 'z-ai/glm-5.2' on 'venice'. Exits with an error if the overall state is below 'cryptographically_checked'. Requires installing 'anonrouter-confidential[connection-binding]' from the GitHub release. ```Python from anonrouter_confidential import create_client, at_least from anonrouter_confidential.gateway.dcap import create_anonrouter_dcap_verifier # pip install "anonrouter-confidential[connection-binding]" (from the GitHub release) with create_client( "https://api.anonrouter.ai", api_key=KEY, control_base_url="https://control.anonrouter.ai", gateway_connection_binding={ "mode": "required", "verification": {"chain_verifier": create_anonrouter_dcap_verifier()}, }, ) as client: verdict = client.verify_route( model="z-ai/glm-5.2", provider="venice", gateway=True ) if not at_least(verdict.overall_state, "cryptographically_checked"): raise SystemExit(f"route not established: {verdict.reason}") ``` -------------------------------- ### Image and speech over the two-origin split (real gateway, your key, BILLABLE) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/examples/README.md Generates an image and synthesizes speech, writing anonrouter-image.png and anonrouter-speech.mp3. One call is two requests to two hosts: the API key mints a content-free ticket at the control origin, then the prompt goes to the confidential origin with only that ticket. The official OpenAI SDK cannot perform this exchange. Makes two real, billable generations. Env: ANONROUTER_IMAGE_MODEL (default alibaba/z-image-turbo), ANONROUTER_SPEECH_MODEL (default venice/kokoro-text-to-speech), ANONROUTER_SPEECH_VOICE, ANONROUTER_BASE_URL, ANONROUTER_CONTROL_URL. ```bash ANONROUTER_API_KEY=ar_... python examples/media.py ``` -------------------------------- ### JavaScript (Node) verification and client setup Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/migrating-to-0.1.3.md Use this TypeScript snippet to perform a read-only verification check and create a client with required gateway connection binding. Requires the native DCAP engine on PATH or in ANONROUTER_DCAP_VERIFIER_BIN; browsers cannot verify hop 1 for api.anonrouter.ai. ```TypeScript import { createClient, verifyContentNode } from "@anonrouter/confidential"; import { createAnonRouterDcapVerifier } from "@anonrouter/confidential/dcap"; // Read-only check, no API key: a fresh nonce on one retained TLS socket. const check = await verifyContentNode(); if (check.verdict.status !== "ok") throw new Error(`gateway: ${check.verdict.reason}`); // Inference: every operation verifies and retains its own socket. const client = createClient({ apiKey: process.env.ANONROUTER_API_KEY!, gatewayConnectionBinding: { mode: "required", verification: { chainVerifier: createAnonRouterDcapVerifier() } } }); ``` -------------------------------- ### Install from monorepo clone with extras Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Install the package from a clone of the monorepo. The connection-binding extra enables verification and E2EE, while mlkem adds the Chutes ML-KEM-768 transport. Requires Python 3.10 or newer. ```bash git clone https://github.com/anonrouter/anonrouter-sdk cd anonrouter-sdk pip install "./python[connection-binding]" # verify (incl. GCP) + NEAR/Venice E2EE + TDX pip install "./python[mlkem]" # adds the Chutes ML-KEM-768 transport ``` -------------------------------- ### Verify a TEE / E2EE route (real gateway, your key, NOT billable) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md Independently verifies a route's enclave attestation against the real gateway, running OUR verifier over the raw evidence. Attestation only, so it does not spend anything. ```bash ANONROUTER_API_KEY=ar_... npm run example:verify-tee ``` -------------------------------- ### Verify published release with npm and anonrouter-verify Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/release-readiness.md Checks npm dist-tags for @anonrouter/confidential and @anonrouter/client, installs version 0.1.3 in a temp project, and runs the anonrouter-verify CLI with DCAP and hardware verification against the production gateway. Compare the registry tarball SHA-256 values with the GitHub release's SHA256SUMS. Do not rebuild or republish version 0.1.3; future release tags need owner approval and the same artifact/live gates. ```bash npm view @anonrouter/confidential dist-tags --json # latest 0.1.3 npm view @anonrouter/client dist-tags --json mkdir -p /tmp/ar013 && cd /tmp/ar013 && npm init -y >/dev/null npm install @anonrouter/confidential@0.1.3 ANONROUTER_DCAP_VERIFIER_BIN=/path/to/anonrouter-dcap-verifier \ npx anonrouter-verify gateway --origin https://api.anonrouter.ai --dcap --require hardware_verified ``` -------------------------------- ### Create client with required gateway connection binding Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Install the package with the connection-binding extra: `pip install "./python[connection-binding]"`. Add `mlkem` to the extras only for Chutes. Other versions and asynchronous transports refuse required mode. This snippet creates a client with `gateway_policy_updates=True` and a required connection binding using a DCAP verifier, then verifies a route. ```python from anonrouter_confidential import create_client from anonrouter_confidential.gateway.dcap import create_anonrouter_dcap_verifier with create_client( api_key="...", gateway_policy_updates=True, gateway_connection_binding={ "mode": "required", "verification": {"chain_verifier": create_anonrouter_dcap_verifier()}, }, ) as client: result = client.verify_route(model="venice-uncensored", provider="venice") ``` -------------------------------- ### Verify a route (hop 2) with verify_attestation Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Creates a client and verifies a provider route's attestation. The result contains an independent NormalizedVerdict; the example asserts status is 'ok' and verification level is 'provider-attested'. ```python from anonrouter_confidential import create_client with create_client( "https://api.anonrouter.ai", api_key="...", control_base_url="https://control.anonrouter.ai", ) as client: result = client.verify_attestation(model="venice-uncensored", provider="venice") verdict = result["verdict"] # OUR independent NormalizedVerdict assert verdict.status == "ok" assert verdict.verification_level == "provider-attested" ``` -------------------------------- ### TypeScript: createAnonRouterDcapVerifier and describeDcapInstallation Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Use to check the installed DCAP engine and to attach the verifier to a gateway for route verification. The adapter fails closed on missing engine, digest mismatch, timeout, crash, non-JSON output, collateral acquisition failure, or report/quote disagreement. Without an engine the ceiling is cryptographically_checked. ```typescript import { createAnonRouterDcapVerifier, describeDcapInstallation } from "@anonrouter/confidential/dcap"; describeDcapInstallation(); // is one installed? which one? what is its digest? const verdict = await client.verifyRoute({ model, provider, gateway: { chainVerifier: createAnonRouterDcapVerifier() } }); ``` -------------------------------- ### verifyGateway() with loadGatewayPolicy Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Pins hop 1 to a reviewed policy loaded from this package. The policy must never come from the gateway itself; an origin with no pin fails closed. The bundled pin is marked published and requires hardware verification, but this package bundles no engine, so verifyGateway() fails closed with reason quote_signature_chain until the separate reproducible engine is installed. ```ts import { loadGatewayPolicy } from "@anonrouter/confidential"; await client.verifyGateway({ policy: loadGatewayPolicy(myReviewedPolicy) }); ``` -------------------------------- ### Image and speech over the two-origin split (real gateway, your key, BILLABLE) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md Generates an image and synthesizes speech, writing anonrouter-image.png and anonrouter-speech.mp3. One call is two requests to two hosts: the API key mints a content-free ticket at the control origin, then the prompt goes to the confidential origin with only that ticket. Makes two real, billable generations. ```bash ANONROUTER_API_KEY=ar_... npm run example:media ``` -------------------------------- ### Full E2EE chat (real gateway, your key, BILLABLE) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/examples/README.md Verifies the enclave, encrypts your prompt in-process, relays only ciphertext, and decrypts the reply. It wraps fetch to PROVE the relay never received your prompt in plaintext, then prints the decrypted answer. Makes a real, tiny billable inference call. ```bash ANONROUTER_API_KEY=ar_... npm run example:chat-e2ee ``` -------------------------------- ### Verify AnonRouter itself (hop 1) with verify_gateway Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Verifies the gateway's attestation. The policy is pinned inside the package; an origin without a pin raises rather than falling back to server claims. The example asserts status is 'ok' and prints the binding's release_id and compose_hash. ```python result = client.verify_gateway() # or policy=... to pin it yourself verdict = result["verdict"] assert verdict.status == "ok" print(verdict.binding.release_id, verdict.binding.compose_hash) ``` -------------------------------- ### Terminal verification commands: doctor, gateway, and exit code check Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Run from a terminal after installing the package. The gateway command is credential-free and requires --dcap and --require hardware_verified. Exit code 0 means met, 1 not met, 2 command itself was wrong. Neither command prints keys, tickets, request content, or raw evidence. ```bash npx anonrouter-verify doctor --origin https://api.anonrouter.ai npx anonrouter-verify gateway --origin https://api.anonrouter.ai --dcap \ --require hardware_verified echo $? # 0 met, 1 not met, 2 the command itself was wrong ``` -------------------------------- ### Set environment variables and run live tests Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Configure live test origins and optional verifier binary, then run the JS and Python test suites. Without an origin, tests skip with a stated reason and never fabricate results; readiness cases still assert that a non-attesting deployment reports 'unavailable'. ```bash export ANONROUTER_LIVE_GATEWAY_ORIGIN=https://your-cvm.example export ANONROUTER_LIVE_PUBLIC_ORIGIN=https://your-non-cvm.example # optional export ANONROUTER_DCAP_VERIFIER_BIN=/path/to/anonrouter-dcap-verifier # optional npm test # JS pytest -q # Python ``` -------------------------------- ### anonrouter-verify doctor Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Runs a diagnostic check on the AnonRouter CLI installation and configuration. Prints a JSON document and exits with a status code indicating success or failure. ```APIDOC ## [CLI] anonrouter-verify doctor ### Description Runs a diagnostic check on the AnonRouter CLI installation and configuration. Prints a JSON document and exits with a status code indicating success or failure. ### Method CLI command ### Endpoint `anonrouter-verify doctor` ### Parameters #### Command Arguments - `--origin` (string) - Required - The base URL of the AnonRouter API. ### Request Example ```bash anonrouter-verify doctor --origin https://api.anonrouter.ai ``` ### Response #### Success Response (0) - **exit code** (integer) - 0 if the check passed, 1 if not met, 2 if the command itself was wrong. #### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Create client and verify route Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Create a client with the AnonRouter API and control URLs, then verify both hops and gate on the result. Requires the ANONROUTER_API_KEY environment variable. The verify_route call uses a DCAP verifier and checks that the overall state is at least 'cryptographically_checked'. ```python import os from anonrouter_confidential import at_least, create_client from anonrouter_confidential.gateway.dcap import create_anonrouter_dcap_verifier client = create_client( base_url="https://api.anonrouter.ai", control_base_url="https://control.anonrouter.ai", api_key=os.environ["ANONROUTER_API_KEY"], ) # Verify BOTH hops and gate on the result. This is the stable contract; see # VERIFYING.md for the five states and what each one does and does not prove. verdict = client.verify_route( model="google/gemma-4-26b-a4b-uncensored", provider="venice", gateway={"chain_verifier": create_anonrouter_dcap_verifier()}, ) if not at_least(verdict.overall_state, "cryptographically_checked"): raise SystemExit(f"route not established: {verdict.reason}") reply = client.chat( model="google/gemma-4-26b-a4b-uncensored", provider="venice", messages=[{"role": "user", "content": "Draft a private message."}], max_output_tokens=512, ) print(reply["content"]) ``` -------------------------------- ### Create client with DCAP verifier and verify route Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Imports createClient, atLeast, and createAnonRouterDcapVerifier. Configures the client with base URLs and an API key, requiring gateway connection binding with a DCAP chain verifier. Verifies both hops and gates on the result, throwing an error if the overall state is not at least 'cryptographically_checked'. The comment references VERIFYING.md for the five states. ```ts import { createClient, atLeast } from "@anonrouter/confidential"; import { createAnonRouterDcapVerifier } from "@anonrouter/confidential/dcap"; const client = createClient({ baseUrl: "https://api.anonrouter.ai", controlBaseUrl: "https://control.anonrouter.ai", apiKey: process.env.ANONROUTER_API_KEY!, gatewayConnectionBinding: { mode: "required", verification: { chainVerifier: createAnonRouterDcapVerifier() } } }); // Verify BOTH hops and gate on the result. This is the stable contract; see // VERIFYING.md for the five states and what each one does and does not prove. const verdict = await client.verifyRoute({ model: "google/gemma-4-26b-a4b-uncensored", provider: "venice", gateway: true }); if (!atLeast(verdict.overallState, "cryptographically_checked")) { throw new Error(`route not established: ${verdict.reason}`); } ``` -------------------------------- ### Download or build the DCAP verifier binary Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Two ways to obtain the verifier engine: download the release asset or build from source with a reproducible build script. The release asset is linux/amd64 and static, with SHA-256 in the release's SHA256SUMS. The build script builds twice from clean in a digest-pinned image and fails unless outputs are byte-identical. ```bash # 1. The release asset. linux/amd64, static, SHA-256 in the release's SHA256SUMS. curl -LO https://github.com/anonrouter/anonrouter-sdk/releases/download/v0.1.1/anonrouter-dcap-verifier-linux-amd64 chmod +x anonrouter-dcap-verifier-linux-amd64 # 2. Your own build of the same source, which is the one that means something. # Builds twice from clean in a digest-pinned image and fails unless the two # outputs are byte-identical. Compare the digest it prints with ours. scripts/build-dcap-verifier.sh --reproduce ``` -------------------------------- ### Python DCAP verifier integration for hardware_verified Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Use `create_anonrouter_dcap_verifier` from `anonrouter_confidential.gateway.dcap` to enable hop 1 to reach `hardware_verified`. Requires the DCAP engine binary on PATH or named in `ANONROUTER_DCAP_VERIFIER_BIN`. ```python from anonrouter_confidential.gateway.dcap import create_anonrouter_dcap_verifier verdict = client.verify_route( model=..., provider=..., gateway={"chain_verifier": create_anonrouter_dcap_verifier()}, ) ``` -------------------------------- ### Verify Content Node with verifyContentNode Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/gateway-policy-updates.md Node-only helper that sends a credential-free attestation GET with a fresh nonce over a normally validated TLS connection. It observes the connection's SPKI, verifies the quote on that socket, and closes it. Requires building the candidate SDK and setting ANONROUTER_DCAP_VERIFIER_BIN. ```typescript import { verifyContentNode } from "@anonrouter/confidential"; const result = await verifyContentNode(); console.log(result.policy.sequence, result.verdict.verificationLevel); ``` -------------------------------- ### anonrouter-verify gateway with custom policy Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Run gateway with your own reviewed policy (any origin) while requiring DCAP and hardware verification. This command is credential-free and does not print keys, tickets, request content, or the raw evidence body. ```bash # Your own reviewed policy (any origin) is still accepted: anonrouter-verify gateway --origin https://your-cvm.example \ --policy ./reviewed-policy.json --dcap --require hardware_verified ``` -------------------------------- ### Load and verify gateway policy with loadGatewayPolicy Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Loads a reviewed gateway policy from a local source and passes it to client.verifyGateway. The policy must never be fetched from the gateway itself; pins ship inside packages or are supplied by you. An origin with no pin fails closed. ```TypeScript import { loadGatewayPolicy } from "@anonrouter/confidential"; await client.verifyGateway({ policy: loadGatewayPolicy(myReviewedPolicy) }); ``` -------------------------------- ### Run the end-to-end self-test Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Runs the full verify plus E2EE chat round trip against an in-process mock gateway. Requires no API key, no network, and spends nothing. ```bash cd js/confidential npm run example:selftest ``` -------------------------------- ### anonrouter-verify route with policy and DCAP Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Run route to add hop 2, reading an API key only from an environment variable; --api-key is refused by name because argv is visible in the process table and lands in shell history. The command does not print a key, ticket, request content, or the raw evidence body. ```bash anonrouter-verify route --origin https://api.anonrouter.ai \ --control-origin https://control.anonrouter.ai --provider venice --model MODEL \ --policy ./reviewed-policy.json --dcap --require cryptographically_checked ``` -------------------------------- ### anonrouter-verify doctor and gateway commands Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Run the doctor command to check the origin, then run gateway with DCAP and hardware verification. For a release-v3 origin without --policy, gateway reports gateway.policy.origin: "signed-release-policy-v3" and gateway.tlsSpki.source: "retained-connection"; without --dcap it reports unavailable. Exit code 0 means the requested assurance was established, 1 means it was not, and 2 means the command or its inputs were wrong. ```bash anonrouter-verify doctor --origin https://api.anonrouter.ai ``` ```bash # GCP: the signed release-v3 feed, one retained socket, native DCAP. anonrouter-verify gateway --origin https://api.anonrouter.ai --dcap --require hardware_verified ``` -------------------------------- ### JavaScript client creation with production defaults Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/ticketed-media.md Creates the AnonRouter client with the API key from the environment. Uses production defaults, so no other configuration is needed. ```typescript // JavaScript — production defaults, so this is the whole configuration. const client = createClient({ apiKey: process.env.ANONROUTER_API_KEY! }); ``` -------------------------------- ### Python client creation with production defaults Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/ticketed-media.md Creates the AnonRouter client with the API key from the environment. Uses the same production defaults as the JavaScript version. ```python # Python — the same defaults. client = create_client(api_key=os.environ["ANONROUTER_API_KEY"]) ``` -------------------------------- ### Run build and bound connection tests Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Run both checks when changing the connection or confidential client. The bound test suite uses a real loopback TLS with a synthetic CA. ```bash cd js/confidential npm run build npm run test:bound ``` -------------------------------- ### create_client() Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Creates an AnonRouter client with the given API key. Production origins are the defaults, so no additional configuration is needed. ```APIDOC ## create_client() ### Description Creates an AnonRouter client with the given API key. Production origins are the defaults, so no additional configuration is needed. ### Method N/A (SDK constructor) ### Endpoint N/A ### Parameters - **api_key** (string) - Required - The AnonRouter API key. ### Request Example ```python from anonrouter_confidential import create_client client = create_client(api_key=os.environ["ANONROUTER_API_KEY"]) ``` ### Response #### Success Response - **client** (object) - An AnonRouter client instance with methods `chat`, `images.generate`, `audio.speech.create`, and `verify_gateway`. ``` -------------------------------- ### Capture gateway pins with capture-gateway-pins.mjs Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/VERIFYING.md Runs the pin capture script against a CVM origin. Prints an observation with a reviewChecklist, not a policy. The output must be corroborated before any value becomes a pin. ```Shell node scripts/capture-gateway-pins.mjs https://your-cvm.example ``` -------------------------------- ### Run retained-operation tests Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Run the primitive retained-operation suite from the repository root. Uses a synthetic native verifier boundary, not hardware attestation or production inference. ```bash node acceptance/run-retained-operation-tests.mjs ``` -------------------------------- ### Run CI parity and smoke gates locally Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Three gates run in CI and can be run locally. The last one, smoke-artifacts.mjs, catches issues invisible to the other gates, such as missing files entries, unresolved exports maps, non-executable bins, or wheels omitting measurement pins. ```bash node scripts/check-parity.mjs # per-package pin copies match shared/ node scripts/check-cli-parity.mjs # both real anonrouter-verify binaries agree node scripts/smoke-artifacts.mjs # every artifact installs into an empty env and works ``` -------------------------------- ### Verify both hops at once with verify_route() and at_least() Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Establishes both hops, cross-binds them to the requested route, and reports ordered states rather than a boolean. The gateway=True argument includes hop 1; omit it to skip hop 1 entirely. overall_state only covers the hops you asked for, so gateway.requested indicates whether hop 1 was in scope. Any entry in binding_mismatches forces the whole verdict untrusted. Gate with at_least() rather than comparing strings because it is the one place the ordering lives. verify() returns the earlier report shape and is still supported; prefer verify_route(). ```python from anonrouter_confidential import at_least verdict = client.verify_route( model="venice-uncensored", provider="venice", gateway=True, # omit to skip hop 1 entirely ) verdict.overall_state # the weakest hop you ASKED about verdict.gateway.requested # whether hop 1 was in scope at all verdict.gateway.state # hardware_verified | ... | unavailable verdict.gateway.failed_checks # the exact required checks that failed verdict.binding_mismatches # the route you asked for vs what was served verdict.content_visible_to_anonrouter # True on a tee route if not at_least(verdict.overall_state, "cryptographically_checked"): raise SystemExit(verdict.reason) ``` -------------------------------- ### verify_route() Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Establishes both hops (gateway and provider) and cross-binds them to the requested route. Returns a verdict object with ordered states and detailed check results. ```APIDOC ## [Python] verify_route() ### Description Establishes both hops (gateway and provider) and cross-binds them to the requested route. Returns a verdict object with ordered states and detailed check results. ### Method Python method ### Endpoint `client.verify_route()` ### Parameters #### Request Body - `model` (string) - Required - The model identifier to verify. - `provider` (string) - Required - The provider name. - `gateway` (boolean) - Optional - Whether to include hop 1 (gateway) verification. Defaults to `False` if omitted. ### Request Example ```python verdict = client.verify_route( model="venice-uncensored", provider="venice", gateway=True, ) ``` ### Response #### Success Response - `overall_state` (string) - The weakest hop state that was asked about. - `gateway.requested` (boolean) - Whether hop 1 was in scope. - `gateway.state` (string) - The state of the gateway hop (e.g., `hardware_verified`, `unavailable`). - `gateway.failed_checks` (array) - The required checks that failed. - `binding_mismatches` (array) - The route asked for vs what was served. - `content_visible_to_anonrouter` (boolean) - True on a tee route. - `reason` (string) - Reason for the verdict (if any). #### Response Example ```python verdict.overall_state verdict.gateway.requested verdict.gateway.state verdict.gateway.failed_checks verdict.binding_mismatches verdict.content_visible_to_anonrouter ``` ``` -------------------------------- ### anonrouter-verify CLI commands for doctor and gateway checks Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Run from a terminal to print one JSON document and exit nonzero unless the requested assurance is established. `gateway` is credential-free; `route` requires an API key from an environment variable only. Exit codes: 0 met, 1 not met, 2 command itself was wrong. ```bash anonrouter-verify doctor --origin https://api.anonrouter.ai anonrouter-verify gateway --origin https://api.anonrouter.ai --dcap \ --require hardware_verified echo $? # 0 met, 1 not met, 2 the command itself was wrong ``` -------------------------------- ### Configure live test environment variables Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/CONTRIBUTING.md Set environment variables to point live tests at a real deployment. The attestation endpoint is credential-free, content-free, and read-only, so no prompt, key, or account identity is sent. The DCAP verifier binary and non-CVM origin are optional. ```bash export ANONROUTER_LIVE_GATEWAY_ORIGIN=https://your-cvm.example export ANONROUTER_LIVE_PUBLIC_ORIGIN=https://your-non-cvm.example # optional export ANONROUTER_DCAP_VERIFIER_BIN=/path/to/anonrouter-dcap-verifier # optional npm test # in js/ pytest -q # in python/ ``` -------------------------------- ### Build the verifier reproducibly with scripts/build-dcap-verifier.sh --reproduce Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/native/README.md Builds the verifier twice from clean inside a registry image pinned by digest and fails unless the two outputs are byte-identical. Prints the SHA-256 to compare against the release asset. Docker is required; nothing else is. ```bash scripts/build-dcap-verifier.sh --reproduce ``` -------------------------------- ### Generate images and speech with anonrouter-confidential (Python) Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/README.md Uses the Python confidential client to generate an image and speech. The API key mints a content-free single-use ticket; the prompt goes to a separate origin. The official OpenAI SDK cannot perform this exchange. ```python client = create_client(api_key=os.environ["ANONROUTER_API_KEY"]) image = client.images.generate(model="alibaba/z-image-turbo", prompt="a lighthouse") open("out.png", "wb").write(image.data[0].data) client.audio.speech.create(model="venice/kokoro-text-to-speech", input="Hello.").write_to("out.mp3") ``` -------------------------------- ### Verify Content Node and Create Client with DCAP Verifier Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Uses the native verifier on PATH or ANONROUTER_DCAP_VERIFIER_BIN; no API key or cost. Requires hardware DCAP, UpToDate TCB, fresh nonce, and retained-socket TLS binding. gce_pzid is optional; absence reports machine identity as unverified, malformed/mismatched identity fails. Inference must retain its own verified connection. ```typescript import { verifyContentNode, createClient } from "@anonrouter/confidential"; import { createAnonRouterDcapVerifier } from "@anonrouter/confidential/dcap"; // Native verifier on PATH or ANONROUTER_DCAP_VERIFIER_BIN. No API key or cost. const result = await verifyContentNode(); console.log(result.policy.sequence, result.verdict.verificationLevel); // Inference must retain its own verified connection. const client = createClient({ apiKey: process.env.ANONROUTER_API_KEY!, gatewayConnectionBinding: { mode: "required", verification: { chainVerifier: createAnonRouterDcapVerifier() } } }); await client.verifyGateway(); // fresh read-only evidence, no credential sent ``` -------------------------------- ### CLI Gateway Verification with DCAP Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Uses the same retained-socket path as the SDK. Without --dcap it reports unavailable. Without connection binding, verifyGateway(), verify(), verifyRoute({ gateway: true }) and gateway-requiring chat() refuse api.anonrouter.ai with unsupported_request before any request. ```bash npx anonrouter-verify gateway --origin https://api.anonrouter.ai --dcap --require hardware_verified ``` -------------------------------- ### Tuple-form policy document with platformKind Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/docs/gateway-platform-tuples.md A policy document with `platformKind` uses the tuple form. It requires native DCAP hardware verification, in-TEE TLS, private logs, digest-pinned images, evidence expiry of at most five minutes, and TCB exactly `UpToDate`. Mixed documents are refused, and unknown fields are rejected. ```json { "platformKind": "gcp-tdx-native", "source": "...", "version": "...", "origins": ["https://..."], "releaseTuples": [{ "tupleId": "release-a@c4-standard-2@fw1", "releaseId": "...", "appId": "<64 hex dm-verity root>", "composeHash": "<64 hex>", "mrTd": "<96 hex>", "rtmr0": "<96 hex>", "rtmr1": "<96 hex>", "rtmr2": "<96 hex>", "tdAttributes": "<16 hex>", "xfam": "<16 hex>", "notBeforeMs": 0, "expiresAtMs": 0 }], "requireInTeeTls": true, "requirePrivateLogs": true, "requireDigestPinnedImages": true, "requireHardwareVerified": true, "acceptableTcbStatuses": ["UpToDate"], "requireEvidenceExpiry": true, "maxEvidenceAgeMs": 300000 } ``` -------------------------------- ### verifyGateway() Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/js/confidential/README.md Verifies hop 1: that the data plane is the exact reviewed build running inside an Intel TDX confidential VM, bound to your nonce and origin. Accepts a policy loaded from the package's pinned gateway policy. ```APIDOC ## verifyGateway() ### Description Verifies hop 1: that the data plane is the exact reviewed build running inside an Intel TDX confidential VM, bound to your nonce and origin. Accepts a policy loaded from the package's pinned gateway policy. ### Method SDK method call ### Endpoint `client.verifyGateway(options)` ### Parameters #### Request Body - **policy** (object) - Required - The gateway policy loaded via `loadGatewayPolicy()`. ### Request Example ```ts import { loadGatewayPolicy } from "@anonrouter/confidential"; await client.verifyGateway({ policy: loadGatewayPolicy(myReviewedPolicy) }); ``` ### Response #### Success Response - **state** (string) - Hardware verification state (e.g., `hardware_verified`, `unavailable`). - **failedChecks** (array) - The exact required checks that failed. #### Error Handling - Fails closed with reason `quote_signature_chain` if the engine is not installed or the quote cannot be chained to Intel's roots. ``` -------------------------------- ### Point the SDK at the verifier with ANONROUTER_DCAP_VERIFIER_BIN and run doctor Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/native/README.md Sets the environment variable to the verifier binary path and runs `anonrouter-verify doctor` against the given origin. `doctor` reports which engine would actually run and its SHA-256. The adapter can also pin the binary via `expectedBinarySha256` / `expected_binary_sha256`. ```bash export ANONROUTER_DCAP_VERIFIER_BIN=/path/to/anonrouter-dcap-verifier anonrouter-verify doctor --origin https://api.anonrouter.ai ``` -------------------------------- ### verify_gateway() Source: https://github.com/anonrouter/anonrouter-sdk/blob/main/python/README.md Verifies that the data plane is the exact reviewed build running inside an Intel TDX confidential VM, bound to the user's nonce and origin. This is part of Hop 1 verification. ```APIDOC ## verify_gateway() ### Description Verifies that the data plane is the exact reviewed build running inside an Intel TDX confidential VM, bound to the user's nonce and origin. This is part of Hop 1 verification. ### Method Function call ### Signature `verify_gateway()` ### Returns - **bool** - True if verification succeeds. ```