Skip to main content

Crate typesafe_rs

Crate typesafe_rs 

Source
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

FeatureDefaultEnables
rustlsyesTLS via rustls (platform verifier)
native-tlsnoPlatform TLS instead of, or in addition to, rustls
tracingyestypesafe.request spans and retry_scheduled events
blockingnoBlockingClient

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.
BlockingClientblocking
Blocking wrapper around Client using a current-thread Tokio runtime.
BlockingModelsblocking
Blocking Models API resource.
CallOptions
Per-call overrides.
Client
Asynchronous TypeSafe System One client.
ClientConfig
Client configuration. Explicit values win over environment, then defaults.
HeaderMap
A specialized multimap for header names and values.
HeaderValue
Represents an HTTP header field value.
IndexMap
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.
RetryPolicy
Retry policy matching the official TypeSafe SDKs.
SecretString
API key wrapper that redacts itself in Debug.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
StatusSet
Set of HTTP status codes that should be retried.
TransportError
Sanitized transport failure. Display never includes API keys.
Url
A parsed URL record.

Enums§

ApiErrorKind
HTTP status class, matching the official SDK error subclasses.
Error
SDK error taxonomy, aligned with the official TypeScript classes.
ErrorBody
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-Agent and X-TypeSafe-SDK.

Traits§

Backend
Pluggable System One evaluator.

Type Aliases§

Result
Result alias for this crate’s Error.