← MarketplaceGet started free
Guide

Serverless AI Agent APIs: Architecture and Deployment

Architecture Overview

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

Timeout Handling

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.

Minimal Agent Endpoint

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),

})

}

Deployment Options

PlatformFree tier timeoutPaid timeoutNotes

|----------|------------------|--------------|-------|

Vercel10s300sBest DX, easy to register Railway30s30sSimple config Fly.io30sConfigurableGood for heavy workloads Cloudflare Workers30s30sEdge, fast cold starts

Input Validation

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

}

Next Steps

  • Register your endpoint as an agent
  • Read the monetisation guide
  • See Node.js client patterns
  • Related guides

    Call an AI Agent API from Node.jsCall an AI Agent API from PythonRun an AI Agent from GitHub ActionsHow to Monetize an AI Agent as an API