Cookbook examples
September 24, 2026 · View on GitHub
Runnable Rust ports of patterns and cookbooks from docs.typesafe.ai.
Mock vs live
| Mode | How 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
| Example | Doc link |
|---|---|
system_one | Quick start |
fan_out | Speculative fan-out |
confidence_routing | Confidence |
guardrails | LLM guardrails |
citation_check | Citation check |
structured_state | State |
composite_scoring | Composite scoring |
intent_routing | Intent routing |
noul_uncertainty | Self-consistency nouls |
blocking_triage | Blocking client on live API; mock path uses async client against wiremock (--features "mock blocking") |
custom_base_url | Non-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"