Skip to main content

typesafe_sdk.TypeSafeClient

Create an 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. Leading and trailing whitespace is stripped. Empty keys, internal whitespace, control characters, and non-ASCII characters are rejected.
  • 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.BaseTransport | None, default: None ) – Optional custom HTTP transport, closed when this SDK client closes.
  • http_client (httpx2.Client | None, default: None ) – Optional httpx2.Client; 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.
  • compression (Literal[‘zstd’, False] | None, default: None ) – Request body compression: "zstd", or False to send bodies uncompressed. Defaults to zstd when available.
Raises:
  • TypeSafeError – The API key is missing or invalid, the timeout is invalid, or zstd compression is unavailable.
  • ValueError – Both transport and http_client are supplied.
Examples:

models

cached property An accessor for the Models API resource. Examples:

attach_assets

Attach assets to calls made within a with block, for referencing them inside strings. Until the block exits, calls on this client send each attached asset whose reference, str(asset), appears in the request.
WarningThe SDK only recognizes references to assets that are attached, passed in assets, or placed directly in the content. A reference to any other asset is sent as plain text, without the asset.
Parameters: Raises: Examples:

system_one

Answer named questions about text, structured state, or assets. See System One for details. Parameters:
  • state (Content) – Text, an asset, a JSON object, or an array to evaluate. See state for details.
  • 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.
  • assets (Mapping[str, Asset] | None, default: None ) – Assets keyed by the reference used for them in state or questions; see Attaching media assets.
  • 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, questions, and assets are set. Merging is last-write-wins: a key that collides with those fields overrides it, and object values are replaced rather than deep-merged.
  • response_model (type[ResponseT] | None, default: None ) – Optional Pydantic BaseModel type describing the JSON response body, including any nested answer models.
Returns:
  • SystemOneResponse | ResponseT – An instance of response_model, or SystemOneResponse with answers keyed by question
  • SystemOneResponse | ResponseT – name and model and token usage details when no custom model is supplied.
Raises: Examples: Create questions with named arguments:
Pass questions as dictionaries:

close

Release network resources and close the underlying HTTP client, including a supplied one.

Models resource

Reached through TypeSafeClient.models.

typesafe_sdk.Models

Access to the models available to the account, reached through TypeSafeClient.models.

list

List the models available to the account. Parameters:
  • 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 ) – Per-operation timeout override; None inherits the client setting.
  • extra_headers (Mapping[str, str] | None, default: None ) – Overrides for additional request headers; authentication, SDK identification, and Accept remain protected.
Returns: Raises: Examples: