npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

financialdatasets-sdk-fork-aamm

v0.1.0

Published

SDK for accessing Financial Datasets API with LLM function calling support

Downloads

182

Readme

Financial Datasets SDK / LLM Tool

A TypeScript SDK providing easy access to the Financial Datasets API, with built-in integrations for LLMs via the Vercel AI SDK.

Example usage of tool

Features

  • Complete TypeScript definitions for all Financial Datasets API endpoints
  • Built-in integration with the Vercel AI SDK for LLM function calling
  • Comprehensive error handling and request validation
  • Clean, declarative API with proper parameter typing and documentation

Installation

# Using npm
npm install financialdatasets-sdk

# Using Yarn
yarn add financialdatasets-sdk

# Using Bun
bun add financialdatasets-sdk

Basic Usage

import { createFinancialDataTools } from "financialdatasets-sdk";

// Initialize the tools with your API key
const financialTools = createFinancialDataTools("your-api-key-here");

// Use the tools directly
async function getAppleIncomeStatements() {
  const result = await financialTools.getIncomeStatements.execute({
    ticker: "AAPL",
    period: "annual",
    limit: 3
  });

  console.log(result);
}

Using with LLMs (Vercel AI SDK)

The SDK is designed to work seamlessly with Large Language Models through the Vercel AI SDK's function calling capabilities.

With Next.js App Router

// app/api/chat/route.ts
import { StreamingTextResponse, ChatCompletionCreateParams } from "ai";
import { createFinancialDataTools } from "financialdatasets-sdk";
import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY
});

// Initialize financial tools
const financialTools = createFinancialDataTools(
  process.env.FINANCIAL_DATASETS_API_KEY!
);

// Define the tools we want to expose to the model
const tools: ChatCompletionCreateParams.Function[] = [
  financialTools.getIncomeStatements,
  financialTools.getBalanceSheets,
  financialTools.getPriceSnapshot,
  financialTools.getCompanyFacts
];

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

  const response = await openai.chat.completions.create({
    model: "gpt-4-turbo-preview",
    messages,
    tools,
    stream: true
  });

  return new StreamingTextResponse(response.body);
}

With Anthropic's Claude

// app/api/chat/route.ts
import { StreamingTextResponse } from "ai";
import { createFinancialDataTools } from "financialdatasets-sdk";
import Anthropic from "@anthropic-ai/sdk";

const anthropic = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY
});

// Initialize financial tools
const financialTools = createFinancialDataTools(
  process.env.FINANCIAL_DATASETS_API_KEY!
);

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

  const response = await anthropic.messages.create({
    model: "claude-3-opus-20240229",
    messages,
    tools: [
      financialTools.getIncomeStatements,
      financialTools.getBalanceSheets,
      financialTools.getPriceSnapshot,
      financialTools.getCompanyFacts
    ],
    stream: true
  });

  return new StreamingTextResponse(response);
}

Tool Reference

The SDK provides access to the following tools:

Financial Statements

| Tool | Description | | --------------------------- | ------------------------------------------------------- | | getIncomeStatements | Get income statements for a company ticker | | getBalanceSheets | Get balance sheets for a company ticker | | getCashFlowStatements | Get cash flow statements for a company ticker | | getAllFinancialStatements | Get all financial statements for a company ticker | | getSegmentedRevenues | Get detailed, segmented revenue data for a company | | searchFinancials | Search financial statements using filters | | searchLineItems | Search for specific financial metrics across statements |

Market Data

| Tool | Description | | ------------------ | --------------------------------------------- | | getPriceSnapshot | Get the real-time price snapshot for a ticker | | getPrices | Get historical price data for a ticker |

Company Information

| Tool | Description | | ------------------------ | ------------------------------------------------------------------- | | getCompanyFacts | Get company facts and details for a ticker | | getFilings | Get SEC filings for a company | | getInsiderTransactions | Get insider trades like purchases, sales, and holdings for a ticker |

Options

| Tool | Description | | ----------------- | ------------------------------------------------------------- | | getOptionsChain | Get real-time options chain data for actively traded equities |

Financial Metrics

| Tool | Description | | ----------------------------- | ------------------------------------------------------------------------- | | getFinancialMetricsSnapshot | Get a real-time snapshot of key financial metrics and ratios for a ticker |

Example LLM Prompts

When using the tools with LLMs, you can provide context about what the tools can do. Here are some example prompts:

For Analysis Using Multiple Tools

You have access to financial data tools for accessing market and company data.
Please analyze Apple (AAPL) using the available tools:
1. Get the company facts
2. Check the latest stock price
3. Analyze the annual income statements for the last 3 years
4. Identify key trends in revenue, profit margins, and growth

For Financial Comparisons

Please compare the financial performance of Tesla (TSLA) and Ford (F) over the last 2 years.
Use the financial tools to retrieve:
- Income statements (annual)
- Key financial metrics
- Current market valuation

Then provide an analysis of which company is performing better in terms of growth,
profitability, and financial health.

For Technical Data Analysis

I'm considering investing in Microsoft (MSFT). Can you:
1. Get the historical price data for the past 3 months (daily interval)
2. Analyze the price trend
3. Check the most recent income statement
4. Look at the financial metrics snapshot
5. Recommend whether this seems like a good investment based on fundamentals and recent price action

Advanced Configuration

Custom Base URL

If you need to use a different API endpoint:

const financialTools = createFinancialDataTools(
  "your-api-key-here",
  "https://custom-api-endpoint.com"
);

Error Handling

All tools include built-in error handling:

const result = await financialTools.getIncomeStatements.execute({
  ticker: "INVALID_TICKER",
  period: "annual"
});

if ("error" in result) {
  console.error(`Error: ${result.error} - ${result.message}`);
} else {
  // Process successful result
  console.log(result.income_statements);
}

Development

Building the SDK

# Install dependencies
bun install

# Build the SDK
bun run build

# Generate API client from OpenAPI spec
bun run generate

License

MIT