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
generateTextruns. - Latency + tokens – from AI SDK usage when available.
- Labeled estimates – public-rate heuristics, not invoices.
- Honest
503when 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": "..."
}| Status | Cause |
|---|---|
503 | No AI provider |
400 | Empty 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
Local Development
cd apps/experiments/cost-aware-ai-lab
pnpm install
pnpm devConfiguration
| Variable | Required | Purpose |
|---|---|---|
AI_GATEWAY_API_KEY | Yes (or OPENAI_API_KEY) | Provider |
AI_MODEL_A / AI_MODEL_B | No | Override models |
Vercel / Next.js Features Used
- AI SDK
generateText - AI Gateway
- Route Handlers