Skip to main content

Crate rtb_ai

Crate rtb_ai 

Source
Expand description

Unified AI client.

Wraps genai for the multi-provider mainstream (OpenAI / Gemini / Ollama / OpenAI-compatible) and drops down to a direct reqwest-on-Anthropic-Messages path for features genai does not yet surface — prompt caching, extended thinking, citations.

Structured output uses schemars::JsonSchema on caller-supplied types: the schema is sent with the request, and the response is validated with jsonschema before deserialising.

See docs/development/specs/2026-05-01-rtb-ai-v0.1.md for the authoritative contract.

§Lint exception

Crate-level deny(unsafe_code) (not forbid) so the genai-key shim in client can locally allow(unsafe_code) the std::env::set_var it needs to hand the API key to genai. No hand-rolled unsafe blocks anywhere else.

Re-exports§

pub use client::AiClient;
pub use client::ChatRequest;
pub use client::ChatResponse;
pub use client::ChatStream;
pub use client::ChatStreamEvent;
pub use config::validate_base_url;
pub use config::Config;
pub use config::Provider;
pub use error::AiError;
pub use message::Citation;
pub use message::ContentBlock;
pub use message::Message;
pub use message::Role;
pub use message::Usage;
pub use thinking::ThinkingMode;

Modules§

client
AiClient — typed façade over genai + the Anthropic-direct path.
config
Config + Provider + base-URL validation.
error
Typed errors for the AI client. Every String payload runs through rtb_redact::string so leaked URLs / tokens / headers in upstream provider errors never reach our telemetry.
message
Provider-agnostic chat-message types.
thinking
Anthropic extended-thinking configuration.