typesafe_sdk/lib.rs
1//! # TypeSafe SDK for Rust
2//!
3//! A community-maintained Rust client for the [TypeSafe AI](https://typesafe.ai) API.
4//!
5//! TypeSafe answers typed questions about text or structured state. Create a client,
6//! describe the questions you want answered, and read the typed answers:
7//!
8//! ```rust,no_run
9//! use typesafe_sdk::{Client, SystemOneRequest};
10//! use serde_json::json;
11//!
12//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
13//! let client = Client::from_env()?;
14//!
15//! let response = client.system_one(
16//! SystemOneRequest::new("I was charged twice. Please fix this ASAP.")
17//! .question("category", typesafe_sdk::choice(
18//! "What is this ticket about?",
19//! [
20//! ("billing", Some(json!("Payments, invoicing, refunds"))),
21//! ("technical", Some(json!("Bugs, outages, integrations"))),
22//! ],
23//! )),
24//! ).await?;
25//!
26//! for (name, answer) in response.choices() {
27//! println!("{name}: {}", answer.choice);
28//! }
29//! # Ok(())
30//! # }
31//! ```
32//!
33//! ## Environment Variables
34//!
35//! | Variable | Description | Default |
36//! |---|---|---|
37//! | `TYPESAFE_API_KEY` | API key (required) | — |
38//! | `TYPESAFE_BASE_URL` | API root URL | `https://api.typesafe.ai` |
39//! | `TYPESAFE_DEFAULT_MODEL` | Default model name | `jev-latest` |
40//! | `TYPESAFE_LOG_LEVEL` | Log verbosity | `warn` |
41//!
42//! ## Status
43//!
44//! This is a **community-maintained** SDK, not an official TypeSafe AI product.
45//! Use it at your own risk. See the [official SDKs](https://docs.typesafe.ai/sdks)
46//! for TypeSafe-maintained packages.
47
48pub mod answers;
49pub mod client;
50pub mod config;
51pub mod errors;
52pub mod logging;
53pub mod questions;
54pub mod retry;
55pub mod types;
56
57pub use answers::{Answer, ChoiceAnswer, NoulAnswer, ScoreAnswer, UnknownAnswer};
58pub use client::Client;
59pub use config::ClientBuilder;
60pub use errors::{ApiError, ConnectionError, Error, ResponseError, TimeoutError};
61pub use questions::{
62 ChoiceQuestion, NoulCriteria, NoulQuestion, Question, ScoreQuestion, choice, noul,
63 noul_with_criteria, score,
64};
65pub use retry::RetryPolicy;
66pub use types::{ModelMetadata, SystemOneRequest, SystemOneResponse, Usage};
67
68/// Crate version.
69pub const VERSION: &str = env!("CARGO_PKG_VERSION");