How to Integrate Next.js for fintech with Vercel AI SDK for multi-agent systems
Next.js for fintech gives you the frontend and server layer to ship regulated financial workflows. Vercel AI SDK gives you the agent orchestration layer to run multi-agent reasoning, tool calls, and streaming responses without wiring everything by hand.
Together, they let you build things like fraud review copilots, customer support agents with account context, and underwriting assistants that can query internal systems, summarize findings, and return a controlled response through a Next.js app.
Prerequisites
- •Node.js 18+ and Python 3.10+
- •A Next.js app already created
- •A Vercel project with AI SDK installed
- •Access to your fintech backend APIs or mock services
- •Environment variables configured:
- •
OPENAI_API_KEY - •
NEXT_PUBLIC_API_BASE_URL - •
VERCEL_AI_GATEWAY_API_KEYif you use Vercel’s gateway
- •
- •Python packages:
- •
requests - •
pydantic - •
fastapi - •
uvicorn
- •
Integration Steps
- •
Set up a Python agent service that will sit behind your Next.js app.
In production, I keep the agent runtime separate from the web app. Next.js handles UI, auth, and request routing; Python handles multi-agent orchestration because it is easier to compose tools, validators, and policy checks there.
from fastapi import FastAPI from pydantic import BaseModel import requests app = FastAPI() class AgentRequest(BaseModel): user_id: str query: str @app.post("/agent/run") def run_agent(payload: AgentRequest): return {"status": "ok", "user_id": payload.user_id, "query": payload.query} - •
Add a fintech data tool that your agents can call.
Your agent should not guess balances, transaction history, or policy status. It should fetch them from your fintech API through a small tool wrapper with strict inputs.
import os import requests FINTECH_API_BASE = os.getenv("NEXT_PUBLIC_API_BASE_URL") def get_account_summary(user_id: str) -> dict: resp = requests.get( f"{FINTECH_API_BASE}/accounts/{user_id}/summary", timeout=10, headers={"Accept": "application/json"}, ) resp.raise_for_status() return resp.json() - •
Wire the Vercel AI SDK model call into your Python orchestration layer.
The Vercel AI SDK is usually used in TypeScript via
streamText,generateText, oruseChat. In a multi-agent setup, your Python service can mirror that pattern by calling an AI endpoint exposed by your Next.js route or by using the same model contract your frontend expects.If your Next.js route uses
streamText, keep the response shape consistent so the Python service can consume it predictably.import requests def ask_model(prompt: str) -> str: resp = requests.post( "http://localhost:3000/api/chat", json={ "messages": [ {"role": "system", "content": "You are a fintech operations agent."}, {"role": "user", "content": prompt}, ] }, timeout=30, ) resp.raise_for_status() data = resp.json() return data["text"] - •
Build a simple multi-agent coordinator in Python.
One agent fetches account data. Another agent reviews risk signals. A coordinator merges both outputs and returns a decision-ready summary to Next.js.
from typing import Dict def risk_agent(account: Dict) -> Dict: balance = account.get("balance", 0) flagged = account.get("flags", []) risk_score = 80 if "chargeback" in flagged else (60 if balance < 100 else 20) return {"risk_score": risk_score, "reason": flagged or ["normal activity"]} def summary_agent(account: Dict, risk: Dict) -> str: prompt = ( f"Summarize this fintech case for an operations analyst:\n" f"Account: {account}\nRisk: {risk}\n" f"Keep it short and action-oriented." ) return ask_model(prompt) def coordinate(user_id: str) -> Dict: account = get_account_summary(user_id) risk = risk_agent(account) summary = summary_agent(account, risk) return { "account": account, "risk": risk, "summary": summary, } - •
Expose the coordinator through an API endpoint that Next.js can consume.
Your Next.js route can call this Python service from server actions or route handlers. That keeps sensitive logic off the client and makes audit logging easier.
from fastapi.responses import JSONResponse @app.post("/agent/decision") def decision(payload: AgentRequest): result = coordinate(payload.user_id) return JSONResponse(result)
Example local run:
uvicorn app:app --reload --port 8000
## Testing the Integration
Run the Python service, then hit the endpoint with a known test user. This verifies three things: your fintech API is reachable, the coordinator runs, and the model response is returned in the expected shape.
```python
import requests
resp = requests.post(
"http://localhost:8000/agent/decision",
json={"user_id": "cust_123", "query": "review this account"},
timeout=30,
)
print(resp.status_code)
print(resp.json())
Expected output:
200
{
'account': {'balance': 2450, 'flags': ['none']},
'risk': {'risk_score': 20, 'reason': ['normal activity']},
'summary': 'Customer account is healthy. No immediate action required.'
}
Real-World Use Cases
- •
Fraud review assistant
Pull transaction summaries from your fintech backend, score them with one agent, and have another agent generate an analyst note for review in Next.js. - •
Customer support copilot
Let support staff ask questions like “why was this payment declined?” while agents fetch policy data, payment status, and produce a controlled explanation. - •
Underwriting workflow helper
Combine KYC data, bank statements, and internal rules into a multi-agent flow that drafts underwriting recommendations for human approval.
Practical Notes
Keep all tool calls deterministic and auditable. For fintech systems, every agent action should map to a logged API call, a model prompt version, and a final decision record.
If you want this production-grade in Next.js for fintech with Vercel AI SDK for multi-agent systems, split responsibilities cleanly:
| Layer | Responsibility |
|---|---|
| Next.js | UI, auth, server actions, route handlers |
| Python agent service | orchestration, tools, validation |
| Fintech APIs | source of truth for financial data |
| Vercel AI SDK | streaming chat UX and model interaction |
That separation keeps your system maintainable when compliance teams ask where a number came from or why an agent made a recommendation.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit