How to integrate Bright Data’s web scraping and proxy capabilities with Vercel AI SDK to add real-time web data access to AI applications. Spans 195 countries.
You might be eligible for our Startup Program. Get fully funded access to the infrastructure you’re reading about right now (up to $50K value).
Vercel AI SDK is a TypeScript toolkit for building AI applications with React, Next.js, Vue, Svelte, Node.js, and more. It provides a unified API for working with different AI providers and includes utilities for streaming, function calling, and building conversational interfaces.The @brightdata/ai-sdk package gives you drop-in tools for web scraping, search, and structured dataset collection, no manual wiring required.
Install the Bright Data AI SDK package alongside the Vercel AI SDK:
npm install @brightdata/ai-sdk ai zod
Set your API key as an environment variable:
.env.local
BRIGHTDATA_API_KEY=your_api_key_here
3
Import and Use
Import the tools you need directly from @brightdata/ai-sdk and pass them to any Vercel AI SDK call.
No additional setup files or wrappers needed, each tool is a factory function that reads your API key
automatically from BRIGHTDATA_API_KEY.
import { scrape, search, amazon_product, linkedin_profile } from '@brightdata/ai-sdk'import { generateText, stepCountIs } from 'ai'import { openai } from '@ai-sdk/openai'const { text } = await generateText({ model: openai('gpt-4o'), prompt: 'Scrape https://news.ycombinator.com and summarize the top 5 stories', tools: { scrape: scrape(), }, stopWhen: stepCountIs(5),})console.log(text)
4
Usage Examples
Next.js App Router
Node.js Script
Custom API Key
Social & Dataset Tools
Create an API route that uses Bright Data tools with any AI provider:
import { anthropic } from '@ai-sdk/anthropic'import { generateText, stepCountIs } from 'ai'import { scrape, search, amazon_product } from '@brightdata/ai-sdk'async function main() { // Example 1: Scrape a website console.log('=== Example 1: Web Scraping ===') const scrapeResult = await generateText({ model: anthropic('claude-opus-4-6'), tools: { scrape: scrape() }, stopWhen: stepCountIs(10), prompt: 'Scrape https://news.ycombinator.com and summarize the top 5 stories', }) console.log(scrapeResult.text) // Example 2: Web search console.log('\n=== Example 2: Web Search ===') const searchResult = await generateText({ model: anthropic('claude-opus-4-6'), tools: { search: search() }, stopWhen: stepCountIs(10), prompt: 'Search for the latest JavaScript frameworks and tell me about the top 3', }) console.log(searchResult.text) // Example 3: Amazon product research console.log('\n=== Example 3: Amazon Product ===') const amazonResult = await generateText({ model: anthropic('claude-opus-4-6'), tools: { amazon_product: amazon_product() }, stopWhen: stepCountIs(10), prompt: "Get details about this product: https://www.amazon.com/dp/B0D2Q9397Y and tell me if it's worth buying", }) console.log(amazonResult.text)}main()
Pass the API key directly to any tool instead of relying on the environment variable:
import { scrape, search } from '@brightdata/ai-sdk'import { generateText, stepCountIs } from 'ai'import { openai } from '@ai-sdk/openai'const { text } = await generateText({ model: openai('gpt-4o'), prompt: 'Search for AI news today', tools: { scrape: scrape({ api_key: 'your-api-key-here' }), search: search({ api_key: 'your-api-key-here' }), }, stopWhen: stepCountIs(5),})
Use the structured dataset tools for LinkedIn, Instagram, Facebook, and more:
import { linkedin_profile, linkedin_jobs, instagram_profile, facebook_profile } from '@brightdata/ai-sdk'import { generateText, stepCountIs } from 'ai'import { openai } from '@ai-sdk/openai'const { text } = await generateText({ model: openai('gpt-4o'), prompt: 'Find AI engineering jobs in San Francisco on LinkedIn', tools: { linkedin_profile: linkedin_profile(), linkedin_jobs: linkedin_jobs(), instagram_profile: instagram_profile(), facebook_profile: facebook_profile(), }, stopWhen: stepCountIs(10),})
Prompt: “Scrape https://example.com and tell me what it’s about”AI Response:
I've scraped the website. Here's what I found:# Example DomainThis domain is for use in illustrative examples in documents. You may use thisdomain in literature without prior coordination or asking for permission.The website appears to be a placeholder domain used for documentation andexamples. It's maintained by IANA (Internet Assigned Numbers Authority) andserves as a standard example domain that can be referenced in documentationwithout needing permission.
Prompt: “Search for best mechanical keyboards 2025”AI Response:
I found several highly-rated mechanical keyboards for 2025:1. **Keychron Q1 Pro** — Premium 75% layout, hot-swappable switches, wireless. ~$200.2. **Wooting 60HE** — Analog switches with adjustable actuation points, popular among gamers.3. **GMMK Pro** — 75% gasket-mounted, extensive customization options.