Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

to11ai-sdk

Python SDK for to11.ai — the AI engineering platform for prompt management, tracing, and evals.

Use it to render managed prompts at runtime, wire your provider client (OpenAI, Anthropic, …) to the to11 gateway with the right auth/trace headers, and group model calls into sessions, conversations, and turns for tracing. Synchronous, snake_case, Python 3.10+. Only runtime dependency: Pydantic.

Installation

pip install to11ai-sdk
# or: uv add to11ai-sdk  ·  poetry add to11ai-sdk

The SDK's only runtime dependency is Pydantic. The provider client libraries used in the examples below (openai, anthropic) are not dependencies — install whichever you use yourself, e.g. pip install openai.

Upgrading from 2.x

3.0 takes environments out of prompt resolution: a prompt has one label, latest, and the client env only routes gateway calls. move_label(), the project label registry and weighted releases are gone, and list_versions(), list_labels() and project_environments.list() return cursor pages instead of lists. See Migrating from 2.x to 3.0 for the full list.

Upgrading from 1.x

2.0 reshapes prompt access around a single render() call and trims the public surface to what we keep stable. prompts.resolve() is gone, the per-call env argument is now label, and routing rules are no longer exported. See Migrating from 1.x to 2.0 for the full list of renames and removals.

Quick start

Create a client, render a prompt, and send it through the gateway with your normal provider client:

import os
from to11ai_sdk import create_client
from openai import OpenAI

to11 = create_client(
    # Each also resolves from an env var, so on a server you can pass nothing:
    base_url=os.environ.get("TO11_API_URL"),        # -> https://api.to11.ai
    api_key=os.environ.get("TO11_API_KEY"),         # -> TO11_API_KEY
    project_id=os.environ.get("TO11_PROJECT_ID"),   # -> TO11_PROJECT_ID
    env=os.environ.get("TO11_ENV"),                 # "prod", "staging", … -> TO11_ENV
)

# Render the prompt's `latest` version for the client's project, shaped for OpenAI.
prompt = to11.prompts.render("welcome-message", variables={"name": "Ada"}, format="openai")

# Point your provider client at the gateway and send it.
openai = OpenAI(**to11.openai_options())
completion = openai.chat.completions.create(
    **prompt["config"],
    messages=prompt["messages"],
    extra_headers=to11.turn().headers(prompt),  # auth + trace id + prompt provenance
)

prompt["config"] carries the model parameters, prompt["messages"] the rendered messages, and turn().headers(prompt) the headers that authenticate the gateway call and record which prompt produced the trace. config["model"] is sent as written, and the hosted gateway needs it to name a provider — set the prompt's model as <provider-slug>::<model> (for example openai::gpt-4o, where openai is the provider's routing identifier in to11).

Configuring the client

create_client(...) takes keyword-only args. Each URL/credential resolves option → environment variable → built-in default, so a server app can construct it from the environment alone:

Argument Resolves from Default
base_url option → TO11_API_URL https://api.to11.ai
gateway_url option → TO11_GATEWAY_URL https://gw.to11.ai
api_key option → TO11_API_KEY — (required)
project_id option → TO11_PROJECT_ID —
env option → TO11_ENV — (gateway routing via x-to11-env; lowercase-kebab, 1–63 chars)
provider_api_key option — (BYOK; carried by openai_options()/anthropic_options())
agent option — ({"id": ..., "name": ...}: the agent every session runs as; see Naming the agent)
format option — ("openai" | "anthropic"; omit for the neutral result)
on_unknown_role option "drop"
timeout_s / max_retries option 30.0 / 3
behavior_overrides option None

The client exposes the resolved values as read-only attributes — to11.base_url, to11.gateway_url, to11.api_key, to11.project_id, and to11.env. Use the non-secret ones (base_url/gateway_url/project_id/env) for diagnostics; api_key is exposed to build manual auth headers — treat it as a secret and never log it. provider_api_key (BYOK) is deliberately not exposed back off the client.

Fetching prompts

prompts.render(slug, ...) resolves the prompt's latest version for the client's project_id in one request. Set format (on the client or per call) to get a result shaped for that provider; omit it for the provider-neutral result.

prompt = to11.prompts.render(
    "weather-concierge",
    variables={"city": "New York", "units": "fahrenheit"},
    # label=...      # pin a label for this call (defaults to "latest", the one label a prompt carries)
    # fallback=...   # a previously-rendered RenderedPrompt served on a network error
    # format="openai" | "anthropic"
    # on_unknown_role="drop" | "warn" | "error"
)
  • With format the result is spread-ready: {"messages": ..., "config": ..., "metadata": ...} (config = the version's model params; metadata = prompt/version provenance). For Anthropic it also carries a top-level "system".
  • Without format you get the neutral RenderedPrompt: .messages, .tools, .tool_choice, .prompt_id, .version, .version_id, .content_hash, .label, .slug, .block_render_record, .model_config_ (trailing underscore avoids Pydantic's reserved name).

Authored developer blocks come back as-is; the SDK maps them per provider (OpenAI keeps developer; Anthropic folds system/developer into the top-level system). on_unknown_role controls how an unrecognized role is handled during provider conversion.

Sending through the gateway

openai_options() / anthropic_options() return spread-ready kwargs (base_url, api_key, default_headers) for a provider client pointed at the gateway; default_headers carries the static tenant auth. Add turn().headers(prompt) per call for the trace id and prompt provenance:

from anthropic import Anthropic
anthropic = Anthropic(**to11.anthropic_options())

By default the gateway runs the call on the project's configured provider credential (managed). For BYOK, set provider_api_key on create_client.

Sessions, conversations & turns

Group model calls for tracing. to11.turn() uses the client's default session; create explicit ones with to11.session(id=None) / to11.conversation(id=None). turn().headers(prompt=None) emits the session/conversation ids + a fresh traceparent (plus prompt provenance when a rendered/shaped prompt is passed) — for the gateway call you make. (This is separate from the SDK's OTel-based traceparent on its own control-plane requests.)

Naming the agent

Name the agent a session runs as, and each request sends x-to11-agent-id (and x-to11-agent-name) so the platform records which agent ran the session. Name it on the client, or per session when one client runs several agents:

to11 = create_client(agent={"id": "support-bot", "name": "Support bot"})

# This session runs as a different agent; its conversations and turns inherit it.
session = to11.session(agent={"id": "pr-reviewer", "name": "PR reviewer"})
openai.chat.completions.create(
    **prompt["config"], messages=prompt["messages"],
    extra_headers=session.turn().headers(prompt),
)
  • id identifies the agent: the same id is the same agent. It is trimmed and lowercased, then must be 1–64 characters of a-z 0-9 . _ / - (PR-Reviewer and pr-reviewer are one agent).
  • name is an optional display name sent beside the id. Any text up to 128 characters.
  • An invalid id or name raises ValueError when the client or session is created.
  • The client's agent id also rides in openai_options() / anthropic_options() default_headers, so a call made without turn().headers() still sends it. The name travels only with turn().headers(), so a session's agent replaces the client's whole, name included.
  • Building headers yourself? gateway_agent_headers(id=..., name=None) returns x-to11-agent-id and, with a name, x-to11-agent-name (percent-encoded).

Managing prompts, versions & labels

Beyond render(), the prompts namespace covers the control-plane lifecycle. All of these default project_id from the client — pass it per call only to override:

to11 = create_client(api_key="...", project_id="proj_abc123")

to11.prompts.list()                                        # uses the bound project_id
to11.prompts.get(prompt_id="prompt_1")
to11.prompts.get_version(prompt_id="prompt_1", version_number=3)
to11.prompts.list_labels(prompt_id="prompt_1")             # page.items: [PromptLabelPointer(label="latest", version_id="ver_9", …)]

list_versions pages a prompt's versions newest first and returns summaries — id, version, format, changelog, who created it and when — without the content. Pass pagination.next_cursor back as cursor for the next page (None on the last one); limit defaults to 50 and clamps to 100. Read one version's template_json, variables_schema and model_config_ with get_version:

page = to11.prompts.list_versions(prompt_id="prompt_1", limit=20)
# page.items: list[PromptVersionSummary]   page.pagination: CursorPaginationInfo(next_cursor, limit)
newest = to11.prompts.get_version(prompt_id="prompt_1", version_number=page.items[0].version)

Full set: render, create, list, get, update, archive, create_version, list_versions, iter_versions, get_version, list_labels, iter_labels, list_org_prompts, render_skill_version. Creating a version moves latest; there is no label to move by hand. to11.project_environments exposes the project-environments registry.

Skills across an organization: list_org_prompts lists the skills in every project of an org you may read prompts in, each with the version latest serves (at most limit rows, default 20, max 50). Render exactly that version with render_skill_version:

listing = to11.prompts.list_org_prompts(org_id="org_1", query="release")
row = listing.items[0]
skill = to11.prompts.render_skill_version(project_id=row.project_id, slug=row.slug, version=row.version)
# skill.files: [RenderedSkillFile(filename="SKILL.md", content=..., ...)]

Organization usage

to11.usage reads an organization's usage. Every method takes the org_id and, except find_principals, a window: absolute ({"from": ..., "to": ...}, ISO 8601 with an offset) or a preset the server resolves in an IANA time zone ({"preset": ..., "n": ..., "timezone": ...}; n only for last_n_hours / last_n_days). Figures carry billed_usd and api_equivalent_usd; every response echoes the absolute window and lists the readable projects it left out (excluded_projects).

members = to11.usage.find_principals(org_id="org_1", query="nigel")  # or email=...
window = {"preset": "last_n_days", "n": 7, "timezone": "Europe/Berlin"}

to11.usage.list_sessions(org_id="org_1", window=window, principal_id=members.items[0].principal_id)  # cursor-paged
to11.usage.get_costs(org_id="org_1", window=window, group_by=["principal", "model"])
to11.usage.list_top_traces(org_id="org_1", window=window, sort="cost", limit=5)  # window <= 60 days

Error handling

To11aiError is the base; catch it broadly or match a subclass:

from to11ai_sdk import To11aiRateLimitError, PromptNotFoundError

try:
    prompt = to11.prompts.render("welcome-message")
except To11aiRateLimitError as exc:
    ...  # exc.retry_after_seconds
except PromptNotFoundError:
    ...
Class When
To11aiApiError non-2xx API response (status_code, error_code, details)
To11aiAuthError 401/403
To11aiRateLimitError 429 (retry_after_seconds)
To11aiValidationError 400
To11aiNetworkError network failure / timeout
PromptNotFoundError · LabelNotFoundError · PromptHasNoVersionsError · PromptPolicyViolationError typed prompt-resolution errors
UnknownRoleError an unrecognized message role with on_unknown_role="error"
To11aiResponseValidationError a 2xx body that fails schema validation

Documentation

Full reference: https://to11.ai/docs/reference/python-sdk. Licensed under MPL-2.0.

Metadata

Release files for to11ai-sdk 3.1.0rc0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for to11ai-sdk 3.1.0rc0
File Size Uploaded Provenance Actions
to11ai_sdk-3.1.0rc0.tar.gz 146.0 kB Without provenance Details for to11ai_sdk-3.1.0rc0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for to11ai-sdk 3.1.0rc0
File Interpreter ABI Platform Actions
to11ai_sdk-3.1.0rc0-py3-none-any.whl Python 3 none any Details for to11ai_sdk-3.1.0rc0-py3-none-any.whl

Total release size: 212.1 kB

Release files / to11ai_sdk-3.1.0rc0.tar.gz

Download URL to11ai_sdk-3.1.0rc0.tar.gz
Size 146.0 kB
Tags Source
SHA-256 checksum
How to use checksums
810a3e9fb3067978339ef61a8f8ac9f13f713946507a0dcd679dd22b699fe7b3
BLAKE2b-256 checksum
How to use checksums
8deb783884bfa47504766e3e7776397deed4e69c031417cf61bbaecdc21213c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / to11ai_sdk-3.1.0rc0-py3-none-any.whl

Download URL to11ai_sdk-3.1.0rc0-py3-none-any.whl
Size 66.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7f6bd39dc161e25e1d795d2f5c3bda62154beed7213893df9edaa41688c0bee
BLAKE2b-256 checksum
How to use checksums
a81c4947123aea685a30a3a2624242ff63cd6354b838e34dca157a056c462b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for to11ai-sdk 3.1.0rc0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page