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.0.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/sdkGet Your API Key
Section titled “Get Your API Key”Before you can start using the SDK, you’ll need to create an 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 “Manage API Keys”
- Click “Create New API Key”
- Give your key a descriptive name (e.g., “Development”, “Production”)
- Copy the generated API key and store it securely
Important: Your API key will only be shown once. Make sure to copy and store it in a secure location.
Set Up Environment Variable
Section titled “Set Up Environment Variable”For security and convenience, store your API key as an environment variable:
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")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();const 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 Domaindescription: Example Domainurl: https://example.comtype: website---
# Example Domain
This domain is for use in illustrative examples in documents. You may use thisdomain in literature without prior coordination or asking for permission.
[More information...](https://www.iana.org/domains/example)Core Features
Section titled “Core Features”The SDK provides three main operators for working with web content:
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
Learn more about Generate features →
Automate
Section titled “Automate”Execute browser automation tasks with natural language:
- Web scraping with real-time updates
- Form filling and submission
- Multi-step workflows
- Streaming progress events
Learn more about Automate features →
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!, timeout: 60000, // Request timeout in milliseconds (default: 60000) maxRetries: 2 // Number of retries for failed requests (default: 2)});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: [email protected]