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

tinyai

v0.1.0

Published

The 5KB AI SDK. Zero dependencies. Just works.

Readme


npm install tinyai

Why TinyAI?

// Vercel AI SDK - 186KB, lots of setup
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
const { text } = await generateText({
  model: openai('gpt-4o-mini'),
  prompt: 'Summarize this text...',
});

// TinyAI - 5KB, one line
import { summarize } from 'tinyai';
const summary = await summarize(text);

Quick Start

import { tinyai } from 'tinyai';

// Configure once
const ai = tinyai({
  provider: 'openai',
  apiKey: process.env.OPENAI_API_KEY // or auto-detects from env
});

// Use anywhere
const summary = await ai.summarize(longArticle);
const sentiment = await ai.classify(review, ['positive', 'negative', 'neutral']);
const data = await ai.extract(email, { name: 'string', date: 'date', amount: 'number' });
const spanish = await ai.translate(text, 'spanish');
const answer = await ai.ask("What's the capital of France?");
const embedding = await ai.embed(text);

Free Options

TinyAI supports completely free AI providers:

Groq (Free Cloud)

Fast, free cloud AI with generous limits (14K tokens/min).

import { tinyai } from 'tinyai';

// Get free API key: https://console.groq.com/keys
const ai = tinyai({
  provider: 'groq',
  apiKey: process.env.GROQ_API_KEY
});

const summary = await ai.summarize(text); // Free!

Models: Llama 3.3 70B, Llama 3.1 8B, Mixtral, Gemma2

Ollama (Free Local)

Run AI 100% locally on your machine. No API key needed.

# 1. Install Ollama: https://ollama.ai
# 2. Pull a model
ollama pull llama3.2
import { tinyai } from 'tinyai';

// No API key needed!
const ai = tinyai({
  provider: 'ollama',
  model: 'llama3.2'  // or mistral, codellama, phi, gemma2
});

const summary = await ai.summarize(text); // 100% free, runs locally

Provider Comparison

| Provider | Cost | Speed | Privacy | Setup | |----------|------|-------|---------|-------| | Ollama | Free | Depends on hardware | 100% local | Install app | | Groq | Free tier | Very fast | Cloud | Get API key | | OpenAI | Paid | Fast | Cloud | Get API key |

Features

Type-Safe Extraction (like Zod, but for AI)

const invoice = await ai.extract(pdfText, {
  vendor: 'string',
  total: 'number',
  items: [{ name: 'string', price: 'number' }],
  dueDate: 'date',
});

// TypeScript knows the exact shape:
// { vendor: string, total: number, items: { name: string, price: number }[], dueDate: Date }

Zero-Config Defaults

// Just set OPENAI_API_KEY env var
import { summarize, classify, extract } from 'tinyai';

const summary = await summarize(text);  // Works instantly

Streaming

for await (const chunk of ai.stream.summarize(text)) {
  process.stdout.write(chunk);
}

Edge-Ready

Works everywhere: Node.js, Deno, Bun, Cloudflare Workers, Vercel Edge.

// Cloudflare Worker
export default {
  async fetch(req: Request) {
    const summary = await summarize(await req.text());
    return new Response(summary);
  }
};

API

tinyai(config?)

Creates a TinyAI instance.

const ai = tinyai({
  provider: 'openai',  // 'openai' | 'anthropic' | 'groq' | 'ollama'
  apiKey: '...',       // Optional, uses env vars by default
  model: 'gpt-4o',     // Optional, defaults to gpt-4o-mini
});

summarize(text, options?)

Summarizes text.

const summary = await ai.summarize(longText);
const brief = await ai.summarize(text, { maxLength: 50 });

classify(text, categories)

Classifies text into one of the provided categories.

const sentiment = await ai.classify(review, ['positive', 'negative', 'neutral']);
const category = await ai.classify(email, ['urgent', 'normal', 'spam']);

extract(text, schema)

Extracts structured data with full TypeScript inference.

const person = await ai.extract(bio, {
  name: 'string',
  age: 'number',
  skills: ['string'],
  contact: {
    email: 'string',
    phone: 'string',
  },
});

Supported types: 'string' | 'number' | 'boolean' | 'date'

translate(text, language)

Translates text to another language.

const spanish = await ai.translate('Hello, world!', 'spanish');

ask(question, options?)

Answers questions, optionally with context.

const answer = await ai.ask("What's 2+2?");
const specific = await ai.ask("What's the total?", { context: invoiceText });

embed(text)

Generates embedding vectors.

const embedding = await ai.embed("Hello, world!");
// Returns number[] with 1536 dimensions (OpenAI)

generate(prompt, options?)

Low-level text generation.

const poem = await ai.generate("Write a haiku about coding");
const story = await ai.generate("Once upon a time...", {
  system: "You are a creative storyteller"
});

Comparison

| Feature | TinyAI | Vercel AI SDK | LangChain | |---------|--------|---------------|-----------| | Bundle size | 5KB | 186KB | 500KB+ | | Dependencies | 0 | 12+ | 50+ | | TypeScript inference | Native | Partial | Plugin | | Setup time | 1 min | 10 min | 30 min | | Learning curve | None | Medium | Steep |

Standalone Functions

All primitives work standalone without creating an instance:

import { summarize, classify, extract } from 'tinyai';

// Just set OPENAI_API_KEY in your environment
const summary = await summarize(text);
const sentiment = await classify(text, ['positive', 'negative']);
const data = await extract(text, { name: 'string' });

Streaming Helpers

import { toReadableStream, collectStream } from 'tinyai';

// Convert to ReadableStream for HTTP responses
const stream = toReadableStream(ai.stream.summarize(text));
return new Response(stream);

// Collect stream to string
const full = await collectStream(ai.stream.summarize(text));

Roadmap

  • [x] Core client with OpenAI provider
  • [x] summarize() - text summarization
  • [x] classify() - text classification
  • [x] extract() - structured data extraction
  • [x] translate() - translation
  • [x] ask() - Q&A
  • [x] embed() - embeddings
  • [x] TypeScript inference
  • [x] Streaming support
  • [x] Provider: Groq (free cloud)
  • [x] Provider: Ollama (free local)
  • [ ] Provider: Anthropic
  • [ ] pipe() - composable pipelines
  • [ ] CLI tool

License

MIT