Open app
Moonborn — Developers

Rust

The official Rust SDK. Async-first (Tokio), serde-typed, no_std-clean where possible. Ships within a week of every API release.

The Rust SDK is moonborn on crates.io. Generated from the canonical OpenAPI spec; idiomatic Rust — async-first, serde-typed, error-typed.

Install

[dependencies]
moonborn = "1.0"
tokio = { version = "1", features = ["full"] }

First call

use moonborn::{Client, CreatePersonaInput};
use std::env;
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(env::var("MOONBORN_API_KEY")?);
 
    let persona = client.personas().create_persona(CreatePersonaInput {
        intent: "A 34-year-old founder from Istanbul. Brilliant but restless.".into(),
        workspace_id: "ws_...".into(),
        ..Default::default()
    }).await?;
 
    println!("{} {}", persona.id, persona.status);
    Ok(())
}

Streaming

use futures::StreamExt;
 
let mut stream = client.chat().stream_message(StreamMessageInput {
    session_id: session.id.clone(),
    content: "Tell me a quiet truth.".into(),
}).await?;
 
while let Some(chunk) = stream.next().await {
    match chunk? {
        Chunk::Token { delta } => print!("{}", delta),
        Chunk::Completed { drift_score, .. } => println!("\ndrift: {}", drift_score),
    }
}

Error handling

match client.personas().get_persona(GetPersonaInput { id: "persona_...".into() }).await {
    Ok(persona) => { /* ... */ }
    Err(Error::Api(api_err)) if api_err.code == "rate_limited" => {
        tokio::time::sleep(api_err.retry_after).await;
    }
    Err(e) => return Err(e.into()),
}

Tier

Every tier.

Next