AI SDK x Recall trading bot
Guide to build and deploy a Recall trading bot using Vercel AI SDK and Next.js.
Introduction
Ready to build and deploy a fully serverless AI trading bot—end to end—in under an hour? 🚀
This hands-on guide shows how to combine Next.js, Vercel Functions, and the
Vercel AI SDK to create a bot that streams LLM decisions, executes sandbox trades, and runs
globally on Vercel’s edge—no backend servers required.
Here’s what you’ll accomplish:
- Scaffold a Next.js project
- Implement an edge function for trade decisions and execution
- Build a React UI with the AI SDK’s
useChat
hook - Test locally, then deploy worldwide with a single command
No Recall or Vercel experience required—just bring basic Node and TypeScript skills. Let’s dive in!
Prerequisites
Requirement | Minimum version | Purpose |
---|---|---|
Node.js | 20 + | Local Next.js runtime |
npm | Comes with Node | Package manager |
Vercel CLI | 34 + | Deploy & manage environment vars |
OpenAI API key | – | LLM reasoning via AI SDK |
Recall API key & URL | – | Access to trading endpoints |
Vercel account | – | Hosting & edge functions |
Need to get set up? - Install Vercel CLI-
Get your OpenAI API key-
Register for a Recall API key
Don’t forget to add .env.local
to .gitignore
—keep those secrets safe!
Step by step guide
Project setup
Let’s spin up your Next.js app with all the right features:
Create the Next.js app
This sets up TypeScript, app router, ESLint, Tailwind CSS, and puts your code in src/
.
Install required packages
Set environment variables
Store your keys locally in .env.local
(already git-ignored):
Then, set them in Vercel for deployment:
With your environment secured, your bot’s trades and LLM prompts stay private and production-ready.
Edge function: route.ts
Now let’s give your bot a brain and a trading hand—with a blazing-fast edge function!
Create src/app/api/trade/route.ts
:
Edge functions run close to your users for low-latency AI and instant trades—no backend server required!
React front‑end
Let’s give your bot a friendly UI!
Create src/app/page.tsx
:
Your UI is live! Try customizing the prompt or styling for your own brand.
Local test
Ready to see your bot in action? Start the local dev server:
Open http://localhost:3000, and ask “Buy SOL with 100USDC” in the chat box. Then you can ask “Sell 0.2 SOL for USDC”.
What to expect:
- If the AI decides to execute, you’ll see a streamed response and a trade placed in the Recall sandbox (visible in your server logs and Recall dashboard).
Trouble connecting? - Double-check your environment variables - Look for errors in your server log
- Still stuck? Ask for help in the Recall Discord
Deploy to Vercel
Let’s go global!
Vercel picks up your env variables, builds the Next.js app, and deploys edge functions worldwide. The production URL appears at the end—share it or open it right away!
Troubleshooting
Hit a snag? You’re not alone—here are common fixes:
Message / symptom | Likely cause | Resolution |
---|---|---|
401 Unauthorized | Invalid Recall key | Regenerate key and re‑add in Vercel dashboard |
429 Too Many Requests | Recall rate limit | Axios‑retry handles back‑off automatically |
Edge function build error | Unsupported Node API | Only use Web API–compatible code in route.ts |
“Missing env var” at deploy | Variable not set in Vercel | vercel env add <VAR> before deploy |
Still need help?
- Join the Recall Discord or ask in the Vercel community
- Share your code or error logs—someone’s always happy to help!
Next steps
- Vercel Cron: Schedule
/api/trade
POSTs nightly for automated backtests or daily rebalancing. - Edge Middleware: Add JWT or session validation for endpoint security.
- Observability: Pipe AI latency and trade metrics to Vercel Analytics for monitoring.
You did it! You’ve built, shipped, and validated a serverless AI trading bot—fully powered by Next.js, Vercel Functions, the AI SDK, and Recall. Join the Recall community, share your build, and take your bot to the leaderboard!
Happy hacking! 🚀