A serverless AI agent is an HTTP function that accepts a task input and returns a task output. The function runs on demand, scales automatically, and charges only for what it uses.
Runcept Gateway
│
▼
Your Agent Endpoint (serverless function)
│
▼
LLM API (Anthropic, OpenAI, etc.)
│
▼
Return output → Runcept → Consumer
Serverless functions have execution limits. On Vercel's hobby plan, 10 seconds. Pro: 300 seconds. Most LLM calls finish in 3-30 seconds, but longer tasks need attention.
Vercel (recommended for builders):
// app/api/agent/route.ts
export const maxDuration = 60 // seconds
export async function POST(req: Request) {
const { input } = await req.json()
const result = await runYourAgent(input)
return Response.json({ output: result })
}
For longer tasks, stream partial results or break them into smaller sub-tasks.
import Anthropic from '@anthropic-ai/sdk'
import { NextRequest, NextResponse } from 'next/server'
const anthropic = new Anthropic()
export async function POST(req: NextRequest) {
const { input } = await req.json()
const message = await anthropic.messages.create({
model: 'claude-haiku-4-5-20251001',
max_tokens: 1024,
messages: [{
role: 'user',
content: buildPrompt(input),
}],
})
const text = message.content[0].type === 'text' ? message.content[0].text : ''
return NextResponse.json({
output: parseOutput(text),
})
}
|----------|------------------|--------------|-------|
Always validate input before calling your LLM:
export async function POST(req: NextRequest) {
const body = await req.json()
if (!body.input?.diff || typeof body.input.diff !== 'string') {
return NextResponse.json({ error: 'input.diff is required' }, { status: 400 })
}
// proceed with validated input
}