SDK Reference

Threadline ships official SDKs for TypeScript and Python. Both expose the same core methods over a typed, idiomatic interface.

Installation

TypeScript / Node.js

npm install threadline-sdk

Python

pip install threadline

Initialization

TypeScript

import { Threadline } from "threadline-sdk"

const tl = new Threadline({ apiKey: process.env.THREADLINE_KEY! })

Python

from threadline import Threadline

tl = Threadline(api_key=os.environ["THREADLINE_KEY"])

Methods

get(userId: string) => Promise<Context>

Fetch the full structured context object for a user.

inject(userId: string, basePrompt: string) => Promise<{ injectedPrompt }>

Build an enriched system prompt by merging stored context into your base prompt.

update({ userId, userMessage, agentResponse }) => Promise<void>

Persist a new conversational turn and any facts extracted from it.

grant({ userId, scope, ttl }) => Promise<Grant>

Issue a scoped, time-bound grant to another agent or tool.

revoke(grantId: string) => Promise<void>

Immediately revoke a previously issued grant.

Full example

const { injectedPrompt } = await tl.inject(userId, basePrompt)

const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "system", content: injectedPrompt }],
})

await tl.update({
  userId,
  userMessage,
  agentResponse: response.choices[0].message.content,
})