Threads AI

API reference

Every public function and type, in TypeScript and Python.

This reference is generated from spec/api.json, the contract both implementations follow. Members that exist in the contract but are not built yet are left out; members built in one language only say so.

Naming

  • Functions and methods are lowerCamelCase in TypeScript and snake_case in Python: openThread and open_thread.
  • Types have the same PascalCase name in both.
  • Required inputs are positional. Everything else is one trailing options object in TypeScript and keyword-only arguments in Python, with the same names and defaults. The one exception is a test seam: a provider factory may take an optional TypeScript-only positional, such as the transport of exa, marked "Seam:".
  • Expected failures are values, not exceptions: TypeScript returns { ok: true, value } or { ok: false, error: { code, message } }, Python returns Ok[T] or Err[Failure]. Only ConfigError, for a definition that can't run, is thrown.

Packages

PackageTypeScriptPython
otel@threads/otelthreads.otel
core@threads/corethreads
host@threads/hostthreads.host
mcp@threads/mcpthreads.mcp
supermemory@threads/supermemorythreads.supermemory
zep@threads/zepthreads.zep
anthropic@threads/anthropicthreads.anthropic
openai@threads/openaithreads.openai
ai-sdk@threads/ai-sdk—
litellm—threads.litellm
e2b@threads/e2bthreads.e2b
daytona@threads/daytonathreads.daytona
modal@threads/modalthreads.modal
dev@threads/corethreads.dev
postgres@threads/postgresthreads.postgres
mem0@threads/mem0threads.mem0
slack@threads/slackthreads.slack
github@threads/githubthreads.github
whatsapp@threads/whatsappthreads.whatsapp
search@threads/corethreads.search

Functions

TypeScriptPythonWhat it does
agentagentDescribe an agent.
dynamicAgentdynamic_agentDescribe a dynamic agent: a template in a lead's team whose members the lead (or team.start) defines at runtime within what this code pins.
tooltoolDefine an app tool.
extensionextensionThe one extension primitive: tools, trusted instructions and hooks.
mcpmcpAn MCP server in one line.
secretsecretA reference to a host secret, resolved only in the host.
usdusdA US-dollar amount as the integer nano-dollars budgets and prices use: usd(0.5) is 500000000.
openThreadopen_threadA handle for inspection and control, independent of any in-memory run.
importThreadimport_threadStores a bundle written by thread.export, or a bare .jsonl export, and returns a handle on its leaf branch.
sqlitesqliteThe one log and artifact store.
localMemorylocal_memoryBuilt-in memory: SQLite FTS5 in the run's store.
localKnowledgelocal_knowledgeBuilt-in knowledge: SQLite FTS5 over admitted versions stored as artifacts.
scriptedModelscripted_modelTest kit.
fakeSandboxfake_sandboxTest kit.
hosthostBind agents to a store, channels and schedules.
openTeamopen_teamA Team handle for a team another process ran, or to act as another principal.
runEvalsrun_evalsRuns every saved case under cases through the checks, cheapest first: replay (the recorded requests re-render byte for byte with the code running now), rerun (the recorded turn reruns offline to the same events, with no model call and every effect stubbed), drift (with agents: the case's recorded config against each agent as it is pinned now, by a dry pin that runs no setup, reads no secret and connects to no MCP server) and, only with live, a judged run of the current agent.
assertNeverassert_neverEnds a switch over a union, so a variant nobody handles is a type error.

Providers

A provider factory connects an agent to an outside service and returns one of the protocol types below. Its page lists every option in both languages and the ConfigError codes it can raise. Options whose description starts with "Seam:" exist in one language to swap a transport or clock in tests.

TypeScriptPythonWhat it does
otelotelAn Exporter that sends each span of every thread in the store once, when it closes, to an OpenTelemetry collector over OTLP/HTTP JSON.
postgrespostgresThe log and artifact store on Postgres: every host process on every machine points at the same database.
supermemorysupermemoryA MemoryProvider that stores records in Supermemory.
zepzepA MemoryProvider that stores records in Zep.
anthropicanthropicA Claude model through the Messages API.
openaiopenaiAn OpenAI model through the Responses API (stateless: store is false).
aiSdkaiSdkAny AI SDK v4 language model as a threads Model, for the providers with no adapter of their own.
litellmlitellmA model behind LiteLLM's openai/ route: any OpenAI-compatible endpoint, named through base_url.
exaexaA web_search backend that searches with Exa (exa.ai).
tavilytavilyA web_search backend that searches with Tavily (tavily.com).
bravebraveA web_search backend that searches with Brave (search.brave.com).
e2be2bA Sandbox on an E2B cloud VM.
daytonadaytonaA Sandbox on Daytona.
modalmodalA Sandbox on Modal.
devSandboxdev_sandboxA Sandbox in a local directory on the host, inside an OS confinement (bubblewrap on Linux, sandbox-exec on macOS).
mem0mem0Mem0 memory: refused, since the mem0ai SDK sends outside any transport threads can fence (its constructor checks the key and it posts telemetry on its own).
slackslackA Slack channel.
githubgithubA GitHub channel.
whatsappwhatsappA WhatsApp Cloud API channel.

These providers exist but are not in the reference yet; their guides describe them: Models, Sandboxes, Host server and Memory.

Types

Agents and runs: Agent, RunResult, RunStream, RunContext, Tool, McpServer, Extension, Hooks, Skill, Secret, Store, ConfigError, ConfigErrorCode

Threads and evals: Thread, CaseExpectation, SavedCase

Host: Host, Schedule

Model adapters: Model, ModelContext, ModelInfo, ModelRequest, ModelResponse, ModelChunk, LookupResult, LookupCapability

Sandbox adapters: Sandbox, SandboxAuthority, SandboxContext, SandboxInfo, SandboxSession, ExecOutput, ExecResult

Memory and knowledge adapters: MemoryProvider, KnowledgeProvider, Scope, Binding, MemoryRecord, RecordRef, MemoryHit, KnowledgeSource, DocVersion, KnowledgeHit, Doc, SearchBackend, SearchHit

Channel adapters: ChannelAdapter, ChannelCapabilities, RawRequest, RawResponse, VerifiedDelivery, Inbound, DeliveryOutcome

Other types: Exporter, SyncReport, SkippedBranch, TeamAgent, DynamicAgent, TeamRunResult, TeamRunStream, ExportedBundle, Live, EvalReport, EvalCaseResult, Verdict, ModelBlockedError, Principal, Workspace, TeamRef, MemberRef, Team, StartRefusal, InvalidDefinition, SendRefusal, AskRefusal, ReplyRefusal, ObserveRefusal, CancelRefusal, OperatorRefusal, MemberState, MemberResult, StoredMemberResult, StartResult, SendResult, AskOutcome, AskResult, ReplyResult, Waited, WaitResult, MonitorResult, CancelResult, TeamStartResult, TeamSendResult, TeamAskResult, TeamWaitResult, TeamCancelResult, TeamMember, AskStatus, TeamCursor, TeamSource, TeamItem, StoreCorruptError, MessagePolicyRule

HTTP API

The host's HTTP API is documented from its OpenAPI file in the HTTP API reference.

Edit on GitHub

On this page