How to Integrate Next.js for wealth management with Vercel AI SDK for AI agents
Combining Next.js for wealth management with Vercel AI SDK gives you a clean path from portfolio data to agentic workflows. The practical win is simple: your advisor app can expose client context, holdings, and risk signals through Next.js, then let a Vercel AI-powered agent reason over that data and return compliant, actionable responses.
This setup is useful when you want an assistant that can answer questions like “What changed in this client’s exposure this week?” or “Draft a rebalancing recommendation for this household.” The trick is to keep the integration deterministic at the API layer and let the agent handle interpretation, summarization, and next-step suggestions.
Prerequisites
- •Python 3.10+
- •A running Next.js for wealth management backend with API routes enabled
- •A Vercel AI SDK endpoint exposed for agent requests
- •API keys or bearer tokens for both systems
- •
requestsinstalled in your Python environment - •Access to a test client account or sandbox portfolio
- •Basic familiarity with JSON payloads and REST calls
Install the Python dependency:
pip install requests
Integration Steps
- •
Expose wealth management data from Next.js
Your Next.js app should provide structured endpoints for portfolio state, client profile, and activity history. In most implementations, that means route handlers under
/api/...returning JSON that the agent can consume.import requests NEXTJS_BASE_URL = "https://wealth.example.com" CLIENT_ID = "client_123" TOKEN = "your-nextjs-api-token" def fetch_client_portfolio(client_id: str): url = f"{NEXTJS_BASE_URL}/api/clients/{client_id}/portfolio" headers = {"Authorization": f"Bearer {TOKEN}"} response = requests.get(url, headers=headers, timeout=30) response.raise_for_status() return response.json() portfolio = fetch_client_portfolio(CLIENT_ID) print(portfolio) - •
Call the Vercel AI SDK agent endpoint with portfolio context
The Vercel AI SDK typically sits behind an agent endpoint that accepts messages plus structured context. Send only the data the model needs, not raw internal objects.
import requests VERCEL_AGENT_URL = "https://agent.example.vercel.app/api/chat" VERCEL_TOKEN = "your-vercel-agent-token" def ask_agent(question: str, portfolio: dict): payload = { "messages": [ { "role": "system", "content": ( "You are a wealth management assistant. " "Use the provided portfolio context and return concise recommendations." ), }, { "role": "user", "content": question, }, ], "context": { "clientId": portfolio["clientId"], "holdings": portfolio["holdings"], "riskProfile": portfolio["riskProfile"], "cashBalance": portfolio["cashBalance"], }, } headers = { "Authorization": f"Bearer {VERCEL_TOKEN}", "Content-Type": "application/json", } response = requests.post(VERCEL_AGENT_URL, json=payload, headers=headers, timeout=60) response.raise_for_status() return response.json() result = ask_agent("Should this client rebalance equity exposure?", portfolio) print(result) - •
Add a server-side orchestration layer
Don’t let the browser talk directly to both systems. Put a small Python orchestration service in front of them so you can enforce auth, logging, redaction, and policy checks before anything reaches the model.
from typing import Any import requests class WealthAgentOrchestrator: def __init__(self, nextjs_base_url: str, nextjs_token: str, vercel_agent_url: str, vercel_token: str): self.nextjs_base_url = nextjs_base_url self.nextjs_token = nextjs_token self.vercel_agent_url = vercel_agent_url self.vercel_token = vercel_token def get_portfolio(self, client_id: str) -> dict[str, Any]: url = f"{self.nextjs_base_url}/api/clients/{client_id}/portfolio" r = requests.get(url, headers={"Authorization": f"Bearer {self.nextjs_token}"}, timeout=30) r.raise_for_status() return r.json() def run_agent(self, prompt: str, context: dict[str, Any]) -> dict[str, Any]: payload = {"messages": [{"role": "user", "content": prompt}], "context": context} headers = {"Authorization": f"Bearer {self.vercel_token}", "Content-Type": "application/json"} r = requests.post(self.vercel_agent_url, json=payload, headers=headers, timeout=60) r.raise_for_status() return r.json() def answer_client_question(self, client_id: str, prompt: str) -> dict[str, Any]: portfolio = self.get_portfolio(client_id) context = { "clientId": portfolio["clientId"], "holdings": portfolio["holdings"], "riskProfile": portfolio["riskProfile"], "constraints": portfolio.get("constraints", []), } return self.run_agent(prompt, context) orchestrator = WealthAgentOrchestrator( nextjs_base_url="https://wealth.example.com", nextjs_token="your-nextjs-api-token", vercel_agent_url="https://agent.example.vercel.app/api/chat", vercel_token="your-vercel-agent-token", ) print(orchestrator.answer_client_question("client_123", "Summarize current concentration risk.")) - •
Map agent output back into your wealth management workflow
The output should not just be text. In production you want structured fields your app can render in a dashboard or use for approval flows.
import json def normalize_agent_response(agent_response: dict) -> dict: content = agent_response.get("message", {}).get("content", "{}") try: parsed = json.loads(content) except json.JSONDecodeError: parsed = {"summary": content} return { "summary": parsed.get("summary", ""), "recommendations": parsed.get("recommendations", []), "risk_notes": parsed.get("risk_notes", []), "requires_human_review": parsed.get("requires_human_review", True), } normalized = normalize_agent_response(result) print(normalized) - •
Store audit events in your Next.js app
Every agent interaction should be traceable. Push the final decision record back into Next.js so advisors can review what was asked and what was returned.
import requests # keep this on the server side only # example audit write-back to Next.js
def write_audit_event(client_id: str, prompt: str, response: dict): url = f"{NEXTJS_BASE_URL}/api/audit/agent-events" payload = { "clientId": client_id, "prompt": prompt, "responseSummary": response.get("summary"), "requiresHumanReview": response.get("requires_human_review", True), } headers = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"} r = requests.post(url, json=payload, headers=headers, timeout=30) r.raise_for_status() return r.json()
## Testing the Integration
Use a known sandbox client and verify that data flows from Next.js into the agent endpoint and back into your app.
```python
def test_integration():
orchestrator = WealthAgentOrchestrator(
nextjs_base_url="https://wealth.example.com",
nextjs_token="your-nextjs-api-token",
vercel_agent_url="https://agent.example.vercel.app/api/chat",
vercel_token="your-vercel-agent-token",
)
response = orchestrator.answer_client_question(
client_id="client_123",
prompt="Provide a one-paragraph risk summary and flag any concentration issues."
)
normalized = normalize_agent_response(response)
print(normalized)
test_integration()
Expected output:
{
"summary": "...",
"recommendations": ["..."],
"risk_notes": ["..."],
"requires_human_review": true
}
If that returns cleanly and your audit event lands in Next.js storage/logs, the integration is working.
Real-World Use Cases
- •Advisor copilot: Pull holdings from Next.js and have the Vercel AI SDK generate concise talking points before client calls.
- •Portfolio monitoring: Trigger an agent when allocation drifts beyond thresholds and have it draft review notes for compliance.
- •Client servicing workflows: Let relationship managers ask natural-language questions about accounts while keeping all sensitive data behind server-side APIs.
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