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

# AI Provider

> Use VecTrade as a tool provider with the Vercel AI SDK

## Overview

The `@vectrade/ai-provider` package integrates VecTrade financial data as tools in the [Vercel AI SDK](https://sdk.vercel.ai/). This lets any LLM access real-time market data, fundamentals, and AI analysis through function calling.

## Installation

```bash theme={null}
npm install @vectrade/ai-provider ai
```

## Quick Start

```typescript theme={null}
import { createVecTrade } from "@vectrade/ai-provider";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

const vt = createVecTrade(); // reads VECTRADE_API_KEY env var

const result = await generateText({
  model: openai("gpt-4o"),
  tools: vt.tools(),
  prompt: "What's AAPL trading at and what do analysts think?",
});

console.log(result.text);
```

## Available Tools

The provider exposes 16 VecTrade API endpoints as AI-callable tools:

| Tool                     | Description                                 |
| ------------------------ | ------------------------------------------- |
| `getQuote`               | Get real-time quote for a symbol            |
| `getBatchQuotes`         | Get quotes for multiple symbols             |
| `getFundamentals`        | Company fundamentals and ratios             |
| `getFinancialStatements` | Income, balance sheet, cash flow statements |
| `getCompanyProfile`      | Company info, sector, industry, exchange    |
| `getTechnicals`          | Technical indicators and scoring            |
| `getNews`                | Latest market news for a symbol             |
| `getSentiment`           | Social & news sentiment scoring             |
| `getAnalystRatings`      | Analyst consensus ratings                   |
| `getAnalystTargets`      | Analyst price targets (high/low/mean)       |
| `getUpgradesDowngrades`  | Recent analyst rating changes               |
| `getEarnings`            | Historical earnings data                    |
| `getInsiderTransactions` | Insider trading activity                    |
| `getOptionsChain`        | Options chain with Greeks                   |
| `getHistoricalPrices`    | OHLCV price history                         |
| `getETF`                 | ETF profile, NAV, and holdings              |

## Configuration

```typescript theme={null}
const vt = createVecTrade({
  apiKey: "vq_live_...",        // or VECTRADE_API_KEY env var
  baseURL: "https://api.vectrade.io/v1",
});

// Use specific tools only
const tools = vt.tools(["getQuote", "getAnalystConsensus"]);
```

## Framework Examples

### Next.js Route Handler

```typescript theme={null}
import { createVecTrade } from "@vectrade/ai-provider";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";

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

  const result = streamText({
    model: openai("gpt-4o"),
    tools: vt.tools(),
    messages,
  });

  return result.toDataStreamResponse();
}
```

### With Claude

```typescript theme={null}
import { createVecTrade } from "@vectrade/ai-provider";
import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

const vt = createVecTrade();

const result = await generateText({
  model: anthropic("claude-sonnet-4-20250514"),
  tools: vt.tools(),
  maxSteps: 5,
  prompt: "Compare NVDA and AMD earnings growth over the last 4 quarters",
});
```

## Requirements

* Node.js 18+
* `ai` package (Vercel AI SDK) v3+
* VecTrade API key

## Resources

* [GitHub](https://github.com/VecTrade-io/vectrade-ai-provider)
* [npm](https://www.npmjs.com/package/@vectrade/ai-provider)
* [Vercel AI SDK Docs](https://sdk.vercel.ai/)
* [Examples](https://github.com/VecTrade-io/vectrade-examples/tree/main/typescript/ai-provider)
