This site is not affiliated with or endorsed by Vercel, Inc. Read the docs, then deploy or run each experiment yourself.
AI

URL Brief Lab

Fetch a URL with size and timeout caps, stream a summary, and preview an ImageResponse Open Graph card.

Run this experiment yourself

Demos are not embedded on this site. Deploy a standalone copy on Vercel or run the experiment app locally.

Local development

cd apps/experiments/url-brief-lab
pnpm install
pnpm dev

Then open http://localhost:3010.

This is an experimental demo. Use it as a starting point for your own projects.

URL Brief Lab fetches a public http(s) URL on the server (8s timeout, ~500KB HTML cap), extracts title / meta description / rough text, streams a summary with streamText, and exposes an OG preview path consumed by GET /api/og (ImageResponse). Response headers carry x-page-title and x-og-preview for the client card.

Features

  • Capped server fetch – timeout + byte limit; only http: / https:.
  • HTML heuristics – extractTitle, extractMetaDescription, stripHtmlToText in logic.ts.
  • streamText summary – token stream to the browser with cancel support.
  • ImageResponse OG – /api/og?title=&description= preview image.
  • Honest 503 without AI keys (fetch still would not run the model).

Server Reference

POST /api/brief

{ "url": "https://example.com" }

Returns a text stream (toTextStreamResponse) with headers:

HeaderMeaning
x-ai-providerai-gateway or openai
x-page-titleURI-encoded page title
x-og-previewPath like /api/og?title=...&description=...

GET /api/og

Query: title, description. Returns a 1200×630 PNG via ImageResponse.

StatusCause
503No AI provider (brief only)
400Bad URL, upstream error, timeout, non-http(s)

Implementation Details

Fetch with AbortController

FETCH_TIMEOUT_MS = 8000, MAX_HTML_BYTES = 500_000.

Extract + stream

Build context from title/meta/text, then streamText. Attach OG path via buildOgPreviewPath.

OG route

app/api/og/route.tsx mirrors OG Image Studio’s ImageResponse approach with a simpler dark card.

Use Cases

  • Link previews with a streamed executive summary.
  • Teaching safe server-side fetch limits.
  • Pairing AI summaries with social card images.

Limitations

  • No SSRF allowlist beyond protocol check - do not expose to untrusted users without hardening.
  • HTML extraction is regex-based, not a full DOM parser.
  • JS-rendered SPAs may yield little text.
  • No auth / rate limits.

Use in your project

Reuse logic.ts extractors and the brief + og routes. Add domain allowlists before production.

Deployment

Deploy on Vercel

Local Development

cd apps/experiments/url-brief-lab
pnpm install
pnpm dev
curl -N -X POST http://localhost:3010/api/brief \
  -H "content-type: application/json" \
  -d '{"url":"https://vercel.com/docs"}'

Configuration

VariableRequiredPurpose
AI_GATEWAY_API_KEYYes (or OPENAI_API_KEY)Preferred provider
OPENAI_API_KEYNoFallback
AI_MODELNoModel override

Vercel / Next.js Features Used

  • AI SDK streamText
  • next/og ImageResponse
  • Route Handlers
  • Zod

Next Steps

On this page