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

Cost-Aware AI Lab

Run the same prompt on two models via AI Gateway and compare latency plus labeled token/cost ESTIMATES.

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/cost-aware-ai-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.

Cost-Aware AI Lab runs one prompt on two models (default gpt-4o-mini vs gpt-4o via Gateway), then shows latency, token usage, and a rough USD estimate clearly labeled as an estimate - not billing truth. Missing AI keys return 503.

Features

  • Dual model compare – parallel generateText runs.
  • Latency + tokens – from AI SDK usage when available.
  • Labeled estimates – public-rate heuristics, not invoices.
  • Honest 503 when AI is not configured.

Server Reference

POST /api/compare

{ "prompt": "..." }

Success (200)

{
  "runs": [
    {
      "model": "openai/gpt-4o-mini",
      "latencyMs": 420,
      "estimatedCostUsd": 0.0001,
      "estimateNote": "..."
    }
  ],
  "estimateDisclaimer": "..."
}
StatusCause
503No AI provider
400Empty prompt

Implementation Details

Resolve two models

AI_MODEL_A / AI_MODEL_B or defaults.

Estimate

estimateCostUsd from rough per-MTok tables - always labeled.

Use Cases

  • Teach cost awareness in demos.
  • Compare latency before picking a default model.

Limitations

  • Estimates are not Gateway invoices.
  • Token counts depend on provider usage fields.

Use in your project

Copy handlers from apps/experiments/cost-aware-ai-lab/.

Deployment

Deploy on Vercel

Local Development

cd apps/experiments/cost-aware-ai-lab
pnpm install
pnpm dev

Configuration

VariableRequiredPurpose
AI_GATEWAY_API_KEYYes (or OPENAI_API_KEY)Provider
AI_MODEL_A / AI_MODEL_BNoOverride models

Vercel / Next.js Features Used

  • AI SDK generateText
  • AI Gateway
  • Route Handlers

Next Steps

On this page