ModelRelay Rust SDK
[]
= "0.32.0"
API Matrix
All four combinations of async/blocking × streaming/non-streaming are supported:
| Mode | Non-Streaming | Streaming | Structured Streaming |
|---|---|---|---|
| Async | .send(&client) |
.stream(&client) |
.stream_json::<T>(&client) |
| Blocking | .send_blocking(&client) |
.stream_blocking(&client) |
.stream_json_blocking::<T>(&client) |
Both ChatRequestBuilder and CustomerChatRequestBuilder support all methods.
Use cases:
- Async + Streaming (default): Real-time UIs, chatbots, lowest latency to first token
- Async + Non-Streaming: Async backends where you don't need progressive output
- Blocking + Streaming: CLI tools with live output, sync apps needing progressive display
- Blocking + Non-Streaming: Scripts, CLI tools, sync backends without Tokio
- Structured Streaming: Progressive UI rendering with typed JSON payloads
Streaming Chat
use ;
async
Structured Outputs
use JsonSchema;
use ;
let result = new
.user
.
.max_retries
.send
.await?;
println!;
Streaming Structured Outputs
Build progressive UIs that render fields as they complete:
let mut stream = new
.user
.
.await?;
while let Some = stream.next.await?
Customer-Attributed Requests
For metered billing, use for_customer() — the customer's tier determines the model:
let response = client.llm
.for_customer
.user
.send
.await?;
Customer Structured Streaming
Stream structured JSON for customer-attributed requests:
let mut stream = client.llm
.for_customer
.user
.response_format
.
.await?;
while let Some = stream.next.await?
// Or collect the final result
let result = stream.collect.await?;
Customer Management (Backend)
// Create/update customer
let customer = client.customers.upsert.await?;
// Create checkout session for subscription billing
let session = client.customers.create_checkout_session.await?;
// Check subscription status
let status = client.customers.get_subscription.await?;
Configuration
let client = new?;
Features
client(default): async reqwest + Tokioblocking: blocking client (no Tokio)streaming(default): SSE streamingtracing: spans/events for observabilitymock: in-memory client for tests