switchyard_llm_client/lib.rs
1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! HTTP LLM client that speaks Switchyard's neutral IR directly.
5//!
6//! [`TranslatingLlmClient`] maps a model name (and the wire format resolved from
7//! the request) to a [`Backend`],
8//! encodes a [`switchyard_protocol::Request`] to that backend's wire format via
9//! `switchyard-translation`, applies auth and forwards caller headers, makes the
10//! HTTP call with a shared [`reqwest::Client`], and decodes the wire response
11//! back to a [`switchyard_protocol::Response`] — supporting both buffered and
12//! streamed responses.
13//!
14//! [`SystemOneClient`] serves typed decision requests. Register decision targets
15//! with [`ClientRouter::new_with_decision_clients`] or
16//! [`ClientRouter::single_with_decision_clients`] to serve them alongside LLM calls.
17//!
18//! [`run()`] pairs the client with a libsy algorithm: it drives
19//! [`switchyard_libsy::Algorithm::run_stream`], serves routing-time calls, and makes the terminal
20//! answer call from the routing outcome when needed. A host that just wants the answer does not
21//! have to drive the step stream itself.
22
23pub mod backend;
24pub mod client;
25pub mod error;
26pub mod metrics;
27mod observability;
28mod observation;
29mod observed_translation;
30mod openai_decisions;
31mod payload_capture;
32pub mod raw;
33mod responses_compatibility;
34mod responses_reasoning;
35pub mod run;
36mod system_one;
37
38pub use backend::{Backend, DEFAULT_MAX_RETRIES, HttpBackendConfig};
39pub use client::{AuxiliaryOperation, ModelConfig, TranslatingLlmClient};
40pub use error::{LlmClientError, Result};
41pub use observation::{ModelCallObservation, RunObservation, RunObserver};
42pub use openai_decisions::OpenAiDecisionClient;
43pub use payload_capture::with_payload_capture;
44pub use raw::RawResponse;
45pub use responses_compatibility::ResponsesCompatibility;
46pub use responses_reasoning::ResponsesReasoningPolicy;
47pub use run::{ClientRouter, decide, run};
48pub use switchyard_translation::RawEventStream;
49pub use system_one::SystemOneClient;
50
51/// Registers process-wide compatibility gauges with the global meter provider.
52pub fn initialize_metrics() {
53 metrics::initialize();
54}