to11ai-sdk and imported as to11ai_sdk. The current version is 0.2.0 and the package is licensed under MPL-2.0. Its only runtime dependency is Pydantic (>=2.13).
This SDK talks to the to11 platform API, the control plane, to manage prompts and routing rules. It is not the path for sending LLM or chat traffic. To send model requests, point a provider SDK such as OpenAI or Anthropic at the gateway base URL
https://gw.to11.ai/v1. See Integrations. For that reason the SDK has no .chat() method.Installation
The SDK requires Python 3.10 or later, andto11ai-sdk 0.2.0 or later. Install it with the package manager of your choice.
Authentication
The SDK authenticates with a to11 API key, sent as a standardAuthorization: Bearer <to11-api-key> HTTP header. The client sets this header from the api_key value passed at construction. The project is identified in the URL path of each request, not in a header.
Read the key from an environment variable rather than embedding it in source:
Creating a client
Construct a client with thecreate_client factory. All arguments are keyword-only.
project_id is not a constructor argument. It is passed on every resource method call. This differs from the to11 TypeScript SDK, where the project is configured once on the client.
Options
| Argument | Type | Default | Description |
|---|---|---|---|
api_key | str | required | The to11 API key. Must be non-empty. |
base_url | str | required | The platform API base URL. Use https://api.to11.ai. |
timeout_s | float | 30.0 | Per-request timeout, in seconds. |
max_retries | int | 3 | Maximum number of retry attempts per request. |
ttl_seconds | int | 300 | Time-to-live for cached responses, in seconds. |
max_cache_entries | int | 100 | Maximum number of entries held in the response cache. |
behavior_overrides | Mapping | None | None | Optional client behavior overrides. |
Resolving prompts
client.prompts.resolve returns the resolved content of a prompt for a project, selected by slug and label. It is the prompt-resolution method in the Python SDK.
prompts namespace also provides:
- Prompt lifecycle methods:
create,list,get,update, andarchive. - Version methods:
create_version,list_versions,get_version,move_label, andlist_labels. - Project-label methods:
list_project_labels,create_project_label,get_project_label,update_project_label,delete_project_label,list_project_label_usages, andlist_label_events.
Managing routing rules
Theclient.routing_rules namespace manages routing rules through two nested namespaces.
client.routing_rules.versions manages rule versions:
createcreates a new rule version.listlists rule versions.getretrieves a single rule version.
client.routing_rules.releases manages which version is released to an environment:
setreleases a version.rollbackreverts to a previous release.listlists releases.
Project environments
Theclient.project_environments namespace manages a project’s environments. It provides list, get, create, update, archive, and restore.
Error handling
The SDK raises typed exceptions.To11aiError is the base class; all other SDK errors inherit from it. Catch To11aiError to handle any SDK error, or catch a specific subclass.
| Exception | Raised when |
|---|---|
To11aiError | Base class for all SDK errors. |
To11aiApiError | The API returns an error response. Carries status_code, error_code, and details. |
To11aiAuthError | The request is unauthorized or forbidden (HTTP 401 or 403). |
To11aiRateLimitError | The request is rate limited (HTTP 429). Carries retry_after_seconds. |
To11aiValidationError | The request is rejected as invalid (HTTP 400). |
To11aiNetworkError | A network-level failure prevents the request from completing. |
RuleNotFoundError | The referenced routing rule does not exist. |
NoApplicableRouteError | No routing rule applies to the request. |
EnvNotEnabledForProviderError | The environment is not enabled for the provider. |
RuleVersionInvalidSnapshotError | The rule version references an invalid snapshot. |
PromptLabelNotRegisteredError | The referenced prompt label is not registered. |
The Python SDK exposes a smaller set of named exceptions than the TypeScript SDK. Some prompt- and environment-specific conditions that the TypeScript SDK raises as dedicated classes (for example
PromptNotFoundError or EnvNotFoundError) surface in Python as a To11aiApiError — inspect its error_code and status_code to distinguish them.Next steps
TypeScript SDK
The to11 TypeScript SDK.
API reference
The underlying HTTP API.