typesafe_sdk.AsyncTypeSafeClient
Create an asynchronous HTTP client for TypeSafe AI API.
Explicit options take precedence over environment variables; empty or whitespace-only environment values are ignored.
Logging setupThe SDK logs to the typesafe_sdk logger; configure it through standard logging, or set TYPESAFE_LOG_LEVEL (debug, info, …) for a quick default. Secret headers are redacted from log output; request and response bodies are not.
Parameters:
-
api_key (str | None, default: None ) –
Required API key; may be set via the TYPESAFE_API_KEY environment variable.
-
model (str | None, default: None ) –
Model name; may be set via the TYPESAFE_DEFAULT_MODEL environment variable.
-
retry (RetryPolicy | None, default: None ) –
A RetryPolicy controlling retry behavior; see RetryPolicy for the available options and their defaults. Pass RetryPolicy(max_retries=0) to disable retries.
-
timeout (float | httpx2.Timeout | None, default: None ) –
Timeout for HTTP operations. Inherits http_client.timeout when supplied, otherwise the SDK default.
-
headers (Mapping[str, str] | None, default: None ) –
Additional request headers to set.
-
transport (httpx2.AsyncBaseTransport | None, default: None ) –
Optional custom HTTP transport, closed when this SDK client closes.
-
http_client (httpx2.AsyncClient | None, default: None ) –
Optional httpx2.AsyncClient; mutually exclusive with transport. Closed when this SDK client closes.
-
base_url (str | None, default: None ) –
API root; may be set via the TYPESAFE_BASE_URL environment variable.
Raises:
-
TypeSafeError –
The API key is missing or the timeout is invalid.
-
ValueError –
Both transport and http_client are supplied.
Examples:
models cached property
An accessor for the Models API resource.
Examples:
system_one async
Answer named questions about text or structured state.
Parameters:
-
state (str | dict[str, JSONValue | None] | list[JSONValue | None]) –
Text, a JSON object, or an array to evaluate; not None.
-
questions (Mapping[str, Question]) –
Nonempty mapping of names to question objects or raw dictionaries.
-
model (str | None, default: None ) –
Model override; None inherits the client default.
-
retry (RetryPolicy | None, default: None ) –
An optional retry policy to override the client-level value for this call only.
-
timeout (float | httpx2.Timeout | None, default: None ) –
An optional timeout for http operations to override the client-level value for this call only, in seconds.
-
extra_headers (Mapping[str, str] | None, default: None ) –
Additional request headers to set.
-
extra_body (Mapping[str, JSONValue | None] | None, default: None ) –
Additional top-level request-body fields, shallow-merged over the body after state, model, and questions are set. Merging is last-write-wins: a key that collides with state, model, or questions overrides it, and object values are replaced rather than deep-merged.
Returns:
-
SystemOneResponse –
Answers keyed by question name, with model and token usage details.
Raises:
-
TypeSafeError –
Questions are empty or score criteria are empty or not indexed consecutively from zero.
-
TypeSafeAPIError –
The server returns an unsuccessful HTTP response after any retries.
-
TypeSafeAPIConnectionError –
The request cannot connect or times out after any retries.
Examples:
Create questions with named arguments:
Pass questions as dictionaries:
aclose async
Release network resources and close the underlying HTTP client, including a supplied one.