async.md

Async client

Use AsyncTypeSafeClient to ask questions, list models, and configure asynchronous TypeSafe API requests.

export function SdkSignature({children}) {
  async function copy(event) {
    const button = event.currentTarget;
    const code = button.parentElement.querySelector("pre code");
    try {
      await navigator.clipboard.writeText(code.textContent);
      button.setAttribute("aria-label", "Signature copied");
      button.dataset.copied = "true";
    } catch {
      button.setAttribute("aria-label", "Copy failed; select the signature to copy");
    }
    setTimeout(() => {
      button.setAttribute("aria-label", "Copy signature");
      delete button.dataset.copied;
    }, 2000);
  }
  return <div className="sdk-signature not-prose">
      <button type="button" className="sdk-signature-copy" aria-label="Copy signature" onClick={copy}>
        <svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
          <rect x="8" y="8" width="12" height="12" rx="2" />
          <path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" />
        </svg>
      </button>
      <pre tabIndex={0} aria-label="SDK signature"><code>{children}</code></pre>
    </div>;
}

typesafe_sdk.AsyncTypeSafeClient

Create an asynchronous HTTP client for TypeSafe AI API.

Explicit options take precedence over environment variables; empty or whitespace-only environment values are ignored.

Logging setup

The SDK logs to the typesafe_sdk logger; configure it through standard logging, or set TYPESAFE_LOG_LEVEL (debug, info, ...) for a quick default. Secret headers are redacted from log output; request and response bodies are not.

Parameters:

Raises:

Examples:

def main() -> None:
    async with AsyncTypeSafeClient() as client:
        result = await client.system_one(
            state="I was charged twice. Please help.",
            questions={
                "billing": Noul(instructions="Is this about billing?"),
                "tone": Choice(
                    instructions="What is the tone?",
                    criteria={"calm": None, "angry": None},
                ),
            },
        )
        assert 0 <= result.nouls["billing"].noul <= 1
        assert result.choices["tone"].choice in {"calm", "angry"}

models

cached property

typesafe_sdk.AsyncTypeSafeClient.models

An accessor for the Models API resource.

Examples:

def main() -> None:
    async with AsyncTypeSafeClient() as client:
        models = await client.models.list()

system_one

async

Parameters:

Returns:

Raises:

Examples: Create questions with named arguments:

def main() -> None:
    async with AsyncTypeSafeClient() as client:
        result = await client.system_one(...)

aclose

async

aclose() -> None

Release network resources and close the underlying HTTP client.