Quick setup examples
Rust (HTTP) Quickstart
Call the Unison brain from Rust using reqwest and serde_json — async, minimal boilerplate.
Add the dependencies to Cargo.toml, then use the async reqwest client. All requests carry your token read from the environment.
Prerequisites
export UNISON_TOKEN=usk_live_...# Cargo.toml
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }Recall — fetch prompt-ready context
use reqwest::Client;
use serde::Deserialize;
use std::env;
#[derive(Deserialize)]
struct ContextResponse {
#[serde(rename = "weakEvidence")]
weak_evidence: bool,
#[serde(rename = "contextMd")]
context_md: String,
}
async fn recall(query: &str) -> Result<String, reqwest::Error> {
let token = env::var("UNISON_TOKEN").expect("UNISON_TOKEN not set");
let client = Client::new();
let resp: ContextResponse = client
.get("https://brain.unisonlabs.ai/v1/brain/context")
.bearer_auth(&token)
.query(&[("q", query), ("k", "5"), ("mode", "auto")])
.send()
.await?
.json()
.await?;
if resp.weak_evidence {
Ok(String::new())
} else {
Ok(resp.context_md)
}
}
#[tokio::main]
async fn main() {
let memory = recall("payment service architecture").await.unwrap();
println!("{}", memory);
}Persist — write memory to the brain
use reqwest::Client;
use serde_json::json;
use std::env;
async fn persist() -> Result<(), reqwest::Error> {
let token = env::var("UNISON_TOKEN").expect("UNISON_TOKEN not set");
let client = Client::new();
let body = json!({
"items": [
{
"type": "conversation",
"turns": [
{ "role": "user", "content": "What queue library should we use?" },
{ "role": "assistant", "content": "Switched to pgmq — simpler ops than Redis." }
],
"sourceRef": "session-1",
"visibility": "private"
}
]
});
let resp: serde_json::Value = client
.post("https://brain.unisonlabs.ai/v1/brain/ingest")
.bearer_auth(&token)
.json(&body)
.send()
.await?
.json()
.await?;
println!("jobId: {}", resp["items"][0]["jobId"]);
Ok(())
}