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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sum-ai

v1.0.1

Published

AI-powered sum function using LLM APIs

Readme

sum-ai

Easily sum two numbers using the power of AI. Just call sum(a, b) and let an LLM do the math for you.

Installation

bun install sum-ai

Quick Start

import { sum } from "sum-ai";

const result = await sum(2, 3);
console.log(result); // 5 (probably)

Configuration

sum-ai connects to any OpenAI-compatible API. Configure it via environment variables or pass options directly.

Environment Variables

| Variable | Description | Default | |---|---|---| | OPENAI_API_KEY | Your API key | (required) | | OPENAI_BASE_URL | API base URL | https://api.openai.com/v1 | | OPENAI_MODEL | Model to use | openai/gpt-4.1-nano |

Since Bun automatically loads .env files, just create one in your project root:

OPENAI_API_KEY=sk-your-api-key-here
OPENAI_BASE_URL=https://openrouter.ai/api/v1
OPENAI_MODEL=openai/gpt-4.1-nano

Programmatic Options

You can override any environment variable per-call:

import { sum } from "sum-ai";

const result = await sum(10, 20, {
  apiKey: "sk-my-key",
  baseUrl: "https://openrouter.ai/api/v1",
  model: "openai/gpt-4.1-nano",
});

Option precedence: function options > environment variables > defaults.

API Reference

sum(a, b, options?)

Sends two numbers to an LLM and asks it to add them.

Parameters:

| Parameter | Type | Required | Description | |---|---|---|---| | a | number | Yes | First number | | b | number | Yes | Second number | | options | SumOptions | No | Override default configuration |

Returns: Promise<number> — the sum of a and b, as computed by AI.

Throws:

| Error | Cause | |---|---| | "No API key provided..." | No OPENAI_API_KEY env var and no apiKey in options | | "API request failed: {status}" | The API returned a non-2xx HTTP status | | "No content in API response." | The API response was empty | | "API returned non-numeric response: ..." | The model responded with something that isn't a number |

SumOptions

interface SumOptions {
  apiKey?: string;   // Overrides OPENAI_API_KEY
  baseUrl?: string;  // Overrides OPENAI_BASE_URL
  model?: string;    // Overrides OPENAI_MODEL
}

Compatible Providers

sum-ai works with any OpenAI-compatible chat completions API:

| Provider | Base URL | |---|---| | OpenAI | https://api.openai.com/v1 (default) | | OpenRouter | https://openrouter.ai/api/v1 | | Together AI | https://api.together.xyz/v1 | | Groq | https://api.groq.com/openai/v1 | | Ollama (local) | http://localhost:11434/v1 |

How It Works

  1. Takes your two numbers
  2. Sends a chat completion request to the configured LLM with:
    • System prompt: "You are a calculator. Reply with only the numeric result, nothing else."
    • User prompt: "What is {a} + {b}?"
  3. Parses the response as a number
  4. Returns the result

Zero runtime dependencies — uses native fetch.

Development

# Install dependencies
bun install

# Run tests
bun test

# Type check
bun run typecheck

# Build for publishing
bun run build

License

MIT