🦀
Languages
Use Hanzo AI with Rust
Use Hanzo AI in Rust via the async-openai crate or raw reqwest HTTP calls. Full async support with Tokio, streaming, and type-safe API access.
Base URL: https://api.hanzo.ai/v1
API Key: Get yours at hanzo.ai/signup · Fully OpenAI-compatible · 390+ models available
🦀
Created by Rust Foundation
License: MIT / Apache-2.0 · View source on GitHub →
Hanzo AI is OpenAI-compatible, so existing Rust code works with zero refactoring. We deeply appreciate the Rust Foundation team for building and maintaining this open-source project.
Cargo.toml
toml
[dependencies]
async-openai = "0.26"
tokio = { version = "1", features = ["full"] }async-openai
rust
use async_openai::{config::OpenAIConfig, Client, types::*};
#[tokio::main]
async fn main() {
let config = OpenAIConfig::new()
.with_api_base("https://api.hanzo.ai/v1")
.with_api_key(std::env::var("HANZO_API_KEY").unwrap());
let client = Client::with_config(config);
let request = CreateChatCompletionRequestArgs::default()
.model("zen4-pro")
.messages([ChatCompletionRequestUserMessageArgs::default()
.content("Hello from Rust!")
.build()
.unwrap()
.into()])
.build()
.unwrap();
let response = client.chat().create(request).await.unwrap();
println!("{}", response.choices[0].message.content.as_ref().unwrap());
}reqwest raw HTTP
rust
use reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() {
let client = Client::new();
let resp = client
.post("https://api.hanzo.ai/v1/chat/completions")
.bearer_auth(std::env::var("HANZO_API_KEY").unwrap())
.json(&json!({
"model": "zen4-pro",
"messages": [{"role": "user", "content": "Hello!"}]
}))
.send()
.await
.unwrap();
println!("{}", resp.text().await.unwrap());
}Build and run
bash
export HANZO_API_KEY="your-hanzo-api-key"
cargo build --release
./target/release/my-ai-appReady to get started?
Create a free account and get your API key. 100K API calls/month free forever.