#[non_exhaustive]pub struct TypeSafeClient { /* private fields */ }Expand description
Client for the TypeSafe AI API.
Construct with TypeSafeClient::new or TypeSafeClient::from_env.
Cloning is cheap and shares the underlying connection pool.
Implementations§
Source§impl TypeSafeClient
impl TypeSafeClient
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self>
pub fn new(api_key: impl Into<String>) -> Result<Self>
Create a new client with the given API key and default settings.
Sourcepub fn from_config(config: ClientConfig) -> Result<Self>
pub fn from_config(config: ClientConfig) -> Result<Self>
Create a new client from a full ClientConfig.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Create a new client, reading the API key from the TYPESAFE_API_KEY
environment variable. Also reads TYPESAFE_BASE_URL and
TYPESAFE_DEFAULT_MODEL if set.
Sourcepub fn default_model(&self) -> &str
pub fn default_model(&self) -> &str
Returns the default model this client uses.
Sourcepub async fn system_one(
&self,
state: impl Into<Value>,
questions: HashMap<String, Question>,
) -> Result<SystemOneResponse>
pub async fn system_one( &self, state: impl Into<Value>, questions: HashMap<String, Question>, ) -> Result<SystemOneResponse>
Answer named questions about text or structured state.
Sends a POST /v1/systemone request and returns a typed
SystemOneResponse.
§Arguments
state— text, a JSON object, or an array to evaluate. Accepts&str,String, or anyserde_json::Value.questions— a non-empty map of question names toQuestions.
Use system_one_with_model to override
the client’s default model.
§Retry safety
This is a POST request. The SDK automatically retries on transient
failures (408, 429, 500, 502, 503, 504, 529, connection errors,
timeouts), but a timeout does
not guarantee the server did not process the request. If the endpoint
has side effects (credit consumption, usage recording, downstream
triggers), a retry may result in duplicate processing. Future versions
will support an Idempotency-Key header to make retries safe.
To avoid replaying a POST whose body the server already processed,
errors that occur while reading the response body — including
timeouts and truncated bodies — are classified as non-retryable
ErrorKind::Transport rather than ErrorKind::Connection
or ErrorKind::Timeout.
§Errors
ErrorKind::Validationif questions are empty or a choice or score question has fewer than two criteria.ErrorKind::Authenticationif the API key is invalid.ErrorKind::RateLimitif rate-limited (after retries).ErrorKind::Connection/ErrorKind::Timeouton network failures (after retries).
Sourcepub async fn system_one_with_model(
&self,
state: impl Into<Value>,
questions: HashMap<String, Question>,
model: Option<&str>,
) -> Result<SystemOneResponse>
pub async fn system_one_with_model( &self, state: impl Into<Value>, questions: HashMap<String, Question>, model: Option<&str>, ) -> Result<SystemOneResponse>
Like system_one but with an explicit model
override (None uses the client default).
Sourcepub async fn system_one_with_opts(
&self,
questions: HashMap<String, Question>,
opts: SystemOneOpts,
) -> Result<SystemOneResponse>
pub async fn system_one_with_opts( &self, questions: HashMap<String, Question>, opts: SystemOneOpts, ) -> Result<SystemOneResponse>
Like system_one but with full per-call options
via a SystemOneOpts builder.
This allows overriding the model, adding extra body fields for forward compatibility, and attaching custom headers — all per-call.
§Example
use typesafeai_sdk::{TypeSafeClient, noul, SystemOneOpts};
use std::collections::HashMap;
let client = TypeSafeClient::from_env()?;
let mut questions = HashMap::new();
questions.insert("billing".to_string(), noul("Is this about billing?").into());
let opts = SystemOneOpts::new()
.with_model(Some("jev-latest".to_string()))
.with_extra_body(serde_json::json!({"user_id": "u123"}));
let response = client.system_one_with_opts(questions, opts).await?;Sourcepub async fn list_models(&self) -> Result<ListModelsResponse>
pub async fn list_models(&self) -> Result<ListModelsResponse>
List available models. Sends GET /v1/models.