TypeScript SDK Quickstart
Get up and running with the Tabstack TypeScript SDK in minutes. Installation, authentication, and your first API call.
Get up and running with the Tabstack TypeScript SDK in minutes. This guide will walk you through installation, authentication, and your first API call.
SDK Version: 2.9.0
Prerequisites
Section titled “Prerequisites”- Node.js >= 20.0.0
- Package manager: npm, yarn, pnpm, or bun
- Tabstack API key from console.tabstack.ai
Installation
Section titled “Installation”Install the SDK using your preferred package manager:
npm install @tabstack/sdkyarn add @tabstack/sdkpnpm add @tabstack/sdkbun add @tabstack/sdkCreate and Setup Your API Key
Before you can start using Tabstack API, you’ll need to create an API key and set it up in your environment.
1. Create Your API Key
- Visit the Tabstack Console
- Sign in to your account (or create one if you haven’t already)
- Navigate to the API Keys section and click the “Manage API Keys”
- Once you are on the API Keys page, Click “Create New API Key”
- Give your key a descriptive name (e.g., “Development”, “Production”) and click the “Create API Key”
- Copy the generated API key and store it securely
2. Set Up Environment Variable
For security and convenience, we recommend storing your API key as an environment variable rather than hardcoding it in your scripts.
macOS/Linux
# Add to your shell profile (~/.bashrc, ~/.zshrc, or ~/.bash_profile)export TABSTACK_API_KEY="your_api_key_here"
# Or set it temporarily for the current sessionexport TABSTACK_API_KEY="your_api_key_here"
# Reload your shell or run:source ~/.bashrc # or ~/.zshrcWindows (Command Prompt)
# Set temporarily for current sessionset TABSTACK_API_KEY=your_api_key_here
# Set permanently (requires restart)setx TABSTACK_API_KEY "your_api_key_here"Windows (PowerShell)
# Set temporarily for current session$env:TABSTACK_API_KEY = "your_api_key_here"
# Set permanently for current user[Environment]::SetEnvironmentVariable("TABSTACK_API_KEY", "your_api_key_here", "User")3. Verify Your Setup
Test that your environment variable is set correctly:
macOS/Linux/Windows (Git Bash):
echo $TABSTACK_API_KEYWindows (Command Prompt):
echo %TABSTACK_API_KEY%Windows (PowerShell):
echo $env:TABSTACK_API_KEYYou should see your API key printed in the terminal.
Your First API Call
Section titled “Your First API Call”Let’s start with a simple markdown extraction to verify your setup:
import Tabstack from "@tabstack/sdk";
// Initialize the clientconst client = new Tabstack({ apiKey: process.env.TABSTACK_API_KEY!,});
// Extract markdown from a URLasync function extractMarkdown() { try { const result = await client.extract.markdown({ url: "https://example.com", }); console.log(result.content); } catch (error) { console.error("Error:", error.message); }}
extractMarkdown();Save this as quickstart.ts and run it with tsx, which runs TypeScript files that use import in any Node project:
npx tsx quickstart.tsconst Tabstack = require("@tabstack/sdk").default;
// Initialize the clientconst client = new Tabstack({ apiKey: process.env.TABSTACK_API_KEY,});
// Extract markdown from a URLasync function extractMarkdown() { try { const result = await client.extract.markdown({ url: "https://example.com", }); console.log(result.content); } catch (error) { console.error("Error:", error.message); }}
extractMarkdown();Response:
---title: Example Domainurl: https://example.com---
This domain is for use in documentation examples without needing permission. This is not a service; avoid relying on it for testing and monitoring purposes.Core Features
Section titled “Core Features”The SDK provides four main operators for working with web content:
Research
Section titled “Research”Ask a question and get back a cited answer from live sources. The call always streams: progress events arrive first, then the complete event carries the report and the pages it cited.
import Tabstack from "@tabstack/sdk";
const client = new Tabstack();
const stream = await client.agent.research({ query: "What are the main approaches to browser automation for AI agents?", mode: "fast",});
for await (const event of stream) { if (event.event === "error") { throw new Error(event.data.error.message); } if (event.event === "complete") { console.log(event.data.report); for (const page of event.data.metadata.citedPages ?? []) { console.log(`- ${page.title ?? "(untitled)"}: ${page.url}`); } }}Extract
Section titled “Extract”Convert web pages to structured data:
- Markdown: Convert HTML to clean Markdown format
- JSON: Extract structured data matching your schema
Generate
Section titled “Generate”Transform web content using AI:
- Summarize and analyze content
- Categorize and tag data
- Perform sentiment analysis
- Extract key insights with custom instructions
Automate
Section titled “Automate”Execute browser automation tasks with natural language:
- Web data collection with real-time updates
- Form filling and submission
- Multi-step workflows
- Streaming progress events
Quick Example: Extract Structured Data
Section titled “Quick Example: Extract Structured Data”Here’s a more advanced example that extracts structured data from a web page:
import Tabstack from "@tabstack/sdk";
const client = new Tabstack({ apiKey: process.env.TABSTACK_API_KEY!,});
// Define the data structure you wantconst schema = { type: "object", properties: { stories: { type: "array", items: { type: "object", properties: { title: { type: "string" }, points: { type: "number" }, author: { type: "string" }, }, required: ["title", "points", "author"], }, }, }, required: ["stories"],};
// Extract data matching the schemaasync function extractStories() { try { const result = await client.extract.json({ url: "https://news.ycombinator.com", json_schema: schema, }); console.log(result.stories); } catch (error) { console.error("Error:", error.message); }}
extractStories();const Tabstack = require("@tabstack/sdk").default;
const client = new Tabstack({ apiKey: process.env.TABSTACK_API_KEY,});
// Define the data structure you wantconst schema = { type: "object", properties: { stories: { type: "array", items: { type: "object", properties: { title: { type: "string" }, points: { type: "number" }, author: { type: "string" }, }, required: ["title", "points", "author"], }, }, }, required: ["stories"],};
// Extract data matching the schemaasync function extractStories() { try { const result = await client.extract.json({ url: "https://news.ycombinator.com", json_schema: schema, }); console.log(result.stories); } catch (error) { console.error("Error:", error.message); }}
extractStories();TypeScript Support
Section titled “TypeScript Support”The SDK is fully type-safe with complete TypeScript definitions:
import Tabstack, { ExtractJsonResponse } from "@tabstack/sdk";
// Define your data typeinterface Story { title: string; points: number; author: string;}
interface HackerNewsData { stories: Story[];}
// Define the schemaconst schema = { type: "object", properties: { stories: { type: "array", items: { type: "object", properties: { title: { type: "string" }, points: { type: "number" }, author: { type: "string" }, }, required: ["title", "points", "author"], }, }, }, required: ["stories"],};
// Get type-safe responsesconst client = new Tabstack({ apiKey: process.env.TABSTACK_API_KEY! });
async function getStories() { const result = (await client.extract.json({ url: "https://news.ycombinator.com", json_schema: schema, })) as HackerNewsData;
// TypeScript knows the structure of result result.stories.forEach((story) => { console.log(story.title); // Type-safe access });}
getStories();Client Configuration Options
Section titled “Client Configuration Options”The SDK client accepts several configuration options:
import Tabstack from "@tabstack/sdk";
const client = new Tabstack({ apiKey: process.env.TABSTACK_API_KEY!, maxRetries: 2, // Number of retries for failed requests (default: 2) // timeout: 120000, // Request timeout in ms. Leave unset to keep the per-endpoint defaults.});Leave timeout unset unless you have a reason to cap every call. Without it, each endpoint uses its own default: 3 minutes for extract.markdown, 5 minutes for extract.json and generate.json, and 10 minutes for agent.automate and agent.research. Setting timeout on the client replaces all of them, including on the streaming endpoints. To give one call longer, pass { timeout } as a request option instead. See Production Reliability.
Next Steps
Section titled “Next Steps”Now that you’re up and running:
- Generate Features: Discover AI-powered content transformation and analysis
- Automate Features: Execute complex browser automation tasks with streaming updates
- Error Handling: Build robust applications with proper error handling
Need Help?
Section titled “Need Help?”- API Reference: REST API Documentation
- GitHub: TypeScript SDK Repository
- Documentation: docs.tabstack.ai
- Support: support@tabstack.ai