1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! # Realtime API (WebSocket)
//!
//! Realtime text and audio conversations over the GLM-Realtime WebSocket
//! protocol (`wss://open.bigmodel.cn/api/paas/v4/realtime`). The protocol types
//! also model passive-video frames, conversation history, function calls, and
//! response lifecycle events.
//!
//! Verified against the official protocol:
//! - <https://github.com/MetaGLM/glm-realtime-sdk/blob/main/GLM-Realtime-doc-for-llm.md>
//! - <https://docs.bigmodel.cn/cn/asyncapi/realtime>
//!
//! ## Quick start
//!
//! ```rust,no_run
//! use zai_rs::{
//! model::GLM_realtime_flash,
//! realtime::{RealtimeClient, TurnDetectionType},
//! };
//!
//! # async fn demo(key: String) -> zai_rs::ZaiResult<()> {
//! let session = RealtimeClient::new(key)
//! .session(GLM_realtime_flash {})
//! .turn_detection(TurnDetectionType::ServerVad)
//! .build()
//! .await?;
//! session.send_text("你好").await?;
//! session.create_response().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Auth modes
//!
//! - **Bearer** (default, server-side): `Authorization: Bearer {API_KEY}`.
//! - **JWT**: `.with_jwt(ttl_seconds)` derives a short-lived token locally and
//! sends that token, rather than the raw API key, in the WebSocket handshake.
//! Generating the token on a trusted server before handing it to an untrusted
//! browser or device is still the application's responsibility.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
use crateModelName;
/// Marker trait for model ids usable in a realtime session.
///
/// This trait is sealed and implemented only for the current official realtime
/// model ids, so arbitrary or retired model markers cannot reach session
/// construction.
///
/// ```compile_fail
/// use zai_rs::{model::GLM4_voice, realtime::RealtimeClient};
///
/// let client = RealtimeClient::new("abc.secret-value");
/// // `GLM4_voice` is an HTTP voice-chat model, not a Realtime WebSocket model.
/// let _session = client.session(GLM4_voice {});
/// ```