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
//! Request customization and response observation at the HTTP boundary.
/// Applies provider-specific JSON fields and headers before a generation request.
///
/// The adapter must preserve the requested response mode and must not perform I/O.
/// It runs for each HTTP attempt under the model's configured retry policy.
/// Headers include configured defaults and constructor credentials. Generation
/// transports preserve removals instead of restoring those defaults afterward.
///
/// # Example
///
/// ```
/// use adk_model::openai::{OpenAICompatible, OpenAICompatibleConfig, RequestAdapter};
/// use std::sync::Arc;
///
/// let adapter: RequestAdapter = Arc::new(|body, headers| {
/// body["metadata"] = serde_json::json!({"application": "example"});
/// headers.insert("x-request-source", "example".parse().expect("valid header"));
/// Ok(())
/// });
/// let client = OpenAICompatible::new(OpenAICompatibleConfig::new("sk-key", "gpt-5-mini"))?
/// .with_request_adapter(adapter);
/// # Ok::<(), adk_core::AdkError>(())
/// ```
pub type RequestAdapter = Arc;
/// Observes response headers before status handling or body consumption.
///
/// The callback runs once for each Responses generation HTTP attempt, retries and
/// unsuccessful statuses included, and not for background polling. It must not
/// panic, block, or perform I/O. Headers may include cookies and other credentials,
/// so do not log or retain the whole map.
///
/// # Example
///
/// ```
/// use adk_model::openai::ResponseObserver;
/// use std::sync::Arc;
///
/// let observer: ResponseObserver = Arc::new(|headers| {
/// if let Some(request_id) = headers.get("x-request-id") {
/// tracing::debug!(request_id = ?request_id, "responses attempt");
/// }
/// });
/// ```
pub type ResponseObserver = Arc;