Vercel
Deploy ADK-TS agents to Vercel as serverless functions
Vercel is a serverless platform optimized for frontend frameworks and API routes. Best for: API-based agents, webhook handlers, and request-response workflows with automatic scaling. Vercel offers zero-configuration deployment and automatic scaling, though it is limited by serverless function execution times. This guide shows you how to deploy your ADK-TS agent to Vercel.
What You'll Need
Before deploying to Railway, ensure you have:
- A Vercel Account to manage your deployments
- Your ADK-TS project ready for deployment
Deployment Options
Vercel offers two main deployment methods:
- GitHub Auto-Deploy (Recommended): Vercel automatically detects and builds your project from GitHub (Recommended)
- Vercel CLI (Manual Deployment): Deploy directly from your terminal for manual control and testing
Option 1: GitHub Auto-Deploy (Recommended)
Vercel automatically detects and builds your Node.js/TypeScript project without requiring manual configuration.
Step 1: Set up your API route
- Install Vercel's dependencies so the platform can build and serve your API route:
pnpm add -D vercel @vercel/nodeOr use npm install --save-dev if you prefer npm or yarn add --dev for yarn.
- Create an API route in the
apidirectory (e.g.,api/chat.ts): This tells Vercel how to handle incoming requests to your agent.
import { AgentBuilder } from "@iqai/adk";
import type { VercelRequest, VercelResponse } from "@vercel/node";
import { env } from "./env";
export default async function handler(req: VercelRequest, res: VercelResponse) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Method not allowed" });
}
try {
const { message } = req.body;
const { runner } = await AgentBuilder.create("assistant")
.withModel(env.LLM_MODEL)
.withInstruction("You are a helpful assistant")
.build();
const response = await runner.ask(message);
return res.status(200).json({ response });
} catch (error) {
console.error("Agent error:", error);
return res.status(500).json({ error: "Internal server error" });
}
}
export const config = {
maxDuration: 60,
};Step 2: Push to GitHub
Commit and push your code to GitHub:
git add .
git commit -m "Prepare for Vercel deployment"
git push origin mainStep 3: Connect to Vercel
- Log in to Vercel
- Click "Add New..." → "Project"
- Select "Import Git Repository" and choose your repository
- Authorize Vercel to access your Git provider (if first time)
- Choose the branch to deploy (usually
main) and click "Deploy"
Step 4: Configure Environment Variables
See Configuring Environment Variables below for detailed instructions.
Step 5: Automatic Deployment
Vercel handles everything automatically:
- First deployment: Clones your repo, installs dependencies, builds, and deploys
- Future updates: Every time you push to your connected branch, Vercel rebuilds and redeploys
- No manual steps needed after initial setup
Option 2: Vercel CLI (Manual Deployment)
Use the Vercel CLI for manual deployments or when you want to deploy without a Git integration.
Step 1: Install Vercel CLI
npm install -g vercelStep 2: Login
vercel loginStep 3: Deploy
From your project directory:
# Deploy to preview (staging)
vercel
# Deploy to production
vercel --prodStep 4: Configure Environment Variables
See Configuring Environment Variables below.
Configuring Environment Variables
All deployment options require environment variables to be configured in Vercel. This is a one-time setup for each project.
Add Environment Variables to Vercel
- In your Vercel project, go to "Settings" → "Environment Variables"
- Add each required environment variable based on your agent's needs.
Environment Variables Are Encrypted
Vercel automatically encrypts all environment variables. Never commit these values to your git repository.
Verifying Deployment
Check Deployment Status
In your Vercel project dashboard:
- Look for the "Deployments" tab - it should show "Ready" with a green indicator
- Click on the latest deployment to view detailed logs and the deployment URL
- Check the logs for your agent's startup messages
- Look for any error messages
Test Your Agent
Once deployment is active, test that it works:
- API agents: Make a test HTTP request to your endpoint (e.g.,
https://your-project.vercel.app/api/chat) - Check logs: Watch Vercel logs in real-time to see your agent responding
- Webhooks: Verify that your webhook handlers are receiving data
Monitoring and Updates
View Logs
Vercel provides real-time logs in the "Logs" tab of your deployment. Use them to:
- Debug issues by viewing error messages
- Monitor your agent's activity and responses
- Track performance and execution times
Updating Your Deployment
For GitHub deployments (Option 1):
- Make code changes locally
- Test changes locally using
vercel dev - Commit and push to your connected branch:
git add . git commit -m "Update agent features" git push origin main - Vercel automatically detects changes, rebuilds, and redeploys
For CLI deployments (Option 2):
- Make code changes locally
- Deploy again using the CLI:
vercel --prod - Vercel will create a new deployment automatically
Vercel Troubleshooting
- Function Timeouts: If your agent takes longer than the default 10-15s to respond, Vercel will terminate the function. Increase
maxDurationin your function config (up to 60s or more depending on your plan). - Cold Start Latency: The first request after some inactivity may be slower due to serverless cold starts. If low latency is critical, consider a platform with long-running instances like Railway.
- Deployment Conflicts: If multiple branches are deploying, check the "Deployments" tab to ensure you are testing the correct version.
Vercel Best Practices
- Local Development: Always use
vercel devto test your API routes locally. This simulates the Vercel environment more accurately than standard Node.js. - Edge Functions: For simple logic, consider using Edge Functions for faster startup times, though note they have more limited Node.js API support.