Expand description
Official Rust SDK for TrustedRouter.
The crate keeps inference traffic on the attested API plane and account or
catalog traffic on the control plane. The async Client is the primary
API. Enable the default blocking feature for BlockingClient.
§trusted-router
Official Rust SDK for TrustedRouter.
use trusted_router::{ChatRequest, Client, FAST_MODEL};
#[tokio::main]
async fn main() -> trusted_router::Result<()> {
let client = Client::new(std::env::var("TRUSTEDROUTER_API_KEY").unwrap())?;
let response = client
.chat_completions(ChatRequest::user(FAST_MODEL, "Reply with PONG"))
.await?;
println!("{}", response.choices[0].message.text_content().unwrap_or(""));
Ok(())
}The crate includes async and blocking clients, SSE streaming, Chat Completions, Responses, Messages, embeddings, model and provider catalogs, privacy filters, orchestration builders, OAuth delegation, billing and broadcast helpers, and Google Confidential Space attestation verification.
Receipt verification requires an explicit issuer pin (use
https://api.trustedrouter.com for production TrustedRouter receipts) and
requires request and response traffic bindings by default. The
ReceiptVerificationOptions::require_bindings = false escape hatch is for
intentional signature-only or partial-binding inspection.
See the repository README for the complete guide and C ABI.
Structs§
- Activity
Response - Activity envelope.
- Advisor
Tool Options - Parameters for the Advisor primitive.
- ApiError
- Structured API failure preserving routing/provider attribution.
- Attestation
Policy - Pinned workload values that a gateway attestation must match.
- Attestation
Verification Options - Inputs for offline or live attestation verification.
- Auth
Session Response - Browser session response.
- Blocking
Client - Blocking wrapper around the asynchronous
Client. - Broadcast
Destination - Broadcast destination.
- Broadcast
Destination List - Broadcast destination list.
- Call
Options - Per-call transport overrides.
- Chat
Choice - One non-streaming chat choice.
- Chat
Chunk Choice - One streaming choice.
- Chat
Completion - Non-streaming Chat Completions response.
- Chat
Completion Chunk - Streaming Chat Completions chunk.
- Chat
Delta - Streaming message delta.
- Chat
Message - OpenAI-compatible message supporting text, multimodal content, and tools.
- Chat
Request - Chat Completions request.
- Chat
Usage - Token, caching, cost, and orchestration usage.
- Checkout
Response - Checkout response.
- Client
- Asynchronous
TrustedRouterSDK client. - Client
Builder - Builder for an asynchronous
Client. - Credits
Balance - Credits envelope. Money remains integer/decimal JSON, never an SDK float.
- Document
Verification Options - Inputs for
verify_gateway_attestation_document. - Embedding
Response - Embeddings response.
- Embeddings
Request - Embeddings request.
- Gateway
Attestation - Verified gateway attestation result.
- Gateway
Attestation Document - Result of
verify_gateway_attestation_document. - MapReduce
Tool Options - Parameters for the
MapReduceprimitive. - Messages
Request - Anthropic Messages request.
- Messages
Response - Anthropic Messages response.
- Missing
Attestation Error - Required receipt attestation evidence is absent.
- Missing
Binding Error - Required caller traffic for a receipt digest binding is absent.
- Model
Filters - Model catalog query filters.
- Model
Info - Model catalog entry.
- Model
List - Model catalog envelope.
- OAuth
Authorization - Complete values needed to begin and finish an OAuth flow.
- OAuth
Authorize Options - Options used to build an OAuth authorization URL.
- OAuth
Callback - Captured loopback OAuth callback.
- OAuth
KeyExchange Request - OAuth key exchange request.
- OAuth
KeyExchange Response - OAuth key exchange response.
- OAuth
Loopback - One-shot localhost OAuth callback listener.
- OAuth
Loopback Options - Localhost OAuth callback listener settings.
- OAuth
Pkce Pair - PKCE verifier and S256 challenge.
- Provider
Info - Provider catalog entry.
- Provider
List - Provider catalog envelope.
- Provider
Preferences - Provider routing preferences shared by chat, Responses, messages, and embeddings.
- Receipt
Capture - Wraps a raw byte stream, preserving every chunk and discovering its receipt.
- Receipt
Claims - Fully verified wire-format-v1 receipt claims.
- Receipt
Hash Claims - A verified request or response hash record.
- Receipt
Issuer Error - The receipt issuer is invalid or does not match the caller’s pin.
- Receipt
Model Claims - Model routing claims from a verified receipt.
- Receipt
Upstream Claims - Upstream transport or TEE verification claims.
- Receipt
Verification Options - Inputs to
verify_receipt. - Region
Info - Region entry.
- Region
List - Region catalog envelope.
- Response
Event - Parsed Responses streaming event.
- Response
Input Tokens - Result of
/responses/input_tokens. - Response
Object - Responses API result. Output items remain typed JSON for protocol evolution.
- Responses
Request OpenAIResponses request with forward-compatible fields.- Selector
Tool Options - Parameters for the Selector primitive.
- SseEvent
- Parsed server-sent event.
- Subagent
Tool Options - Parameters for the Subagent primitive.
- Synth
Tool Options - Parameters for the Synth primitive.
- Trust
Release - Signed public release metadata used to pin the attested image.
- Trust
Release Data Policy - Prompt and control-plane commitments in the trust release.
- Trust
Release Tls - TLS metadata in the signed public trust release.
- Unsupported
Attestation Error - The receipt uses an attestation kind this SDK cannot verify.
- User
Info Response - OAuth-style user-info envelope.
Enums§
- Attestation
Binding - What a verified attestation proves about the connection the caller’s requests travel over, weakest first.
- Error
- Error returned by the SDK.
- Error
Kind - HTTP/API error classification.
- Plane
- API plane selected for a request.
- Receipt
Attestation Status - Whether attestation evidence was verified by this SDK.
- Receipt
Verification Error - Common, typed error taxonomy for all fail-closed receipt checks.
- Selection
Strategy - Synth answer-selection behavior.
Constants§
- ADVISOR_
MODEL - Advisor orchestration primitive.
- ALIAS_
API_ BASE_ URLS - Exact aliases of
DEFAULT_API_BASE_URL, on separate domains served by separate DNS providers (trustedrouter.com from Google Cloud DNS, these two from Route 53). They resolve to the same attested enclaves. - ATHENA_
MODEL - Private-configuration Athena alias.
- AUTO_
MODEL - Automatic non-orchestration model routing.
- CONFIDENTIAL_
MODEL - Alias for
E2E_MODEL. - DEFAULT_
API_ BASE_ URL - Attested inference API base URL.
- DEFAULT_
CONTROL_ BASE_ URL - Dashboard and account control-plane API base URL.
- DEFAULT_
MAX_ RETRIES - Number of retries after the initial request.
- DEFAULT_
ORCHESTRATION_ TIMEOUT - Default orchestration timeout.
- DEFAULT_
REQUEST_ TIMEOUT - Default per-attempt request timeout.
- DEFAULT_
STATUS_ URL - Public status JSON document.
- DEFAULT_
TELEMETRY_ PATH - Control-plane ingest path for the telemetry beacon channel (contract v1
§4): batches are
POSTed to{control_base_url}/client-events. - DEFAULT_
TRUST_ RELEASE_ URL - Public signed trust-release document.
- E2E_
MODEL - Provider-side confidential-compute and end-to-end-encrypted pool.
- EU_
MODEL - EU-focused provider pool.
- EXPORTER_
LABEL - RFC 9266 channel-binding label committed by the gateway.
- EXPORTER_
LENGTH - Required TLS exporter length.
- FAST_
MODEL - Lowest-latency healthy routing pool.
- FUSION_
MODEL - Legacy alias for
SYNTH_MODEL. - GCP_
ISSUER - Issuer used by Google Confidential Space attestation JWTs.
- GCP_
JWKS_ URL - Public Google JWKS for Confidential Space workload attestations.
- MAP_
REDUCE_ MODEL - Map-reduce orchestration primitive.
- PROMETHEUS_
MODEL - Stable Prometheus model alias.
- SELECTOR_
MODEL - Selector orchestration primitive.
- SOCRATES_
MODEL - Stable Socrates model alias.
- SUBAGENT_
MODEL - Subagent orchestration primitive.
- SYNTH_
FREEDOM_ FALLBACK_ FINALS - Recommended fallback synthesizer chain.
- SYNTH_
FREEDOM_ FALLBACK_ JUDGES - Recommended fallback judge chain.
- SYNTH_
FREEDOM_ PANEL - Recommended permissive open-model Synth panel.
- SYNTH_
MODEL - Synth orchestration primitive.
- TELEMETRY_
BACKOFF_ MAX_ SECONDS - Ceiling on the beacon backoff and on an honoured
Retry-After(§6.2). - TELEMETRY_
BACKOFF_ MIN_ SECONDS - Initial beacon backoff after a 429/503 or transport failure (§6.2).
- TELEMETRY_
ENDPOINTS - Closed telemetry endpoint vocabulary (contract v1 §5.2).
- TELEMETRY_
ERROR_ CLASSES - Closed telemetry transport-error class vocabulary (contract v1 §5.2).
- TELEMETRY_
FINAL_ OUTCOMES - Closed telemetry final-outcome vocabulary (contract v1 §5.2): every
per-attempt outcome plus
exhausted. - TELEMETRY_
FLUSH_ SECONDS - Beacon flush interval in seconds (§6.2). The server may only lengthen it.
- TELEMETRY_
HOSTS - Closed telemetry host vocabulary (contract v1 §5.2).
- TELEMETRY_
LATENCY_ BUCKETS - Closed telemetry latency-bucket vocabulary (contract v1 §5.2); upper bounds in milliseconds, exclusive.
- TELEMETRY_
MAX_ BATCH_ COUNTERS - Maximum per-minute counters per beacon batch (§4).
- TELEMETRY_
MAX_ BATCH_ EVENTS - Maximum events per beacon batch (§4).
- TELEMETRY_
MAX_ EVENTS - Maximum buffered sampled events per process (§6.2); the oldest success, then the oldest failure, is dropped past it and every drop is counted.
- TELEMETRY_
MAX_ WINDOW_ KEYS - Maximum distinct counter keys per minute window (§5.4); a new key past the cap folds into a coarser existing key so counts stay exact.
- TELEMETRY_
OUTCOMES - Closed telemetry per-attempt outcome vocabulary (contract v1 §5.2).
- TELEMETRY_
RETENTION_ BYTES - Byte cap on retained closed minute windows (§6.2); the oldest window is dropped first.
- TELEMETRY_
RETENTION_ SECONDS - How long closed minute windows are retained while the control plane is unreachable (§4), in seconds.
- TELEMETRY_
SCHEMA_ VERSION - Client-telemetry contract schema version implemented by this SDK.
- TELEMETRY_
TIMEOUT_ PHASES - Closed telemetry timeout-phase vocabulary (contract v1 §5.2).
- US_
MODEL - US-jurisdiction provider pool.
- VERSION
- Crate version.
- ZDR_
MODEL - Zero-data-retention routing pool.
- ZEUS_
MODEL - Stable Zeus model alias.
Functions§
- advisor_
tool - Builds a
trustedrouter:advisortool. - create_
pkce_ pair - Creates or derives a PKCE S256 pair.
- map_
reduce_ tool - Builds a
trustedrouter:mapreducetool. - messages_
to_ values - Convenience conversion for arbitrary JSON messages.
- policy_
from_ trust_ release - Builds a fail-closed policy from a trust release.
- random_
oauth_ state - Generates an opaque URL-safe anti-CSRF state token.
- selector_
tool - Builds a
trustedrouter:selectortool. - subagent_
tool - Builds a
trustedrouter:subagenttool. - synth_
tool - Builds a
trustedrouter:fusiontool accepted by both Synth and Fusion aliases. - verify_
gateway_ attestation - Verifies a Google-signed Confidential Space JWT and every
TrustedRouterpin. - verify_
gateway_ attestation_ document - Verifies a gateway attestation document on its own, with no TLS binding.
- verify_
receipt - Verifies a compact or flattened inference receipt and returns typed claims.
Type Aliases§
- Json
Stream - Stream of arbitrary JSON payloads.
- Receipt
Result - Result type returned by receipt verification.
- Response
Event Stream - Stream of Responses API lifecycle events.
- Result
- SDK result type.
- SseStream
- Stream of raw parsed SSE events.
- Text
Stream - Stream of visible chat text deltas.