ModelRelay Rust SDK
Async and blocking clients for the ModelRelay API with optional SSE streaming, tracing, and offline mocks.
Install
[]
= "0.3.6"
# blocking-only:
# modelrelay = { version = "0.3.6", default-features = false, features = ["blocking"] }
# blocking with streaming (no Tokio runtime):
# modelrelay = { version = "0.3.6", default-features = false, features = ["blocking", "streaming"] }
# async without streaming:
# modelrelay = { version = "0.3.6", default-features = false, features = ["client"] }
Features
client(default): async reqwest client + Tokio.blocking: blocking reqwest client (no Tokio).streaming(default): SSE streaming for/llm/proxy; opt into NDJSON framing withProxyOptions::with_ndjson_stream()orChatRequestBuilder::ndjson_stream().tracing: optional spans/events around HTTP + streaming.mock: in-memory mock client + fixtures for offline tests.
Quickstart (async)
use ;
async
Structured outputs (response_format)
Request JSON or JSON Schema-constrained responses when the provider supports it:
use ;
# async
Error handling
use ;
async
More examples
- Async streaming + chat builder:
docs/async.md - Blocking usage (streaming + non-streaming):
docs/blocking.md - Tracing + metrics hooks:
docs/telemetry.md - Offline tests with mocks/fixtures:
docs/mocks.md - Auth/frontend tokens and API keys:
docs/auth.md
Quickstart (blocking/CLI)
use ;
Configuration highlights
- Defaults: 5s connect timeout, 60s request timeout (non-streaming), 3 attempts with jittered exponential backoff.
- Per-request overrides via
ProxyOptions(timeout,retry, extra headers/metadata, request IDs). - Predefined environments: production/staging/sandbox or custom base URL. Staging base:
https://api-stg.modelrelay.ai/api/v1.
Environment variables
MODELRELAY_API_KEY— secret key for server-to-server calls.MODELRELAY_PUBLISHABLE_KEY— publishable key for frontend token exchange.MODELRELAY_BASE_URL— override API base URL.