Skip to main content

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;
31pub mod raw;
32pub mod run;
33mod system_one;
34
35pub use backend::{Backend, DEFAULT_MAX_RETRIES, HttpBackendConfig};
36pub use client::{AuxiliaryOperation, ModelConfig, TranslatingLlmClient};
37pub use error::{LlmClientError, Result};
38pub use observation::{ModelCallObservation, RunObservation, RunObserver};
39pub use openai_decisions::OpenAiDecisionClient;
40pub use raw::RawResponse;
41pub use run::{ClientRouter, decide, run};
42pub use switchyard_translation::RawEventStream;
43pub use system_one::SystemOneClient;
44
45/// Registers process-wide compatibility gauges with the global meter provider.
46pub fn initialize_metrics() {
47    metrics::initialize();
48}