How to Integrate Next.js for investment banking with Vercel AI SDK for production AI
Why this integration matters
If you’re building AI for investment banking, the hard part is not the chat UI. It’s getting a secure Next.js front end to talk to an AI layer that can handle market context, document workflows, and controlled tool use without turning into a demo-grade mess.
Pairing Next.js for investment banking with Vercel AI SDK gives you a clean pattern: Next.js handles the client and server boundaries, while the AI SDK handles streaming, tool calls, and structured responses. That combination is what you want for analyst copilots, deal-room assistants, and internal research workflows.
Prerequisites
- •Node.js 18+ and Python 3.10+
- •A Next.js app already created with
create-next-app - •Vercel AI SDK installed in your Next.js project:
- •
npm install ai @ai-sdk/openai
- •
- •Python dependencies for your backend bridge:
- •
pip install fastapi uvicorn httpx pydantic
- •
- •An OpenAI API key or compatible model provider key
- •A backend service endpoint that your Next.js app can call
- •Basic auth in place if this will touch sensitive banking data
Integration Steps
- •
Create a Python AI bridge service
In production, I keep the model orchestration outside the UI layer. Your Python service can handle prompt assembly, policy checks, logging, and downstream calls before returning a response to Next.js.
from fastapi import FastAPI from pydantic import BaseModel import httpx import os app = FastAPI() class ChatRequest(BaseModel): messages: list[dict] @app.post("/api/ai/chat") async def chat(req: ChatRequest): api_key = os.environ["OPENAI_API_KEY"] payload = { "model": "gpt-4.1-mini", "messages": req.messages, } headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", } async with httpx.AsyncClient() as client: resp = await client.post( "https://api.openai.com/v1/chat/completions", json=payload, headers=headers, timeout=60, ) return resp.json() - •
Wire Next.js API routes to the Python service using the Vercel AI SDK
On the Next.js side, use the AI SDK route handler pattern. The SDK’s
streamTextfunction is the standard entry point for streaming model output from a server route.# This file demonstrates the backend contract your Next.js route will consume. # In practice, your Next.js route calls this Python endpoint over HTTP. from pydantic import BaseModel class Message(BaseModel): role: str content: str class RoutePayload(BaseModel): messages: list[Message] def normalize_messages(payload: RoutePayload) -> list[dict]: return [{"role": m.role, "content": m.content} for m in payload.messages]Then in your Next.js route handler:
# Example of the request shape your Python bridge should accept. request_body = { "messages": [ {"role": "system", "content": "You are an investment banking assistant."}, {"role": "user", "content": "Summarize this earnings call transcript."} ] } - •
Add structured tool execution for banking workflows
Banking assistants need controlled tools. Use the Vercel AI SDK’s tool calling pattern on the Next.js side, then forward validated actions to Python services that touch internal systems.
from pydantic import BaseModel from typing import Literal class DealLookupRequest(BaseModel): ticker: str action: Literal["lookup_company", "fetch_deal_notes"] def validate_tool_input(data: dict) -> DealLookupRequest: return DealLookupRequest(**data) def build_tool_result(company_name: str, sector: str) -> dict: return { "company_name": company_name, "sector": sector, "source": "internal-deal-db" } - •
Return streamed responses to the browser
For production UX, stream tokens instead of waiting for a full completion. The Vercel AI SDK supports this pattern well through
streamText, which keeps analyst-facing interfaces responsive.import httpx import asyncio async def fetch_ai_response(messages: list[dict]) -> dict: async with httpx.AsyncClient() as client: response = await client.post( "http://localhost:8000/api/ai/chat", json={"messages": messages}, timeout=60, ) response.raise_for_status() return response.json() async def main(): messages = [ {"role": "system", "content": "You are an investment banking copilot."}, {"role": "user", "content": "Draft a one-paragraph IC memo summary."} ] result = await fetch_ai_response(messages) print(result) asyncio.run(main()) - •
Add auth and audit logging before production rollout
Don’t ship an agent that can query sensitive deal data without traceability. Put request IDs, user IDs, and tool-call logs in place before enabling real users.
from datetime import datetime import uuid def audit_event(user_id: str, action: str, payload: dict) -> dict: return { "event_id": str(uuid.uuid4()), "user_id": user_id, "action": action, "timestamp": datetime.utcnow().isoformat(), "payload": payload, }
Testing the Integration
Use a simple end-to-end check from your local shell or test runner. The goal is to confirm that Next.js can reach the Python bridge and that the model returns a valid response shape.
import asyncio
import httpx
async def test_chat():
async with httpx.AsyncClient() as client:
resp = await client.post(
"http://localhost:8000/api/ai/chat",
json={
"messages": [
{"role": "system", "content": "You are an investment banking assistant."},
{"role": "user", "content": "Give me a two-bullet summary of IPO readiness risks."}
]
},
)
resp.raise_for_status()
data = resp.json()
print(data["choices"][0]["message"]["content"])
asyncio.run(test_chat())
Expected output:
- Financial reporting controls need tightening before diligence starts.
- Management should close open legal and cap table issues before launch.
Real-World Use Cases
- •
Deal room assistant
- •Summarizes CIMs, earnings calls, and diligence notes.
- •Answers banker questions with citations from approved sources.
- •
Investment committee memo generator
- •Turns raw research into structured IC drafts.
- •Uses tool calls to pull financials and comparable transactions.
- •
Internal analyst copilot
- •Helps analysts draft emails, teasers, and management presentation outlines.
- •Keeps human approval in the loop before anything leaves the firm.
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