---
title: Generate Features | Tabstack
description: Use AI to transform and analyze web content with the Tabstack TypeScript SDK Generate operator.
---

The Generate operator uses AI to transform and analyze web content according to your instructions. Unlike Extract which pulls data as-is, Generate creates new insights, summaries, and transformations of the original content.

## Overview

The `generate` operator is accessed through your Tabstack client instance:

- [TypeScript](#tab-panel-308)
- [JavaScript](#tab-panel-309)

```
import Tabstack from "@tabstack/sdk";


const client = new Tabstack({
  apiKey: process.env.TABSTACK_API_KEY!,
});


// Access generate methods
client.generate.json({ url, json_schema, instructions });
```

```
const Tabstack = require("@tabstack/sdk").default;


const client = new Tabstack({
  apiKey: process.env.TABSTACK_API_KEY,
});


// Access generate methods
client.generate.json({ url, json_schema, instructions });
```

## When to Use Generate vs Extract

**Extract** pulls data as it appears on the page:

```
// Extract: Get the exact price shown on the page
const result = await client.extract.json({ url, json_schema: priceSchema });
// Returns: { price: 99.99 }
```

**Generate** transforms and analyzes content with AI:

```
// Generate: Analyze pricing and create insights
const result = await client.generate.json({
  url,
  json_schema: analysisSchema,
  instructions:
    "Analyze the pricing strategy and categorize it as budget, mid-range, or premium",
});
// Returns: { price: 99.99, category: "mid-range", analysis: "..." }
```

## Generate JSON

Transform web content into structured data using AI with custom instructions.

### Basic Usage

- [TypeScript](#tab-panel-310)
- [JavaScript](#tab-panel-311)

```
const schema = {
  type: "object",
  properties: {
    summaries: {
      type: "array",
      items: {
        type: "object",
        properties: {
          title: { type: "string" },
          category: { type: "string" },
          summary: { type: "string" },
        },
        required: ["title", "category", "summary"],
      },
    },
  },
  required: ["summaries"],
};


const result = await client.generate.json({
  url: "https://news.ycombinator.com",
  json_schema: schema,
  instructions:
    "For each story, categorize it (tech, business, science, etc.) and write a one-sentence summary",
});


console.log(result.summaries);
```

```
const schema = {
  type: "object",
  properties: {
    summaries: {
      type: "array",
      items: {
        type: "object",
        properties: {
          title: { type: "string" },
          category: { type: "string" },
          summary: { type: "string" },
        },
        required: ["title", "category", "summary"],
      },
    },
  },
  required: ["summaries"],
};


const result = await client.generate.json({
  url: "https://news.ycombinator.com",
  json_schema: schema,
  instructions:
    "For each story, categorize it (tech, business, science, etc.) and write a one-sentence summary",
});


console.log(result.summaries);
```

**Example Output:**

```
{
  "summaries": [
    {
      "title": "New AI Model Released",
      "category": "tech",
      "summary": "A breakthrough language model with improved reasoning capabilities was announced today."
    },
    {
      "title": "Database Performance Tips",
      "category": "tech",
      "summary": "Key strategies for optimizing database queries and indexing in production systems."
    }
  ]
}
```

## Real-World Examples

### Example 1: Sentiment Analysis

Analyze the sentiment and tone of web content:

- [TypeScript](#tab-panel-312)
- [JavaScript](#tab-panel-313)

```
interface SentimentAnalysis {
  overallSentiment: "positive" | "negative" | "neutral";
  confidence: number;
  keyPhrases: string[];
  emotionalTone: string;
  mainTopics: string[];
}


const schema = {
  type: "object",
  properties: {
    overallSentiment: {
      type: "string",
      enum: ["positive", "negative", "neutral"],
    },
    confidence: {
      type: "number",
      description: "Confidence score from 0 to 1",
    },
    keyPhrases: {
      type: "array",
      items: { type: "string" },
      description: "Important phrases that indicate sentiment",
    },
    emotionalTone: {
      type: "string",
      description: "Description of the emotional tone",
    },
    mainTopics: {
      type: "array",
      items: { type: "string" },
    },
  },
  required: ["overallSentiment", "confidence"],
};


const result = (await client.generate.json({
  url: "https://reviews.example.com/product/123",
  json_schema: schema,
  instructions:
    "Analyze the overall sentiment of the product reviews, extract key phrases, and identify main topics discussed",
})) as SentimentAnalysis;


console.log(
  `Sentiment: ${result.overallSentiment} (${result.confidence * 100}% confident)`,
);
console.log(`Tone: ${result.emotionalTone}`);
console.log(`Key phrases: ${result.keyPhrases.join(", ")}`);
console.log(`Topics: ${result.mainTopics.join(", ")}`);
```

```
const schema = {
  type: "object",
  properties: {
    overallSentiment: {
      type: "string",
      enum: ["positive", "negative", "neutral"],
    },
    confidence: {
      type: "number",
      description: "Confidence score from 0 to 1",
    },
    keyPhrases: {
      type: "array",
      items: { type: "string" },
      description: "Important phrases that indicate sentiment",
    },
    emotionalTone: {
      type: "string",
      description: "Description of the emotional tone",
    },
    mainTopics: {
      type: "array",
      items: { type: "string" },
    },
  },
  required: ["overallSentiment", "confidence"],
};


const result = await client.generate.json({
  url: "https://reviews.example.com/product/123",
  json_schema: schema,
  instructions:
    "Analyze the overall sentiment of the product reviews, extract key phrases, and identify main topics discussed",
});


console.log(
  `Sentiment: ${result.overallSentiment} (${result.confidence * 100}% confident)`,
);
console.log(`Tone: ${result.emotionalTone}`);
console.log(`Key phrases: ${result.keyPhrases.join(", ")}`);
console.log(`Topics: ${result.mainTopics.join(", ")}`);
```

### Example 2: Content Categorization and Tagging

Automatically categorize and tag articles:

- [TypeScript](#tab-panel-314)
- [JavaScript](#tab-panel-315)

```
interface CategorizedArticle {
  title: string;
  primaryCategory: string;
  secondaryCategories: string[];
  tags: string[];
  targetAudience: string;
  readingLevel: "beginner" | "intermediate" | "advanced";
  estimatedReadingTime: number;
}


const schema = {
  type: "object",
  properties: {
    title: { type: "string" },
    primaryCategory: {
      type: "string",
      description: "Main category (e.g., Technology, Business, Health)",
    },
    secondaryCategories: {
      type: "array",
      items: { type: "string" },
    },
    tags: {
      type: "array",
      items: { type: "string" },
      description: "Relevant keywords and topics",
    },
    targetAudience: {
      type: "string",
      description: "Description of intended audience",
    },
    readingLevel: {
      type: "string",
      enum: ["beginner", "intermediate", "advanced"],
    },
    estimatedReadingTime: {
      type: "number",
      description: "Reading time in minutes",
    },
  },
  required: ["title", "primaryCategory", "tags", "readingLevel"],
};


const result = (await client.generate.json({
  url: "https://blog.example.com/article",
  json_schema: schema,
  instructions:
    "Categorize this article, identify relevant tags, determine the target audience, assess reading difficulty, and estimate reading time",
})) as CategorizedArticle;


console.log(`Title: ${result.title}`);
console.log(`Category: ${result.primaryCategory}`);
console.log(`Level: ${result.readingLevel}`);
console.log(`Reading Time: ${result.estimatedReadingTime} minutes`);
console.log(`Tags: ${result.tags.join(", ")}`);
```

```
const schema = {
  type: "object",
  properties: {
    title: { type: "string" },
    primaryCategory: {
      type: "string",
      description: "Main category (e.g., Technology, Business, Health)",
    },
    secondaryCategories: {
      type: "array",
      items: { type: "string" },
    },
    tags: {
      type: "array",
      items: { type: "string" },
      description: "Relevant keywords and topics",
    },
    targetAudience: {
      type: "string",
      description: "Description of intended audience",
    },
    readingLevel: {
      type: "string",
      enum: ["beginner", "intermediate", "advanced"],
    },
    estimatedReadingTime: {
      type: "number",
      description: "Reading time in minutes",
    },
  },
  required: ["title", "primaryCategory", "tags", "readingLevel"],
};


const result = await client.generate.json({
  url: "https://blog.example.com/article",
  json_schema: schema,
  instructions:
    "Categorize this article, identify relevant tags, determine the target audience, assess reading difficulty, and estimate reading time",
});


console.log(`Title: ${result.title}`);
console.log(`Category: ${result.primaryCategory}`);
console.log(`Level: ${result.readingLevel}`);
console.log(`Reading Time: ${result.estimatedReadingTime} minutes`);
console.log(`Tags: ${result.tags.join(", ")}`);
```

### Example 3: Extract Key Insights

Pull out the most important information from long-form content:

- [TypeScript](#tab-panel-316)
- [JavaScript](#tab-panel-317)

```
interface ArticleInsights {
  mainThesis: string;
  keyPoints: string[];
  conclusions: string[];
  actionItems: string[];
  relevantQuotes: Array<{
    quote: string;
    context: string;
  }>;
}


const schema = {
  type: "object",
  properties: {
    mainThesis: {
      type: "string",
      description: "The primary argument or purpose of the article",
    },
    keyPoints: {
      type: "array",
      items: { type: "string" },
      description: "Main points supporting the thesis",
    },
    conclusions: {
      type: "array",
      items: { type: "string" },
      description: "Key conclusions or takeaways",
    },
    actionItems: {
      type: "array",
      items: { type: "string" },
      description: "Actionable recommendations",
    },
    relevantQuotes: {
      type: "array",
      items: {
        type: "object",
        properties: {
          quote: { type: "string" },
          context: { type: "string" },
        },
      },
    },
  },
  required: ["mainThesis", "keyPoints", "conclusions"],
};


const result = (await client.generate.json({
  url: "https://research.example.com/paper",
  json_schema: schema,
  instructions:
    "Extract the main thesis, key supporting points, conclusions, and actionable recommendations. Include 2-3 relevant quotes with context.",
})) as ArticleInsights;


console.log("Main Thesis:");
console.log(result.mainThesis);
console.log("\nKey Points:");
result.keyPoints.forEach((point, i) => {
  console.log(`${i + 1}. ${point}`);
});
console.log("\nAction Items:");
result.actionItems.forEach((item, i) => {
  console.log(`${i + 1}. ${item}`);
});
```

```
const schema = {
  type: "object",
  properties: {
    mainThesis: {
      type: "string",
      description: "The primary argument or purpose of the article",
    },
    keyPoints: {
      type: "array",
      items: { type: "string" },
      description: "Main points supporting the thesis",
    },
    conclusions: {
      type: "array",
      items: { type: "string" },
      description: "Key conclusions or takeaways",
    },
    actionItems: {
      type: "array",
      items: { type: "string" },
      description: "Actionable recommendations",
    },
    relevantQuotes: {
      type: "array",
      items: {
        type: "object",
        properties: {
          quote: { type: "string" },
          context: { type: "string" },
        },
      },
    },
  },
  required: ["mainThesis", "keyPoints", "conclusions"],
};


const result = await client.generate.json({
  url: "https://research.example.com/paper",
  json_schema: schema,
  instructions:
    "Extract the main thesis, key supporting points, conclusions, and actionable recommendations. Include 2-3 relevant quotes with context.",
});


console.log("Main Thesis:");
console.log(result.mainThesis);
console.log("\nKey Points:");
result.keyPoints.forEach((point, i) => {
  console.log(`${i + 1}. ${point}`);
});
console.log("\nAction Items:");
result.actionItems.forEach((item, i) => {
  console.log(`${i + 1}. ${item}`);
});
```

### Example 4: Comparative Analysis

Compare multiple items and generate insights:

- [TypeScript](#tab-panel-318)
- [JavaScript](#tab-panel-319)

```
interface ProductComparison {
  products: Array<{
    name: string;
    price: number;
    pros: string[];
    cons: string[];
    bestFor: string;
  }>;
  recommendation: string;
  valueLeader: string;
  premiumChoice: string;
}


const schema = {
  type: "object",
  properties: {
    products: {
      type: "array",
      items: {
        type: "object",
        properties: {
          name: { type: "string" },
          price: { type: "number" },
          pros: { type: "array", items: { type: "string" } },
          cons: { type: "array", items: { type: "string" } },
          bestFor: {
            type: "string",
            description: "Type of user or use case",
          },
        },
      },
    },
    recommendation: {
      type: "string",
      description: "Overall recommendation based on comparison",
    },
    valueLeader: { type: "string" },
    premiumChoice: { type: "string" },
  },
  required: ["products", "recommendation"],
};


const result = (await client.generate.json({
  url: "https://reviews.example.com/laptop-comparison",
  json_schema: schema,
  instructions:
    "Compare the laptops, list pros and cons for each, identify who each is best for, and provide an overall recommendation. Identify the value leader and premium choice.",
})) as ProductComparison;


console.log("Comparison Summary:");
console.log(result.recommendation);
console.log(`\nBest Value: ${result.valueLeader}`);
console.log(`Premium Choice: ${result.premiumChoice}`);


result.products.forEach((product) => {
  console.log(`\n${product.name} - $${product.price}`);
  console.log(`Best for: ${product.bestFor}`);
  console.log(`Pros: ${product.pros.join(", ")}`);
  console.log(`Cons: ${product.cons.join(", ")}`);
});
```

```
const schema = {
  type: "object",
  properties: {
    products: {
      type: "array",
      items: {
        type: "object",
        properties: {
          name: { type: "string" },
          price: { type: "number" },
          pros: { type: "array", items: { type: "string" } },
          cons: { type: "array", items: { type: "string" } },
          bestFor: {
            type: "string",
            description: "Type of user or use case",
          },
        },
      },
    },
    recommendation: {
      type: "string",
      description: "Overall recommendation based on comparison",
    },
    valueLeader: { type: "string" },
    premiumChoice: { type: "string" },
  },
  required: ["products", "recommendation"],
};


const result = await client.generate.json({
  url: "https://reviews.example.com/laptop-comparison",
  json_schema: schema,
  instructions:
    "Compare the laptops, list pros and cons for each, identify who each is best for, and provide an overall recommendation. Identify the value leader and premium choice.",
});


console.log("Comparison Summary:");
console.log(result.recommendation);
console.log(`\nBest Value: ${result.valueLeader}`);
console.log(`Premium Choice: ${result.premiumChoice}`);


result.products.forEach((product) => {
  console.log(`\n${product.name} - $${product.price}`);
  console.log(`Best for: ${product.bestFor}`);
  console.log(`Pros: ${product.pros.join(", ")}`);
  console.log(`Cons: ${product.cons.join(", ")}`);
});
```

## Writing Effective Instructions

The quality of your results depends heavily on your instructions. Here are best practices:

### Be Specific and Clear

```
// Vague
"Analyze this content";


// Specific
"Analyze the sentiment of customer reviews, categorize each as positive/negative/neutral, and extract common themes";
```

### Define Expected Output

```
// Unclear output
"Summarize the articles";


// Clear expectations
"For each article, write a 2-sentence summary focusing on the main finding and its practical implications";
```

### Include Context

```
// No context
"Extract information";


// With context
"You are analyzing product reviews for a purchasing decision. Extract the most mentioned pros and cons, and identify any dealbreaker issues.";
```

### Use Examples When Helpful

```
const instructions = `
Categorize each product review as positive, negative, or mixed.
Examples:
- "Great product, works perfectly!" → positive
- "Terrible quality, broke after one week" → negative
- "Good features but poor battery life" → mixed
`;
```

## Options Reference

### GenerateJsonOptions

| Option         | Type                  | Default | Description                                                                     |
| -------------- | --------------------- | ------- | ------------------------------------------------------------------------------- |
| `url`          | `string`              | -       | The URL to generate content from                                                |
| `json_schema`  | `object`              | -       | JSON schema defining the output structure                                       |
| `instructions` | `string`              | -       | Instructions for the AI to follow                                               |
| `geoTarget`    | `{ country: string }` | -       | Geotargeting parameters for region-specific content (e.g., `{ country: 'GB' }`) |
| `nocache`      | `boolean`             | `false` | Bypass cache and force fresh generation                                         |

## Combining Generate with Extract

You can combine Extract and Generate for powerful workflows:

- [TypeScript](#tab-panel-320)
- [JavaScript](#tab-panel-321)

```
// Step 1: Extract raw data
const extractSchema = {
  type: "object",
  properties: {
    products: {
      type: "array",
      items: {
        type: "object",
        properties: {
          name: { type: "string" },
          price: { type: "number" },
          description: { type: "string" },
        },
      },
    },
  },
};


const extracted = await client.extract.json({
  url,
  json_schema: extractSchema,
});


// Step 2: Generate insights from extracted data
const generateSchema = {
  type: "object",
  properties: {
    analysis: {
      type: "object",
      properties: {
        priceRange: { type: "string" },
        averagePrice: { type: "number" },
        productCategories: { type: "array", items: { type: "string" } },
        recommendations: { type: "array", items: { type: "string" } },
      },
    },
  },
};


const generated = await client.generate.json({
  url,
  json_schema: generateSchema,
  instructions:
    "Analyze the product lineup, determine price ranges, categorize products, and provide purchasing recommendations",
});


console.log("Product Analysis:", generated.analysis);
```

```
// Step 1: Extract raw data
const extractSchema = {
  type: "object",
  properties: {
    products: {
      type: "array",
      items: {
        type: "object",
        properties: {
          name: { type: "string" },
          price: { type: "number" },
          description: { type: "string" },
        },
      },
    },
  },
};


const extracted = await client.extract.json({
  url,
  json_schema: extractSchema,
});


// Step 2: Generate insights from extracted data
const generateSchema = {
  type: "object",
  properties: {
    analysis: {
      type: "object",
      properties: {
        priceRange: { type: "string" },
        averagePrice: { type: "number" },
        productCategories: { type: "array", items: { type: "string" } },
        recommendations: { type: "array", items: { type: "string" } },
      },
    },
  },
};


const generated = await client.generate.json({
  url,
  json_schema: generateSchema,
  instructions:
    "Analyze the product lineup, determine price ranges, categorize products, and provide purchasing recommendations",
});


console.log("Product Analysis:", generated.analysis);
```

## Best Practices

### 1. Use Descriptive Schema Properties

Include `description` fields to guide the AI:

```
const schema = {
  type: "object",
  properties: {
    sentiment: {
      type: "string",
      enum: ["positive", "negative", "neutral"],
      description: "Overall sentiment based on tone and language used",
    },
    confidence: {
      type: "number",
      description: "Confidence level from 0 to 1, where 1 is very confident",
    },
  },
};
```

### 2. Be Mindful of Costs

Generate operations use AI and are more expensive than Extract. Use them when you need analysis, not just data extraction.

```
// Good: Use Extract for straightforward data
const prices = await client.extract.json({ url, json_schema: priceSchema });


// Wasteful: Using Generate when Extract would work
const prices = await client.generate.json({
  url,
  json_schema: priceSchema,
  instructions: "Get the prices",
});
```

### 3. Test Instructions Iteratively

Start simple and refine based on results:

```
// Iteration 1: Basic
"Summarize the article";


// Iteration 2: More specific
"Summarize the article in 3 sentences, focusing on key findings";


// Iteration 3: Optimized
"Summarize the article in 3 sentences. Focus on: 1) main finding, 2) methodology, 3) practical implications for developers";
```

### 4. Handle Variable Content

Account for pages that might not have all expected content:

```
const schema = {
  type: "object",
  properties: {
    sentiment: { type: "string" },
    keyPoints: {
      type: "array",
      items: { type: "string" },
      description: "Main points if present; empty array if none found",
    },
  },
};
```

## Next Steps

- **[Automate Features](./automate)**: Execute complex browser automation tasks
- **[Error Handling](./error-handling)**: Build robust applications with proper error handling
- **[REST API Reference](/api/index.md)**: See the underlying REST API endpoint
