Skip to main content
This guide walks you through using the Vercel AI SDK with Valyu’s financial search API to build an AI agent capable of analyzing real-time market data, financial reports, earnings transcripts, and economic indicators in under five minutes.

Why This Stack?

Vercel AI SDK

The fastest way to build AI apps. Stream-first design, framework-agnostic, batteries included.

Valyu Financial Search

Real-time access to SEC filings, earnings calls, financial statements, market data, and economic indicators.

Built for Speed

Production-ready in minutes. No complex data pipelines or expensive Bloomberg terminals.

Type-Safe

Full TypeScript support. Autocomplete everywhere. Zero runtime surprises.

What You’ll Build

An AI financial analyst that:
  • Searches real-time financial data and SEC filings
  • Analyzes regulatory filings and insider data
  • Monitor market conditions and regulatory changes
  • Provides actionable market relationships and statistical insights
  • Track multi-stock holdings and performance metrics with charts & data
  • Works across all public companies and markets

Get Started

1

Installation

Install Dependencies

npx create-next-app@latest finance-ai-agent --typescript --tailwind --app
cd finance-ai-agent
npm install ai @ai-sdk/openai @valyu/ai-sdk
Grab your API keys from:Add the keys to your .env.local:
VALYU_API_KEY=your_valyu_key_here
OPENAI_API_KEY=your_openai_key_here
2

Create API Route

Build the Search Endpoint

Create app/api/chat/route.ts:
import { openai } from '@ai-sdk/openai';
import { financeSearch } from '@valyu/ai-sdk';
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: openai('gpt-5'),
    messages,
    system: `You are an expert financial analyst with access to real-time market data and SEC filings.

    Guidelines:
    - Use financeSearch to find relevant financial data and reports
    - Cite sources with [Company/Report](URL) markdown links
    - Provide quantitative analysis with specific metrics
    - Include filing dates and reporting periods
    - Highlight material risks and opportunities
    - Compare metrics across quarters and competitors`,
    tools: {
      searchFinance: financeSearch(),
    },
  });

  return result.toDataStreamResponse();
}
That’s it! Your agent now has access to real-time financial search.
3

Build the UI

Create the Chat Interface

Replace app/page.tsx with:
'use client';

import { useChat } from 'ai/react';

export default function FinanceAgent() {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();

  return (
    <div className="flex flex-col h-screen max-w-4xl mx-auto p-4">
      <div className="flex-1 overflow-y-auto space-y-4 mb-4">
        {messages.map((message) => (
          <div
            key={message.id}
            className={`flex ${
              message.role === 'user' ? 'justify-end' : 'justify-start'
            }`}
          >
            <div
              className={`rounded-lg px-4 py-2 max-w-2xl ${
                message.role === 'user'
                  ? 'bg-blue-500 text-white'
                  : 'bg-gray-100 text-gray-900 prose prose-sm'
              }`}
            >
              <div
                dangerouslySetInnerHTML={{
                  __html: message.content.replace(
                    /\[([^\]]+)\]\(([^)]+)\)/g,
                    '<a href="$2" target="_blank" class="text-blue-600 underline">$1</a>'
                  ),
                }}
              />
            </div>
          </div>
        ))}
      </div>

      <form onSubmit={handleSubmit} className="flex gap-2">
        <input
          value={input}
          onChange={handleInputChange}
          placeholder="Ask about any company, market, or financial metric..."
          className="flex-1 px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
          disabled={isLoading}
        />
        <button
          type="submit"
          disabled={isLoading}
          className="px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:bg-gray-300"
        >
          {isLoading ? 'Analyzing...' : 'Analyze'}
        </button>
      </form>
    </div>
  );
}
You’re free to design the UI in whatever way works best for your use case.
4

Run Your Agent

Start Analyzing

npm run dev
Try the following queries when you run your agent:
  • “Analyze Tesla’s latest earnings and compare to previous quarter”
  • “What are the key risks mentioned in NVIDIA’s recent 10-K filing?”
  • “Compare revenue growth of Microsoft, Google, and Amazon over the past year”
  • “Summarize the main points from Apple’s latest earnings call”
Your agent searches real-time financial data and delivers actionable insights instantly.
Here are four production-ready agentic apps you can build using financial search:

1. Earnings Call Intelligence

Automate earnings analysis with AI-powered transcript analysis:
import { financeSearch } from '@valyu/ai-sdk';
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: openai('gpt-5'),
    messages,
    system: `You are an earnings call analyst. Your role:

    1. Extract key financial metrics and guidance changes
    2. Identify management sentiment and tone shifts
    3. Highlight unexpected developments or surprises
    4. Compare results to analyst expectations
    5. Flag potential red flags or accounting concerns
    6. Summarize Q&A insights and management responses

    Always provide: beat/miss analysis, forward guidance, margin trends, competitive positioning.`,
    tools: {
      financialSearch: financeSearch(),
    },
  });

  return result.toDataStreamResponse();
}
Example queries:
  • “Analyze sentiment changes in Microsoft’s earnings calls over the past year”
  • “What did NVIDIA management say about AI chip demand in their latest call?”
  • “Compare guidance revisions across major tech companies this quarter”

2. SEC Filing Analyzer

Monitor regulatory filings and extract material changes:
import { financeSearch } from '@valyu/ai-sdk';
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: openai('gpt-5'),
    messages,
    system: `You are an SEC filing specialist. Focus on:

    1. Identifying material changes in 10-K/10-Q filings
    2. Extracting risk factors and legal proceedings
    3. Tracking insider transactions and beneficial ownership
    4. Monitoring M&A activity via 8-K filings
    5. Analyzing proxy statements for governance changes
    6. Detecting accounting policy modifications

    Highlight: new risk disclosures, regulatory issues, litigation updates, executive changes.`,
    tools: {
      filings: financeSearch(),
    },
  });

  return result.toDataStreamResponse();
}
Example queries:
  • “What new risks did Tesla add to their latest 10-K?”
  • “Track insider selling patterns at Meta over the past 6 months”
  • “Has Amazon changed their accounting policies in recent filings?“

3. Competitive Market Intelligence

Build real-time competitive analysis dashboards:
import { financeSearch } from '@valyu/ai-sdk';
import { openai } from '@ai-sdk/openai';
import { streamText } from 'ai';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: openai('gpt-5'),
    messages,
    system: `You are a competitive intelligence analyst. Track:

    1. Revenue and margin trends across competitors
    2. Product launch announcements and partnerships
    3. Market share shifts and customer wins/losses
    4. R&D spending and innovation indicators
    5. Geographic expansion and new market entry
    6. Pricing strategy changes and promotional activity

    Provide: year-over-year comparisons, market positioning, competitive threats, growth opportunities.`,
    tools: {
      marketData: financeSearch(),
    },
  });

  return result.toDataStreamResponse();
}
Example queries:
  • “Compare cloud revenue growth rates: AWS vs Azure vs Google Cloud”
  • “Which EV manufacturers are gaining market share in China?”
  • “Track R&D spending trends in pharmaceutical companies”

4. Investment Research Assistant

Generate comprehensive investment memos and due diligence reports:
import { financeSearch } from '@valyu/ai-sdk';
import { openai } from '@ai-sdk/openai';
import { generateObject } from 'ai';

export async function POST(req: Request) {
  const { ticker } = await req.json();

  const { object } = await generateObject({
    model: openai('gpt-5'),
    prompt: `Generate a comprehensive investment analysis for ${ticker}`,
    tools: {
      search: financeSearch(),
    },
  });

  return Response.json(object);
}
Example queries:
  • “Generate investment thesis for emerging fintech companies”
  • “What are the key value drivers for SaaS companies in the current market?”
  • “Analyze downside risks for semiconductor stocks”
Each of these agents can be built in under 30 minutes and provides immediate value to investors, analysts, and financial professionals.

Real-World Application

Want to see Valyu’s financial search in action? Check out our production demo:

Valyu Finance AI

Experience a full-featured enterprise-grade financial research assistant powered by Valyu’s financial search. Query earnings data, analyze SEC filings, and get actionable market insights in real-time.

Next Steps