TypeScript SDK
Call the Teak API from TypeScript with the typed teak-sdk client
teak-sdk is the typed client for the Teak API. It is one bundle with no runtime dependencies, published to npm with the same version as the other Teak apps. The CLI, the browser extension and Raycast use it too.
Install
npm install teak-sdkpnpm add teak-sdkyarn add teak-sdkbun add teak-sdknub add teak-sdkaube add teak-sdkCreate a client
import { createTeakClient, staticTokenProvider } from "teak-sdk";
const client = createTeakClient({
baseUrl: "https://teakvault.com/api",
tokenProvider: staticTokenProvider(process.env.TEAK_API_KEY!),
});
await client.cards.create({ content: "A note from my script", tags: ["research"] });
const page = await client.cards.search({ query: "typography" });
baseUrl defaults to https://teakvault.com/api, and requests time out after 10 seconds unless you pass timeoutMs. Use an API key from Settings → Security → API keys, or an OAuth access token from sign-in.
What the client covers
The client covers every API endpoint: cards.list, search, favorites (with trashed, archived, style, hue, and hex filters), get, create, update (including removeAiTags), setFavorite, setArchived, delete (pass { permanent: true } to skip Trash), restore, refresh, content, duplicate, bulk, changes, setThumbnail (bytes and a MIME type, or { fileKey } from createThumbnailUpload), and resetThumbnail (with a folder filter on the listings, and folderIds on update), plus folders.list, get, create, update, delete, addCards, and removeCards, tags.list, rename, merge, delete, and operation, uploads, me, and exports.start / exports.latest.
- Pass
{ idempotencyKey }tocards.createorcards.bulkto make retries safe. - Errors are
TeakApiErrors with acode,status,retryAt, and the response’srequestId.ERROR_CODESlists every code. formatBytes(card.fileSize)turns a file size into the label Teak shows, such as4.6 MBor50 MB.
Token providers
A TokenProvider has getAccessToken(), which returns the token for each request, and an optional onUnauthorized(rejectedToken: string). When a request returns a retry-eligible 401, onUnauthorized receives the access token that request used. Return a refreshed or newer stored token to retry the request once, or null to stop. Compare the rejected token with the current session before refreshing: a late response may refer to an older token, and refreshing for it could replace newer credentials.
Sign in with WorkOS Connect
The SDK includes the WorkOS Connect sign-in steps that the CLI, Raycast, and the browser extension use:
discoverAuthServer("https://teakvault.com/api")returns the deployment’s sign-in endpoints and the client ID for your surface. Discover again after a sign-in or refresh failure.randomBase64UrlandcreatePkceChallengefor PKCE, andcreateConnectAuthorizeUrlfor the browser step.requestConnectTokensfor code and refresh grants. It returnsrefresh_token_rejectedonly when WorkOS says the refresh token is no longer valid; treat other failures as temporary and keep the saved sign-in.fetchConnectOwnerIdbinds the tokens to an account, anddisconnectConnectGrantsigns the surface out.
The SDK never stores credentials or opens a browser. Keep tokens in your platform’s secure storage.