IntegrationRust

Integrate Multiple LLM APIs in Rust with One Crate

Use the official LLMWise Rust crate to call multiple AI models with one API key. Async/await on tokio, zero-copy SSE streaming, serde-typed models, and built-in failover.

Credit-based pay-per-use with token-settled billing. No monthly subscription. Paid credits never expire.

Replace multiple AI subscriptions with one wallet that includes routing, failover, and optimization.

Why teams start here first
No monthly subscription
Pay-as-you-go credits
Start with trial credits, then buy only what you consume.
Failover safety
Production-ready routing
Auto fallback across providers when latency, quality, or reliability changes.
Data control
Your policy, your choice
BYOK and zero-retention mode keep training and storage scope explicit.
Single API experience
One key, multi-provider access
Use Chat/Compare/Blend/Judge/Failover from one dashboard.
Quick start
# Cargo.toml
[dependencies]
llmwise = "0.1"
tokio = { version = "1", features = ["full"] }
serde_json = "1"

Full example

Rust
// cargo add llmwise tokio serde_json
use llmwise::{Client, ChatRequest, Message};
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), llmwise::Error> {
    let client = Client::new(
        std::env::var("LLMWISE_API_KEY")
            .expect("LLMWISE_API_KEY must be set"),
    );

    // Basic chat request
    let response = client
        .chat(&ChatRequest {
            model: "auto".into(),
            messages: vec![
                Message::user("Explain ownership and borrowing in Rust."),
            ],
            max_tokens: Some(512),
            ..Default::default()
        })
        .await?;

    println!("{}", response.content);

    // Streaming chat with async Stream
    let mut stream = client
        .chat_stream(&ChatRequest {
            model: "claude-sonnet-4.5".into(),
            messages: vec![
                Message::user("Write an async TCP echo server in Rust."),
            ],
            stream: Some(true),
            ..Default::default()
        })
        .await?;

    while let Some(event) = stream.next().await {
        let event = event?;
        if let Some(delta) = &event.delta {
            print!("{delta}");
        }
        if event.done {
            println!("\nCredits charged: {}", event.credits_charged.unwrap_or(0));
            break;
        }
    }

    Ok(())
}
Evidence snapshot

Rust integration overview

Everything you need to integrate LLMWise's multi-model API into your Rust project.

Setup steps
6
to first API call
Features
8
capabilities included
Models available
9
via single endpoint
Starter credits
20
free credits never expire

What you get

+Official LLMWise Rust crate with async/await on tokio runtime
+Zero-copy SSE streaming via tokio-stream (Stream + StreamExt)
+Typed request and response structs with serde Serialize/Deserialize
+Mesh failover routing with automatic retry on 429/5xx/timeouts
+Connection pooling via reqwest with hyper HTTP/2 backend
+Compile-time guarantees with exhaustive enums for models and modes
+WASM-compatible build target for browser and edge runtimes
+Structured error types with thiserror for ergonomic error handling

Step-by-step integration

1Add the LLMWise crate to Cargo.toml

Add the official llmwise crate along with tokio for async runtime. Requires Rust 1.75+ (async fn in trait stabilization).

# Cargo.toml
[dependencies]
llmwise = "0.1"
tokio = { version = "1", features = ["full"] }
2Set your LLMWise API key

Store your API key as an environment variable. The client reads it at construction time.

export LLMWISE_API_KEY="your_api_key_here"
3Create a client instance

Build the client with your API key. It uses reqwest internally with connection pooling enabled by default.

use llmwise::Client;

let client = Client::new(
    std::env::var("LLMWISE_API_KEY").expect("LLMWISE_API_KEY required"),
);
4Send a basic chat request

Call client.chat() with a ChatRequest struct. Fields use Option types with Default trait for optional parameters.

use llmwise::{ChatRequest, Message};

let response = client
    .chat(&ChatRequest {
        model: "gemini-3-flash".into(),
        messages: vec![
            Message::user("What are Rust's zero-cost abstractions?"),
        ],
        max_tokens: Some(512),
        ..Default::default()
    })
    .await?;

println!("{}", response.content);
5Stream tokens with async Stream

Use client.chat_stream() to get an async Stream of SSE events. Process with StreamExt::next() in a while-let loop for zero-copy iteration.

use tokio_stream::StreamExt;

let mut stream = client
    .chat_stream(&ChatRequest {
        model: "deepseek-v3".into(),
        messages: vec![Message::user("Implement a lock-free queue in Rust.")],
        stream: Some(true),
        ..Default::default()
    })
    .await?;

while let Some(event) = stream.next().await {
    let event = event?;
    if let Some(delta) = &event.delta {
        print!("{delta}");
    }
    if event.done { break; }
}
6Use Compare mode for multi-model evaluation

Send the same prompt to multiple models and compare their outputs. Responses are returned as a Vec of typed CompareResponse structs.

use llmwise::CompareRequest;

let response = client
    .compare(&CompareRequest {
        models: vec!["gpt-5.2".into(), "claude-sonnet-4.5".into(), "gemini-3-flash".into()],
        messages: vec![
            Message::user("Explain the borrow checker to a C++ developer."),
        ],
        ..Default::default()
    })
    .await?;

for r in &response.responses {
    println!("[{}]: {}\n", r.model, r.content);
}

Common questions

Does the Rust crate support async/await?
Yes. The crate is built on tokio and reqwest. All network operations are async. Streaming uses tokio-stream's Stream trait so you can compose with other async combinators like map, filter, and timeout.
Can I use the crate in WASM?
Yes. The crate supports a wasm32-unknown-unknown target by using reqwest's WASM feature. Streaming in WASM uses the browser's Fetch API under the hood. Enable the wasm feature flag in Cargo.toml.
How are errors handled?
The crate uses a custom llmwise::Error type built with thiserror. Variants include ApiError (with status code and message), NetworkError, ParseError, and TimeoutError. Use pattern matching for exhaustive handling.
What Rust toolchain version is required?
Rust 1.75 or later is recommended for async fn in trait support. The crate compiles on stable Rust with no nightly features required. MSRV is tested in CI.

One wallet, enterprise AI controls built in

Credit-based pay-per-use with token-settled billing. No monthly subscription. Paid credits never expire.

Replace multiple AI subscriptions with one wallet that includes routing, failover, and optimization.

Chat, Compare, Blend, Judge, MeshPolicy routing + replay labFailover without extra subscriptions
Get LLM insights in your inbox

Pricing changes, new model launches, and optimization tips. No spam.