Deploy cascadeflow as a globally distributed edge function on Vercel for low-latency AI inference with 40-85% cost savings.
- ⚡ Global edge network (runs closest to users)
- 🔒 Secure (API keys never exposed to browser)
- 💰 Cost tracking (visualize savings in real-time)
- 🎨 Beautiful UI (responsive, modern design)
- 📦 Zero config (deploy in 60 seconds)
pnpm install# Add your OpenAI API key
vercel env add OPENAI_API_KEYOr create .env.local:
OPENAI_API_KEY=sk-...vercel devOpen http://localhost:3000 in your browser.
vercel deploy --prodvercel-edge/
├── api/
│ └── chat.ts Edge function (handles AI requests)
├── public/
│ └── index.html Frontend UI
├── package.json
├── vercel.json Vercel configuration
└── README.md
The edge function runs on Vercel's global network:
import { CascadeAgent } from '@cascadeflow/core';
export default async function handler(req: Request) {
// Recommended: Claude Haiku + GPT-5
const agent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008, apiKey: process.env.ANTHROPIC_API_KEY },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125, apiKey: process.env.OPENAI_API_KEY }
]
});
const { query } = await req.json();
const result = await agent.run(query);
return Response.json(result);
}Simple fetch call to the edge function:
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: 'What is TypeScript?' })
});
const result = await response.json();
console.log(`Saved ${result.savingsPercentage}%`);Edit api/chat.ts:
const agent = new CascadeAgent({
models: [
{ name: 'claude-3-5-haiku-20241022', provider: 'anthropic', cost: 0.0008 },
{ name: 'gpt-5', provider: 'openai', cost: 0.00125 },
{ name: 'o1-mini', provider: 'openai', cost: 0.003 }, // Add reasoning model
]
});const agent = new CascadeAgent({
models: [...],
quality: {
threshold: 0.8, // Higher = more selective (fewer drafts accepted)
requireValidation: true
}
});const result = await agent.run(query, {
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get current weather',
parameters: {
type: 'object',
properties: {
location: { type: 'string' }
}
}
}
}
]
});| Scenario | Traditional Cost | cascadeflow Cost | Savings |
|---|---|---|---|
| Simple query (200 tokens) | $0.00025 (GPT-5) | $0.00016 (Claude Haiku) | 36% |
| Complex query (500 tokens) | $0.000625 (GPT-5) | $0.000625 (escalated) | 0% (correct escalation) |
| Mixed (70% simple) | $0.0005 | $0.000299 | 40% |
1000 queries/day:
- Traditional (GPT-5): $0.50/day = $15.00/month
- cascadeflow (Claude Haiku + GPT-5): $0.30/day = $9.00/month
- Savings: $6.00/month (40%)
vercel logsCheck Vercel dashboard for:
- Function execution time
- Error rates
- Bandwidth usage
- Set
OPENAI_API_KEYin Vercel dashboard - Update CORS settings in
api/chat.ts - Add rate limiting (use Vercel Edge Config)
- Monitor costs in OpenAI dashboard
- Set up error tracking (Sentry, etc.)
vercel env add OPENAI_API_KEY
vercel env pull # Pull to local .env.localIncrease timeout in vercel.json:
{
"functions": {
"api/**/*.ts": {
"maxDuration": 30
}
}
}Update api/chat.ts:
headers: {
'Access-Control-Allow-Origin': 'https://yourdomain.com',
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Headers': 'Content-Type'
}MIT