Cookbook examples

September 24, 2026 · View on GitHub

Runnable Rust ports of patterns and cookbooks from docs.typesafe.ai.

Mock vs live

ModeHow to run
Mock (default, no API key)cargo run --example NAME --features mock
Live (your account)TYPESAFE_LIVE=1 plus TYPESAFE_API_KEY set, then cargo run --example NAME

Mock mode starts an in-process wiremock server with canned JSON from examples/support/fixtures.rs. Live mode calls TYPESAFE_BASE_URL when set, otherwise https://api.typesafe.ai. custom_base_url is the exception. Its live path requires TYPESAFE_BASE_URL and does not fall back to https://api.typesafe.ai.

CI runs the same fixtures in tests/examples_integration.rs via cargo test --features mock.

Examples

ExampleDoc link
system_oneQuick start
fan_outSpeculative fan-out
confidence_routingConfidence
guardrailsLLM guardrails
citation_checkCitation check
structured_stateState
composite_scoringComposite scoring
intent_routingIntent routing
noul_uncertaintySelf-consistency nouls
blocking_triageBlocking client on live API; mock path uses async client against wiremock (--features "mock blocking")
custom_base_urlNon-default base URL for POST /v1/systemone and GET /v1/models. Mock mounts /v1/… on the wiremock origin. Live requires TYPESAFE_BASE_URL and does not fall back to https://api.typesafe.ai.

Build all mocks locally

cargo test --features mock
for ex in system_one fan_out confidence_routing guardrails citation_check \
  structured_state composite_scoring intent_routing noul_uncertainty custom_base_url; do
  cargo run --example "$ex" --features mock
done
cargo run --example blocking_triage --features "mock blocking"