Expand description
§baochuan — 宝船
baochuan (Bǎochuán, 宝船 — “Treasure Ship”) is a multi-provider AI API client for Rust. Just as Admiral Zheng He’s colossal treasure ships sailed from China to connect civilizations across the Indian Ocean, baochuan carries your Rust code to every major AI provider through a single, unified interface.
The companion Java library, ZhengHe, is named after the explorer who introduced China to Java (the island) — a fitting metaphor for connecting Java to the DeepSeek API. baochuan continues that voyage, this time in Rust, with a fleet of providers.
§Quickstart
use baochuan::{providers::DeepSeekProvider, ChatMessage, ChatRequestBuilder, Provider};
#[tokio::main]
async fn main() {
let provider = DeepSeekProvider::new(
std::env::var("DEEPSEEK_API_KEY").expect("DEEPSEEK_API_KEY not set"),
);
let request = ChatRequestBuilder::new("deepseek-chat")
.message(ChatMessage::user("Tell me about the treasure ships of Zheng He."))
.max_tokens(512)
.build()
.unwrap();
let response = provider.chat(&request).await.unwrap();
println!("{}", response.content().unwrap_or(""));
}Re-exports§
pub use error::BaochuanError;pub use provider::Provider;pub use types::AudioInput;pub use types::AudioOutput;pub use types::AudioOutputConfig;pub use types::ChatMessage;pub use types::ChatRequest;pub use types::ChatRequestBuilder;pub use types::ChatResponse;pub use types::ContentPart;pub use types::DocumentInput;pub use types::FunctionCall;pub use types::FunctionDefinition;pub use types::ImageUrl;pub use types::MessageContent;pub use types::ModelInfo;pub use types::Role;pub use types::Tool;pub use types::ToolCall;pub use types::ToolChoice;pub use types::TtsRequest;pub use types::TtsRequestBuilder;pub use types::Usage;