# Kranth — Rust SDK

```bash
cargo add kranth
```

```rust
use kranth::{Kranth, CreateSimRequest};
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Kranth::new("kr_live_…");

    let sim = client.sims().create(&CreateSimRequest {
        idea_text:       "We're launching a paid Rust devtool. $29/mo.".into(),
        persona_count:   50,
        model_id:        "claude-sonnet-4-6".into(),
        training_opt_in: None,
    }).await?;

    let mut stream = client.sims().stream(&sim.sim_id);
    while let Some(ev) = stream.next().await {
        let ev = ev?;
        match ev.kind.as_str() {
            "persona.ready"     => { /* render persona card */ }
            "reaction.complete" => { /* score it */ }
            "sim.complete"      => {
                let report = ev.data.get("report");
                println!("verdict: {report:?}");
                break;
            }
            _ => {}
        }
    }
    Ok(())
}
```

## Resources

- `client.sims().create(&req)` / `.create_with_idempotency_key(&req, key)`
- `client.sims().get(sim_id)` / `.list(&params)` / `.cancel(sim_id)` / `.export(sim_id)`
- `client.sims().stream(sim_id)` — `impl Stream<Item = Result<SimEvent>>`
- `client.recon().create(&req)` / `.get(id)` / `.list()` / `.tiers()` / `.export(id)` / `.stream(id)` — web-grounded research swarm
- `client.debates().create(&req)` / `.get(id)` / `.list()` / `.turns(id)` / `.set_public(id, public)` / `.cancel(id)` / `.export(id)` / `.stream(id)` — adversarial panel
- `client.api_keys().create(name, env)` / `.list()` / `.revoke(id)`
- `client.models().list()`
- `client.billing().usage()` / `.checkout_url(params)` / `.portal_url(return_url)`
- `client.me()`

## Errors

```rust
use kranth::Error;

match client.sims().create(&req).await {
    Err(Error::PaymentRequired { .. }) => { /* top up via billing().checkout_url */ }
    Err(Error::RateLimited { retry_after, .. }) => {
        tokio::time::sleep(std::time::Duration::from_secs_f64(retry_after.unwrap_or(60.0))).await;
    }
    _ => {}
}
```

## Configuration

```rust
use std::time::Duration;

let client = Kranth::builder("kr_live_…")
    .base_url("https://api.kranth.ai")
    .timeout(Duration::from_secs(60))
    .build();
```

Bring your own `reqwest::Client` if you need custom transport:

```rust
let http = reqwest::Client::builder().user_agent("custom/1.0").build()?;
let client = Kranth::builder("kr_live_…").http_client(http).build();
```

## License

Apache-2.0
