Installation
Add brain-db-sdk to a Rust project, set up the Tokio runtime, and verify the install against a running Brain.
Add the crate
cargo add brain-db-sdkOr add it to Cargo.toml by hand:
[dependencies]
brain-db-sdk = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }The crate name is brain-db-sdk; the library you use is brain_db_sdk (Cargo maps the dash to an underscore):
use brain_db_sdk::{Auth, BrainClient, BrainHttpClient};Tokio is required
Both clients are async and run on Tokio. BrainHttpClient is built on reqwest, and BrainClient uses Tokio's TCP stack for the connection. You need a Tokio runtime in scope — the simplest way is the #[tokio::main] macro:
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// ... client calls go here
Ok(())
}The wire codec itself (frame + CBOR encoding under brain_db_sdk::wire) is runtime-agnostic, but every client verb is async and drives Tokio I/O, so a Tokio runtime is mandatory to call them.
Feature flags
The crate has no optional Cargo features — the full surface (both the HTTP and wire clients) is always compiled. reqwest is pulled in with rustls-tls (no OpenSSL / system TLS dependency), so HTTPS to the hosted edge works out of the box with no extra system libraries.
Minimum supported Rust version
The MSRV is Rust 1.75. Older toolchains are not supported.
Verify the install
With a Brain reachable, drop this into src/main.rs and run cargo run:
use brain_db_sdk::BrainHttpClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = BrainHttpClient::localhost("my-api-key");
let who = client.whoami().await?;
println!("connected as agent {} in namespace {:?}", who.agent_id, who.namespace);
Ok(())
}whoami is an idempotent GET, so it is safe to run repeatedly. A successful call prints the identity the server resolved from your key. BrainHttpClient::localhost(...) points at the self-host default http://127.0.0.1:8080.
If the call returns a BrainHttpError with status: 0, the base URL is unreachable (transport failure). A 401 means the key is wrong or expired. See Errors for the full taxonomy.
Was this page helpful?