Skip to main content

Crate zai_rs

Crate zai_rs 

Source
Expand description

§ZAI-RS: Zhipu AI Rust SDK

zai-rs is a type-safe Rust SDK that provides complete support for the Zhipu AI (BigModel) APIs. It offers strongly typed API clients and models for a wide range of AI capabilities including chat, image generation, speech recognition, and text-to-speech.

§Capabilities

  • Chat completions (text, vision, and voice)
  • Image generation
  • Speech-to-text (audio transcription)
  • Text-to-speech (audio synthesis)
  • Tool/function calling integration
  • File management (upload, list, content, delete)
  • Streaming responses via Server-Sent Events (SSE)

§Module Structure

  • client — HTTP client and networking
  • model — Data models, API request/response types
  • file — File management features
  • batches — Batch processing endpoints (list batches)
  • toolkits — Tool calling and execution framework

§Quick Start

use zai_rs::{client::http::*, model::*};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let model = GLM4_5_flash {};
    let key = std::env::var("ZHIPU_API_KEY").unwrap();
    let client = ChatCompletion::new(model, TextMessage::user("Hello"), key);
    let _resp = client.post().await?;
    Ok(())
}

§Features

  • Type safety with compile-time checks to minimize runtime errors
  • Async support powered by Tokio
  • Streaming support for real-time responses
  • Tool integration for function calling and external tools
  • Built-in validation and error handling

Re-exports§

pub use client::error::*;

Modules§

batches
Batch Processing Module
client
HTTP Client Module
file
File Management Module
knowledge
Knowledge Base Module
model
Model Module
tool
Tool Module
toolkits
Toolkits Module

Macros§

define_model_type
Macro for defining AI model types with standard implementations.
impl_message_binding
Macro for binding message types to AI models.
impl_model_markers
Macro for implementing multiple capability traits on model types.