> ## Documentation Index
> Fetch the complete documentation index at: https://docs.valyu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Build an Academic Research AI Agent

> Build an academic research AI agent with Vercel AI SDK and Valyu

This guide walks you through using the Vercel AI SDK with Valyu’s academic search intelligence to build an AI agent capable of searching millions of scholarly papers, journals, and textbooks in under five minutes.

## Why This Stack?

<CardGroup cols={2}>
  <Card title="Vercel AI SDK" icon="react">
    The fastest way to build AI apps. Stream-first design, framework-agnostic, batteries included.
  </Card>

  <Card title="Valyu Fulltext Paper Search" icon="brain">
    Real-time access to millions of papers across PubMed, arXiv, bioRxiv, medRxiv, and 100+ journals.
  </Card>

  <Card title="Built for Speed" icon="bolt">
    Production-ready in minutes. No complex RAG pipelines.
  </Card>

  <Card title="Type-Safe" icon="shield">
    Full TypeScript support. Autocomplete everywhere. Zero runtime surprises.
  </Card>
</CardGroup>

## What You'll Build

An AI research assistant that:

* Searches millions of academic papers and journals
* Streams intelligent responses with citations
* Provides source links to original publications
* Works across all scientific disciplines

## Get Started

<Steps>
  <Step title="Installation">
    ### Install Dependencies

    ```bash theme={null}
    npx create-next-app@latest paper-ai-agent --typescript --tailwind --app
    cd paper-ai-agent
    npm install ai @ai-sdk/openai @valyu/ai-sdk
    ```

    Grab your API keys from:

    * **Valyu**: [platform.valyu.ai](https://platform.valyu.ai) - ***\$10 free credits for new signups***
    * **OpenAI**: [platform.openai.com](https://platform.openai.com)

    Add the keys to your `.env.local`:

    ```bash theme={null}
    VALYU_API_KEY=your_valyu_key_here
    OPENAI_API_KEY=your_openai_key_here
    ```
  </Step>

  <Step title="Create API Route">
    ### Build the Search Endpoint

    Create `app/api/chat/route.ts`:

    ```typescript theme={null}
    import { openai } from '@ai-sdk/openai';
    import { paperSearch } 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 research assistant with access to millions of academic papers.

        Guidelines:
        - Use paperSearch to find relevant scholarly articles
        - Cite sources with [Title](URL) markdown links
        - Prioritize peer-reviewed research
        - Synthesize findings from multiple papers
        - Include publication dates when relevant`,
        tools: {
          searchPapers: paperSearch(), 
        },
      });

      return result.toDataStreamResponse();
    }
    ```

    **That's it!** Your agent now has access to real-time academic paper search.
  </Step>

  <Step title="Build the UI">
    ### Create the Chat Interface

    Replace `app/page.tsx` with:

    ```typescript theme={null}
    'use client';

    import { useChat } from 'ai/react';

    export default function ResearchAgent() {
      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 research topic..."
              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 ? 'Searching...' : 'Search'}
            </button>
          </form>
        </div>
      );
    }
    ```

    You’re free to design the UI in whatever way works best for your use case.
  </Step>

  <Step title="Run Your Agent">
    ### Start Searching

    ```bash theme={null}
    npm run dev
    ```

    Try the following search queries when you run your agent:

    * "Latest breakthroughs in CRISPR gene editing"
    * "Quantum computing applications in cryptography"
    * "Machine learning for protein folding prediction"
    * "Climate change impact on marine ecosystems"

    Your agent searches millions of papers and synthesizes results in real-time.
  </Step>
</Steps>

Here are four production-ready agentic apps you can build using academic paper search:

### 1. Literature Review Assistant

Automate systematic literature reviews for academic research:

```typescript theme={null}
import { paperSearch } 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 literature review specialist. Your role:

    1. Search comprehensively across multiple databases
    2. Identify seminal papers and recent advances
    3. Synthesize findings thematically
    4. Highlight research gaps and controversies
    5. Provide structured summaries with full citations

    Always organize findings by: key themes, methodologies, chronological trends.`,
    tools: {
      academicSearch: paperSearch(),
    },
  });

  return result.toDataStreamResponse();
}
```

**Example queries:**

* "Systematic review of transformer architectures in NLP 2020-2025"
* "Meta-analysis of climate change impacts on coral reef ecosystems"
* "Literature synthesis on quantum error correction techniques"

### 2. Grant Writing Research Agent

Accelerate grant proposals with comprehensive background research:

```typescript theme={null}
import { paperSearch, 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 grant writing research assistant. Focus on:

    1. Finding relevant preliminary studies and citations
    2. Identifying funding trends and successful grant patterns
    3. Highlighting societal/commercial impact potential
    4. Locating competing/complementary research
    5. Summarizing state-of-the-art methodologies

    Provide evidence-based rationales for research significance.`,
    tools: {
      papers: paperSearch(),
    },
  });

  return result.toDataStreamResponse();
}
```

**Example queries:**

* "Research gaps in renewable energy storage for NSF proposal"
* "Preliminary studies on CRISPR safety for NIH R01 application"
* "Commercial potential of quantum sensors for SBIR grant"

### 3. Competitive Academic Intelligence

Monitor research trends and competitive landscape:

```typescript theme={null}
import { paperSearch, patentSearch } 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 research intelligence analyst. Track:

    1. Emerging research trends and hot topics
    2. Leading research groups and their focus areas
    3. Patent filings in relevant domains
    4. Collaboration networks and funding patterns
    5. Technology transfer and commercialization activities

    Identify threats and opportunities for strategic positioning.`,
    tools: {
      papers: paperSearch()
    },
  });

  return result.toDataStreamResponse();
}
```

**Example queries:**

* "Who are the leading research groups in neuromorphic computing?"
* "Emerging trends in mRNA vaccine development 2024-2025"
* "Patent landscape for solid-state battery technologies"

### 4. AI Researcher

Identify emerging research opportunities in AI:

```typescript theme={null}
import { paperSearch } from '@valyu/ai-sdk';
import { openai } from '@ai-sdk/openai';
import { generateObject } from 'ai';
import { z } from 'zod';

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

  const { object } = await generateObject({
    model: openai('gpt-5'),
    prompt: `Analyze research trends and gaps for: ${query}`,
    tools: {
      search: paperSearch(),
    },
  });

  return Response.json(object);
}
```

**Example queries:**

* "Analyze AI safety research trends and identify critical gaps"
* "Find understudied areas in microbiome-cancer interactions"
* "Emerging opportunities at the intersection of neuroscience and AI"

Each of these agents can be built in under 30 minutes and provides immediate value to researchers, academics, and R\&D teams.

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Valyu AI SDK Playground" icon="book" href="https://ai-sdk.valyu.ai">
    Explore Valyu AI SDK features
  </Card>

  <Card title="Valyu API Reference" icon="code" href="/api-reference/endpoint/deepsearch">
    Full API documentation and parameters
  </Card>

  <Card title="Example Apps" icon="github" href="/example-apps">
    Open source example applications
  </Card>

  <Card title="Join Discord" icon="discord" href="https://discord.gg/umtmSsppRY">
    Get help from the Valyu community
  </Card>
</CardGroup>

***
