TypeScript SDK
Call the Teak API from TypeScript with the typed teak-sdk client
teak-sdk is the typed client for the Teak API: one bundle with no runtime dependencies, versioned with 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 → Integrations → API keys, or an OAuth access token from sign-in.
What the client covers
Each method calls one API operation and follows its rules, limits and errors:
- Cards:
cards.list,search,favorites,pinned,similar,get,links,content({ kind: "article" }for a link’s article),create,update,duplicate,setFavorite,setPinned,reorderPinned,setArchived,setDone,savePdf,refresh,setThumbnail(bytes and a MIME type, or{ fileKey }fromcreateThumbnailUpload),resetThumbnail,delete({ permanent: true }deletes a card in Trash for good),restore,bulk, andchanges. Listings take the same filters asGET /v1/cards(CARD_LIST_PARAMSlists them, with what each takes;SEARCH_QUERY_HELPdescribes every search qualifier), and anAbortSignalas{ signal }. - Folders:
folders.list,get,create,update(including a manual folder’s rules),delete,addCards,removeCards,getRuleRun,waitForRuleRun, andundoRuleRun. - Tags:
tags.list,rename,merge,delete,operation, andwaitFor. - Highlights:
highlights.list(cardId),create(cardId, { quote, note?, prefix?, suffix? }),update(id, { note }), anddelete(id). - Everything else:
me,uploads.createanduploads.putFile,exports.start,exports.latestandexports.waitFor, andpageSnapshots.createUpload, which lets a browser extension send the page it shows as a link’s saved copy.
A few methods run a whole task:
cards.createFromFile({ bytes, fileName, mimeType?, tags?, notes? })checks the file is a type and size Teak takes, uploads it and creates its card.onUploadedhands you the finished upload; pass it back asuploadedto retry only the create.cards.pages(filters)iterates a listing page by page, followingnextCursor; stop iterating to stop fetching.tags.waitFor(operation),folders.waitForRuleRun(folderId, run)andexports.waitFor()poll background work until it finishes, backing off up to 3 seconds and giving up aftertimeoutMs(10 minutes by default). A tag change that stops making progress comes backfailed.waitFordoes the same for anything you poll yourself.
Pass { idempotencyKey } to cards.create, cards.createFromFile or cards.bulk to make retries safe. formatBytes(card.fileSize) turns a file size into the label Teak shows, such as 4.6 MB.
Errors and retries
Errors are TeakApiErrors with a code, status, retryAt, and the response’s requestId; ERROR_CODES lists every code. Each also has a kind to word it by: auth (sign in again; AUTH_ERROR_CODES), not_found, rate_limited, network, unavailable, invalid, limit, conflict, forbidden, config or server. The SDK’s own messages name no client, so show them as they are or replace them by kind. An answer that isn’t JSON, such as a proxy’s HTML error page, is named by its status (UNAUTHORIZED, RATE_LIMITED, SERVICE_UNAVAILABLE…), and retryAt comes from Retry-After when the body has none.
Reads, and writes sent with an idempotencyKey, are retried up to twice when Teak is busy (429, 502, 503, 504, or a 409 IN_PROGRESS replay) or the network drops, waiting as long as Retry-After asks, up to 5 seconds; a longer wait is returned as the error. Pass retries: 0 to createTeakClient to turn this off. Writes without a key are never sent twice.
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
createOAuthSession({ apiUrl, surface, store, lock }) is the whole sign-in, as the CLI and the browser extension use it. You give it where to keep the tokens (store.read and store.write, where null clears them) and, if several processes share them, a lock; it gives you:
tokenProvider()forcreateTeakClient. It sends a saved token without discovery while it has more than a minute left (ACCESS_TOKEN_REFRESH_MARGIN_MS), refreshes it once for concurrent requests and saves the rotated refresh token first, refreshes after a 401 and sends the request again, keeps the sign-in through an outage, and clears it only when WorkOS refuses the refresh token.tokenProvider({ ownerId })refuses another account’s sign-in.signIn({ redirectUri, authorize }), whereauthorize(url)opens the URL in a browser and returns the redirect it ends on. It checks the state, exchanges the code, confirms the account, and disconnects a sign-in it replaces.signOut(), which disconnects the grant and clears it."signed-out-here"means the grant was already dead, so other installations stay connected until they’re disconnected in Settings.
A failed step throws an OAuthSessionError whose reason (provider_changed, signed_out, sign_out_first, token_rejected…) you can word for your app.
The steps it is built from are exported too:
discoverAuthServer("https://teakvault.com/api")returns the deployment’s sign-in endpoints and the client ID for your surface, in one request, and caches the result for up to 60 seconds. You don’t need it while a saved access token is still fresh: send that token to the deployment it was issued for, and discover when you refresh it, after a 401, and at sign-in and sign-out. Pass{ forceRefresh: true }after a sign-in or refresh failure. For a cloud development backend with a local sign-in server, pass that server’s loopback origin aslocalIssuer; remote metadata can’t enable loopback by itself.randomBase64UrlandcreatePkceChallengefor PKCE, andcreateConnectAuthorizeUrlfor the browser step. It requests the right OAuth resource for the deployment.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.