Beato Docs

Rust

Beato API client and runnable example for Rust.

Download the Rust SDK

Run the example

Extract the archive and run these commands inside its directory. The example lists public models by default. To submit a job, set BEATO_API_KEY and BEATO_IDEMPOTENCY_KEY in your environment.

cargo run --locked --example generate

Example source

use beato_api::{Beato, JobInput};
use std::{env, thread, time::Duration};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let base = env::var("BEATO_API_BASE_URL").ok();
    let client = Beato::new(env::var("BEATO_API_KEY").unwrap_or_default(), base.as_deref())?;
    let key = env::var("BEATO_IDEMPOTENCY_KEY").unwrap_or_default();
    if key.is_empty() {
        println!("{:#?}", client.models()?);
        return Ok(());
    }
    let input = JobInput {
        model: "nano-banana", prompt: "A watercolor of a rainy street", aspect_ratio: None, asset_id: None,
    };
    let mut job = client.create_job(&input, &key)?;
    for _ in 0..60 {
        if matches!(job.status.as_str(), "succeeded" | "failed") { break; }
        thread::sleep(Duration::from_secs(5));
        job = client.get_job(&job.id)?;
    }
    println!("{job:#?}");
    Ok(())
}