Skip to main content

Calling the System One API

Choosing a model

Inspect the available models:
Select the model when constructing a client:
See the Models resource reference for more information on available models, their capabilities, pricing details, and model aliases.

Attaching Media Assets

System One requests can include media assets.
Supported asset typesOnly images are supported at the moment, with more modalities coming in the future.
Images are only dreamer-readyAs of November 14, 2026, image support is only dreamer-ready. The brave may opt-in to this feature via HTTP headers:
Learn about support for images:
  • API docs: how to enable and use images with TypeSafe’s System One API
  • SDK docs: documentation and code examples for using images with typesafe-sdk
Upload formatRequests with assets are sent as multipart/form-data, with each asset’s raw bytes in its own part.

An asset reference inside the content of state or questions will be replaced with the actual asset data, provided to the client separately. There are two ways to create asset references:
  1. Automatic references: place assets directly in the content, or format them into strings. The SDK then auto-generates a unique reference for each asset.
  2. Named references: choose your own references for assets, passed through the assets argument to system_one.
Both types of asset references may be used together in the same request.

Automatic references

Assets in structured objects

Place assets directly in state or in question instructions and criteria:
NoteUnder the hood, each asset is automatically assigned a unique uuid-like reference.

Assets in text

Use client.attach_assets to attach assets to the client, and str(asset) to reference them in text:
WarningDon’t forget the with client.attach_assets context manager block! The SDK will not be able to associate text-rendered asset references with the original asset data.

Named references

To choose your own reference for an asset, pass it through assets, keyed by that reference. Use distinct delimiters (such as <product>) to avoid matching ordinary text:
TipAn asset passed through assets may also be placed directly in the content: it is sent once, under its name.

Typed system_one responses

It is possible to provide a response model to system_one to make using the response more type-safe:

Custom response types

It is also possible to define a completely new response model without inheriting from SystemOneResponse:

Retries

Pass a custom RetryPolicy as retry on the client or per call. Invalid API keys raise TypeSafeError during client creation, before any request or retry. On the client:
Per call:

Error handling

Handle exceptions raised by the SDK:

Environment variables

The SDK reads and uses the following environment variables: See the constants reference for SDK defaults. API keys supplied through api_key or TYPESAFE_API_KEY have leading and trailing whitespace stripped, including newlines from key files. Empty keys, internal whitespace, control characters, and non-ASCII characters are rejected before sending a request. An explicitly empty key does not fall back to the environment.

Configuring the base URL

In order to use the SDK with a different API url, set base_url on the client or the TYPESAFE_BASE_URL environment variable. This requires the alternative API to follow the TypeSafe OpenAPI spec. For example, connect through an AI gateway using its API key and model ID.
Use an OpenRouter API key and an OpenRouter model ID: