Rust SDK

Official Rust SDK for Tenzro Cloud. High-performance async client built on Tokio.

Installation

cargo add tenzro
# or add to Cargo.toml:
[dependencies]
tenzro = "1.0"
tokio = { version = "1", features = ["full"] }

Quick Start

use tenzro::{Tenzro, TenzroConfig};
#[tokio::main]
async fn main() -> Result<(), tenzro::Error> {
let config = TenzroConfig::builder()
.api_key(std::env::var("TENZRO_API_KEY")?)
.build()?;
let tenzro = Tenzro::new(config)?;
// AI chat completion
let response = tenzro.ai().chat()
.model("gemini-2.5-flash")
.message("user", "Hello!")
.send()
.await?;
println!("{}", response.response_text);
Ok(())
}

Vector Database

use tenzro::vec::VectorEntry;
use serde_json::json;
// Create vector database
let db = tenzro.vec().create()
.project_id("project-id")
.db_name("embeddings")
.dimension(1536)
.send()
.await?;
// Insert vectors
tenzro.vec().upsert(&db.vec_db_id)
.vector(VectorEntry {
id: "doc-1".into(),
vector: embedding,
metadata: json!({ "title": "Document 1" }),
})
.send()
.await?;
// Search vectors
let results = tenzro.vec().search(&db.vec_db_id)
.vector(query_embedding)
.top_k(10)
.send()
.await?;

Key-Value Store

use std::time::Duration;
// Set value with TTL
tenzro.kev().set(&kev_db_id, "session:123")
.value(&user_data)
.ttl(Duration::from_secs(3600))
.send()
.await?;
// Get value
let session: UserData = tenzro.kev()
.get(&kev_db_id, "session:123")
.send()
.await?;
// Delete value
tenzro.kev().delete(&kev_db_id, "session:123")
.send()
.await?;

AI Agents

// Create agent
let agent = tenzro.agents().create()
.project_id("project-id")
.agent_name("assistant")
.system_prompt("You are a helpful assistant.")
.ai_model("gemini-2.5-flash")
.send()
.await?;
// Chat with agent
let response = tenzro.agents().chat(&agent.agent_id)
.message("Hello!")
.conversation_id("conv-123")
.send()
.await?;
println!("{}", response.response);

Streaming

use futures::StreamExt;
// Stream AI responses
let mut stream = tenzro.ai().stream()
.model("gemini-2.5-flash")
.message("user", "Write a story")
.send()
.await?;
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
print!("{}", chunk.text);
}

Error Handling

use tenzro::{Error, ApiError};
match tenzro.ai().chat().model("gemini-2.5-flash").send().await {
Ok(response) => println!("{}", response.response_text),
Err(Error::Authentication(msg)) => {
eprintln!("Invalid API key: {}", msg);
}
Err(Error::RateLimit { retry_after }) => {
eprintln!("Rate limited, retry after: {:?}", retry_after);
}
Err(Error::Api(e)) => {
eprintln!("API error {}: {}", e.status, e.message);
}
Err(e) => eprintln!("Error: {}", e),
}

Builder Pattern

All operations use the builder pattern for type-safe request construction:

// Configure client with custom settings
let config = TenzroConfig::builder()
.api_key(api_key)
.base_url("https://api.tenzro.com")
.timeout(Duration::from_secs(30))
.max_retries(3)
.build()?;
let tenzro = Tenzro::new(config)?;
// Fluent API for requests
let response = tenzro.ai().chat()
.model("gemini-2.5-flash")
.message("system", "You are a helpful assistant")
.message("user", "What is Rust?")
.temperature(0.7)
.max_tokens(1000)
.send()
.await?;

Available Services

ServiceDescription
tenzro.ai()AI inference (chat, embeddings, multi-modal)
tenzro.agents()AI agent orchestration with tools and memory
tenzro.vec()Vector database for embeddings and similarity search
tenzro.kev()Key-value store for sessions, cache, and state
tenzro.data()PostgreSQL databases for structured data
tenzro.graph()Graph database for relationships and traversals
tenzro.files()Object storage for files and media
tenzro.workflows()Visual workflow execution
tenzro.hub()Model hub for browsing and downloading models
tenzro.enclaves()Secure enclaves for sensitive data
tenzro.security()Cryptographic operations and key management

Related