Calling the System One API
- Async
- Sync
Choosing a model
Inspect the available models:- Async
- Sync
- Async
- Sync
Attaching Media Assets
System One requests can include media assets.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:
- Automatic references: place assets directly in the content, or format them into strings. The SDK then auto-generates a unique reference for each asset.
- Named references: choose your own references for assets, passed through the
assetsargument tosystem_one.
Automatic references
Assets in structured objects
Place assets directly instate or in question instructions and criteria:
- Async
- Sync
NoteUnder the hood, each asset is automatically assigned a unique uuid-like reference.
Assets in text
Useclient.attach_assets to attach assets to the client, and str(asset) to reference them in text:
- Async
- Sync
Named references
To choose your own reference for an asset, pass it throughassets, keyed by that reference. Use distinct delimiters (such as <product>) to avoid matching ordinary text:
- Async
- Sync
Typed system_one responses
It is possible to provide a response model to system_one to make using the response more type-safe:
- Async
- Sync
Custom response types
It is also possible to define a completely new response model without inheriting fromSystemOneResponse:
- Async
- Sync
Retries
Pass a customRetryPolicy as retry on the client or per call. Invalid API keys raise TypeSafeError during client creation, before any request or retry.
On the client:
- Async
- Sync
- Async
- Sync
Error handling
Handle exceptions raised by the SDK:- Async
- Sync
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, setbase_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.
- OpenRouter
- Vercel AI Gateway
- Pydantic AI Gateway
Use an OpenRouter API key and an OpenRouter model ID:
- Async client
- Sync client

