How it works
v0 generates frontend components. ScrapeGraphAI runs server-side (e.g. in a Next.js API route or Server Action) to avoid exposing your API key and to bypass CORS restrictions.Setup
1. Generate your component with v0
Ask v0 to build a component, for example:Create a card component that displays a company name, description, and founding year fetched from an external API.
2. Add a Next.js API route
Install the v2 SDK:app/api/scrape/route.ts in your Next.js project:
3. Store your API key
AddSGAI_API_KEY to your .env.local file:
4. Fetch data inside your component
Tips
- Use Server Components (
async function Page()) or Server Actions to callsgai.extractdirectly without an API route — the key stays on the server. - Pass a
schema(JSON Schema or Zod-compiled JSON Schema) tosgai.extract({ url, prompt, schema })to get typed, structured data back.
Never pass
SGAI_API_KEY to a client component. Keep it on the server side.