Skip to main content

gemini_live/
lib.rs

1//! # gemini-live
2//!
3//! High-performance, idiomatic Rust client for the
4//! [Gemini Multimodal Live API](https://ai.google.dev/api/live).
5//!
6//! Designed for real-time audio/video streaming where every allocation
7//! counts.  See [`audio::AudioEncoder`] for the zero-allocation hot path,
8//! `docs/design.md` for performance goals, and `docs/roadmap.md` for
9//! known gaps and planned work.
10//!
11//! ## Architecture
12//!
13//! The crate is organised in layers — each builds on the one below:
14//!
15//! | Layer         | Module        | Responsibility                                                  |
16//! |---------------|---------------|-----------------------------------------------------------------|
17//! | **Session**   | [`session`]   | Connection lifecycle, reconnection, typed send/receive          |
18//! | **Transport** | [`transport`] | WebSocket connection, TLS, frame I/O                            |
19//! | **Codec**     | [`codec`]     | JSON ↔ Rust; [`ServerMessage`] → [`ServerEvent`] decomposition  |
20//! | **Audio**     | [`audio`]     | PCM encoding utilities and format constants                     |
21//! | **Types**     | [`types`]     | Strongly-typed wire-format structs                              |
22//! | **Errors**    | [`error`]     | Layered error enums                                             |
23//!
24//! ## Quick start
25//!
26//! ```rust,no_run
27//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
28//! use gemini_live::session::{Session, SessionConfig, ReconnectPolicy};
29//! use gemini_live::transport::{Auth, TransportConfig};
30//! use gemini_live::types::*;
31//!
32//! let mut session = Session::connect(SessionConfig {
33//!     transport: TransportConfig {
34//!         auth: Auth::ApiKey(std::env::var("GEMINI_API_KEY")?),
35//!         ..Default::default()
36//!     },
37//!     setup: SetupConfig {
38//!         model: "models/gemini-3.1-flash-live-preview".into(),
39//!         generation_config: Some(GenerationConfig {
40//!             response_modalities: Some(vec![Modality::Text]),
41//!             ..Default::default()
42//!         }),
43//!         ..Default::default()
44//!     },
45//!     reconnect: ReconnectPolicy::default(),
46//! }).await?;
47//!
48//! session.send_text("Hello!").await?;
49//!
50//! while let Some(event) = session.next_event().await {
51//!     match event {
52//!         ServerEvent::ModelText(text) => print!("{text}"),
53//!         ServerEvent::TurnComplete => println!("\n--- turn done ---"),
54//!         _ => {}
55//!     }
56//! }
57//! # Ok(())
58//! # }
59//! ```
60
61pub mod audio;
62pub mod codec;
63pub mod error;
64pub mod session;
65pub mod transport;
66pub mod types;
67
68// Re-export the most commonly used items at the crate root for convenience.
69pub use error::*;
70pub use session::{ReconnectPolicy, Session, SessionConfig, SessionStatus};
71pub use transport::{Auth, Connection, RawFrame, TransportConfig};
72pub use types::*;