Expand description
Rust client for TypeSafe’s System One API.
System One evaluates a state against a map of named questions (noul,
choice, score) and returns one typed answer per question. This crate is
the HTTP client: configuration, retries, errors, POST /v1/systemone, and
GET /v1/models.
This is a community SDK, not an official TypeSafe product. Env vars, defaults, retries, identification headers, and error kinds match the official Python and TypeScript SDKs.
Set TYPESAFE_API_KEY. Optional: TYPESAFE_BASE_URL, TYPESAFE_DEFAULT_MODEL.
§Quick start
use typesafe_rs::{questions, Client, Question};
let client = Client::from_env()?;
let response = client
.system_one(
"Help! My payouts have been failing for 3 days.",
questions! {
"urgent" => Question::noul("Does this convey urgency?"),
},
)
.await?;
println!("{:?}", response.noul("urgent"));For tests, use typesafe-rs-mock instead
of the live API. See the quickstart example.
§Crate features
| Feature | Default | Enables |
|---|---|---|
rustls | yes | TLS via rustls (platform verifier) |
native-tls | no | Platform TLS instead of, or in addition to, rustls |
tracing | yes | typesafe.request spans and retry_scheduled events |
blocking | no | BlockingClient |
Enable rustls (the default) or native-tls. HTTPS will not compile with
neither.
Re-exports§
pub use types::Answer;pub use types::ChoiceView;pub use types::Entry;pub use types::ListModelsResponse;pub use types::MAX_CHOICE_OPTIONS;pub use types::ModelCard;pub use types::NoulCriteria;pub use types::NoulView;pub use types::Question;pub use types::Questions;pub use types::ResponseMeta;pub use types::ScoreView;pub use types::SystemOneRequest;pub use types::SystemOneResponse;pub use types::Usage;
Modules§
- types
- Wire types for the System One API.
Macros§
- questions
- Build an ordered map of named questions.
Structs§
- ApiError
- Non-2xx API response.
- Blocking
Client blocking - Blocking wrapper around
Clientusing a current-thread Tokio runtime. - Blocking
Models blocking - Blocking Models API resource.
- Call
Options - Per-call overrides.
- Client
- Asynchronous TypeSafe System One client.
- Client
Config - Client configuration. Explicit values win over environment, then defaults.
- Header
Map - A specialized multimap for header names and values.
- Header
Value - Represents an HTTP header field value.
- Index
Map - A hash table where the iteration order of the key-value pairs is independent of the hash values of the keys.
- Models
- Models API resource.
- Retry
Policy - Retry policy matching the official TypeSafe SDKs.
- Secret
String - API key wrapper that redacts itself in
Debug. - Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Status
Set - Set of HTTP status codes that should be retried.
- Transport
Error - Sanitized transport failure. Display never includes API keys.
- Url
- A parsed URL record.
Enums§
- ApiError
Kind - HTTP status class, matching the official SDK error subclasses.
- Error
- SDK error taxonomy, aligned with the official TypeScript classes.
- Error
Body - Body of an error response.
Constants§
- DEFAULT_
BASE_ URL - Default API root.
- DEFAULT_
MODEL - Default model when none is configured.
- DEFAULT_
TIMEOUT - Default per-attempt timeout, including the response body.
- ENV_
API_ KEY - Environment variable for the API key.
- ENV_
BASE_ URL - Environment variable for the API root URL.
- ENV_
DEFAULT_ MODEL - Environment variable for the default model.
- VERSION
- Crate version, used in
User-AgentandX-TypeSafe-SDK.
Traits§
- Backend
- Pluggable System One evaluator.