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
Createapp/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()) to call the ScrapeGraphAI API directly without an API route, keeping your key secure on the server. - Define a Zod schema and pass it via
output_schemato get typed, structured data back.
Never pass
SGAI_API_KEY to a client component. Keep it on the server side.