Skip to main content

Crate minimax_client

Crate minimax_client 

Source
Expand description

An async Rust client for the MiniMax APIs.

Everything goes through MinimaxClient, which owns a reqwest::Client internally. Keep one instance alive for the lifetime of your program so connections are reused; cloning it is cheap and shares the same pool.

§Capabilities

§Quick start

use futures_util::StreamExt;
use minimax_client::{types::TtsRequest, MinimaxClient};

let client = MinimaxClient::from_env()?;

let request = TtsRequest {
    text: "Hello, world!".into(),
    ..Default::default()
};

let mut stream = client.tts_stream(&request);
while let Some(chunk) = stream.next().await {
    let pcm = chunk?; // raw PCM i16 little-endian at 32 kHz
    println!("received {} bytes", pcm.len());
}

§Streaming behavior

The streaming methods spawn a background Tokio task, so they must be called from within a runtime and the request begins before the stream is first polled. Chunks are buffered in an unbounded queue, which keeps the HTTP connection draining even when the consumer falls behind; if you cannot keep up with real time, write chunks to disk rather than holding them in memory. Dropping the stream stops the background task at the next chunk boundary.

§Error handling

Every method returns Result<T, Error>. Error distinguishes transport failures from MiniMax’s own base_resp codes, and offers is_auth_error, is_rate_limited, and is_retryable so you can branch without matching on numeric codes:

match client.tts_synthesize(&request).await {
    Ok(result) => println!("{} bytes", result.audio_bytes.len()),
    Err(e) if e.is_rate_limited() => println!("slow down: {e}"),
    Err(e) if e.is_auth_error() => println!("check your API key: {e}"),
    Err(e) => println!("failed: {e}"),
}

§TLS

The rustls-tls feature is enabled by default. To link against the platform’s TLS stack instead, disable default features and enable native-tls.

Re-exports§

pub use error::Error;
pub use error::Result;

Modules§

error
Error types returned by this crate.
types
Request and response types for every endpoint.

Structs§

LyricsWithMusicStream
Lyrics paired with the audio stream that sings them.
MinimaxClient
An async client for the MiniMax APIs.

Constants§

API_KEY_ENV
The environment variable read by MinimaxClient::from_env.
BASE_URL_CHINA
The mainland China endpoint.
BASE_URL_GLOBAL
The global endpoint.
BASE_URL_US_WEST
The western United States endpoint.
DEFAULT_BASE_URL
The default MiniMax base URL, matching the official OpenAPI specification.