Type Safe
Back to integrations
Official SDKVerifiedAvailable2026-09-23

TypeSafe Python SDK

A minimal server-side Python quickstart based only on the public official SDK example, with explicit notes where production controls still require verification.

Install

uv add typesafe-sdk

Server environment variables

TYPESAFE_API_KEY

Prerequisites

  • A supported Python environment
  • A TypeSafe API key stored outside source control
  • The current Python SDK documentation

Implementation steps

  1. 1Install the official typesafe-sdk package.
  2. 2Set TYPESAFE_API_KEY in the server environment.
  3. 3Create a TypeSafeClient inside a context manager.
  4. 4Submit state and named Choice criteria.
  5. 5Read the selected choice from the response.
  6. 6Add verified timeout, retry, validation, and human-review controls before production use.
Server example
import os

from typesafe_sdk import Choice, TypeSafeClient

api_key = os.environ.get("TYPESAFE_API_KEY")
if not api_key:
    raise RuntimeError("TYPESAFE_API_KEY is required")

with TypeSafeClient(api_key=api_key) as client:
    response = client.system_one(
        state={"ticket": "I was charged twice. Please fix this ASAP."},
        questions={
            "route": Choice(
                instructions="Choose the support queue.",
                criteria={
                    "billing": "Payments, invoices, refunds, or duplicate charges",
                    "technical": "Product behavior, errors, or integrations",
                    "other": "Everything else",
                },
            )
        },
    )

print({"route": response.choices["route"].choice})

Production checks

  • Keep credentials in a secret manager or server environment.
  • Validate response fields before using them in an automated action.
  • Use a bounded request timeout and retry policy after checking the installed SDK version.
  • Route ambiguous or high-impact decisions to a person.

Limitations and verification notes

Timeout and retry constructor options were not verified in the public README reviewed on 2026-09-23, so this example does not invent them. Check the current SDK reference before production use.

Sources

This guide is independently maintained by Type Safe. Check the provider’s current documentation, versions, and terms before use.