Skip to main content

Crate trusted_router

Crate trusted_router 

Source
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§

ActivityResponse
Activity envelope.
AdvisorToolOptions
Parameters for the Advisor primitive.
ApiError
Structured API failure preserving routing/provider attribution.
AttestationPolicy
Pinned workload values that a gateway attestation must match.
AttestationVerificationOptions
Inputs for offline or live attestation verification.
AuthSessionResponse
Browser session response.
BlockingClient
Blocking wrapper around the asynchronous Client.
BroadcastDestination
Broadcast destination.
BroadcastDestinationList
Broadcast destination list.
CallOptions
Per-call transport overrides.
ChatChoice
One non-streaming chat choice.
ChatChunkChoice
One streaming choice.
ChatCompletion
Non-streaming Chat Completions response.
ChatCompletionChunk
Streaming Chat Completions chunk.
ChatDelta
Streaming message delta.
ChatMessage
OpenAI-compatible message supporting text, multimodal content, and tools.
ChatRequest
Chat Completions request.
ChatUsage
Token, caching, cost, and orchestration usage.
CheckoutResponse
Checkout response.
Client
Asynchronous TrustedRouter SDK client.
ClientBuilder
Builder for an asynchronous Client.
CreditsBalance
Credits envelope. Money remains integer/decimal JSON, never an SDK float.
DocumentVerificationOptions
Inputs for verify_gateway_attestation_document.
EmbeddingResponse
Embeddings response.
EmbeddingsRequest
Embeddings request.
GatewayAttestation
Verified gateway attestation result.
GatewayAttestationDocument
Result of verify_gateway_attestation_document.
MapReduceToolOptions
Parameters for the MapReduce primitive.
MessagesRequest
Anthropic Messages request.
MessagesResponse
Anthropic Messages response.
MissingAttestationError
Required receipt attestation evidence is absent.
MissingBindingError
Required caller traffic for a receipt digest binding is absent.
ModelFilters
Model catalog query filters.
ModelInfo
Model catalog entry.
ModelList
Model catalog envelope.
OAuthAuthorization
Complete values needed to begin and finish an OAuth flow.
OAuthAuthorizeOptions
Options used to build an OAuth authorization URL.
OAuthCallback
Captured loopback OAuth callback.
OAuthKeyExchangeRequest
OAuth key exchange request.
OAuthKeyExchangeResponse
OAuth key exchange response.
OAuthLoopback
One-shot localhost OAuth callback listener.
OAuthLoopbackOptions
Localhost OAuth callback listener settings.
OAuthPkcePair
PKCE verifier and S256 challenge.
ProviderInfo
Provider catalog entry.
ProviderList
Provider catalog envelope.
ProviderPreferences
Provider routing preferences shared by chat, Responses, messages, and embeddings.
ReceiptCapture
Wraps a raw byte stream, preserving every chunk and discovering its receipt.
ReceiptClaims
Fully verified wire-format-v1 receipt claims.
ReceiptHashClaims
A verified request or response hash record.
ReceiptIssuerError
The receipt issuer is invalid or does not match the caller’s pin.
ReceiptModelClaims
Model routing claims from a verified receipt.
ReceiptUpstreamClaims
Upstream transport or TEE verification claims.
ReceiptVerificationOptions
Inputs to verify_receipt.
RegionInfo
Region entry.
RegionList
Region catalog envelope.
ResponseEvent
Parsed Responses streaming event.
ResponseInputTokens
Result of /responses/input_tokens.
ResponseObject
Responses API result. Output items remain typed JSON for protocol evolution.
ResponsesRequest
OpenAI Responses request with forward-compatible fields.
SelectorToolOptions
Parameters for the Selector primitive.
SseEvent
Parsed server-sent event.
SubagentToolOptions
Parameters for the Subagent primitive.
SynthToolOptions
Parameters for the Synth primitive.
TrustRelease
Signed public release metadata used to pin the attested image.
TrustReleaseDataPolicy
Prompt and control-plane commitments in the trust release.
TrustReleaseTls
TLS metadata in the signed public trust release.
UnsupportedAttestationError
The receipt uses an attestation kind this SDK cannot verify.
UserInfoResponse
OAuth-style user-info envelope.

Enums§

AttestationBinding
What a verified attestation proves about the connection the caller’s requests travel over, weakest first.
Error
Error returned by the SDK.
ErrorKind
HTTP/API error classification.
Plane
API plane selected for a request.
ReceiptAttestationStatus
Whether attestation evidence was verified by this SDK.
ReceiptVerificationError
Common, typed error taxonomy for all fail-closed receipt checks.
SelectionStrategy
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:advisor tool.
create_pkce_pair
Creates or derives a PKCE S256 pair.
map_reduce_tool
Builds a trustedrouter:mapreduce tool.
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:selector tool.
subagent_tool
Builds a trustedrouter:subagent tool.
synth_tool
Builds a trustedrouter:fusion tool accepted by both Synth and Fusion aliases.
verify_gateway_attestation
Verifies a Google-signed Confidential Space JWT and every TrustedRouter pin.
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§

JsonStream
Stream of arbitrary JSON payloads.
ReceiptResult
Result type returned by receipt verification.
ResponseEventStream
Stream of Responses API lifecycle events.
Result
SDK result type.
SseStream
Stream of raw parsed SSE events.
TextStream
Stream of visible chat text deltas.