Universal AI Layer for TypeScript

Stop juggling different AI API docs. Write once, switch providers seamlessly. Use OpenAI, Google Gemini, DeepSeek, Mistral, and Anthropic Claude with one unified interface.

5+
AI Providers
15KB
Gzipped Size
100%
Type Safe
5

Major AI Providers

15KB

Gzipped Bundle Size

0

Code Changes to Switch

v0.0.4

Latest Version

Framework Agnostic AI Toolkit

The open-source SDK designed to help developers build AI-powered applications with React, Next.js, Node.js, and more.

Single Interface

Write once, switch providers. Same code works across OpenAI, Google Gemini, DeepSeek, Mistral, and Anthropic Claude.

Type-Safe

Full TypeScript support with proper types for all providers and operations. Catch errors at compile time.

Lightning Fast

Only 15KB gzipped. Minimal dependencies—just dotenv for environment variables. Zero bloat.

Streaming Built-in

Real-time responses without custom parsing. Unified StreamOutput format across all providers.

Automatic Fallback

Provider fails? Automatically retry with others. Reliable production behavior by default.

LLM Council

Run same prompt across multiple models and have a judge synthesize the best answer for complex decisions.

Tool Calling

Let Gemini decide when to call your local TypeScript functions. The SDK runs them and feeds the result back for the final answer.

Built-in Tools

Ready-made definitions for reading, writing, appending, listing, and deleting files—plus streaming shell commands. Spread one into tool and go.

Guarded Shell Access

Shell commands spawn without a system shell and are checked against a deny list covering privilege escalation, destructive removal, and protected paths.

Supported Providers

Switch between major AI providers with one line of code. No code changes required.

OpenAI

GPT-4, GPT-4 Turbo, GPT-4o and more

Google Gemini

Gemini 2.5, Gemini Pro, and variants

DeepSeek

DeepSeek-Chat and models

Mistral

Mistral-Small, Medium, Large

Anthropic Claude

Claude 3, 3.5 Sonnet, Opus, Haiku

Just configure the API keys you need. You don't have to set up all providers.

Quick Start

Get up and running in 5 minutes. Just one import and you're ready.

Installation
$ npm install dev-ai-sdk
Environment Setup
# .env
OPENAI_API_KEY=sk-...
GOOGLE_API_KEY=AIza...
ANTHROPIC_API_KEY=sk-ant-...
5-Minute Example
import { genChat } from 'dev-ai-sdk';

// 1. Create a client with your API keys
const ai = new genChat({
  openai: {
    apiKey: process.env.OPENAI_API_KEY,
  },
});

// 2. Generate text
const result = await ai.generate({
  openai: {
    model: 'gpt-4o-mini',
    prompt: 'What is the capital of France?',
  },
});

// 3. Use the result
console.log(result.data); // "The capital of France is Paris."
console.log(result.provider); // "openai"
console.log(result.model); // "gpt-4o-mini"

What's Next?

  • →Try streaming responses for real-time data
  • →Enable automatic fallback for reliability
  • →Use LLM Council for better decisions
  • →Give the model tools with tool: [...writeFileTool]

Common Patterns

Explore powerful patterns you can implement today

Streaming Responses

Get real-time responses without custom parsing

const stream = await ai.generate({
  google: {
    model: 'gemini-2.5-flash',
    prompt: 'Write a haiku...',
    stream: true,
  },
});

for await (const chunk of stream) {
  console.log(chunk.text);
  if (chunk.done) {
    console.log(`Completed from ${chunk.provider}`);
  }
}

Automatic Fallback

Reliability by default with provider fallback

const ai = new genChat({
  openai: { apiKey: process.env.OPENAI_API_KEY },
  google: { apiKey: process.env.GOOGLE_API_KEY },
  fallback: true,
});

const result = await ai.generate({
  openai: {
    model: 'gpt-4o-mini',
    prompt: 'What is 2+2?',
  },
});

// Uses Google if OpenAI fails
console.log(result.provider);

LLM Council

Get answers from multiple models

const decision = await ai.councilGenerate({
  members: [
    { google: { model: 'gemini-2.5-flash-lite' } },
    { mistral: { model: 'mistral-small-latest' } },
  ],
  judge: { openai: { model: 'gpt-4o-mini' } },
  prompt: 'Top 3 languages for 2025?',
});

console.log(decision.finalAnswer);
console.log(decision.memberResponses);
console.log(decision.reasoning);

Tool Calling

Let the model run local functions on your machine

import {
  genChat,
  listFileTool,
  writeFileTool,
} from 'dev-ai-sdk';

const result = await ai.generate({
  google: {
    model: 'gemini-2.5-flash',
    prompt: 'List ./src and save a summary.',
    tool: [...listFileTool, ...writeFileTool],
  },
});

// Schemas go to the model.
// Your execute functions stay local.
console.log(result.data);

Shell Commands

Stream a local process, guarded by a deny list

import { genChat, streamShellCommandTool } from 'dev-ai-sdk';

const result = await ai.generate({
  google: {
    model: 'gemini-2.5-flash',
    prompt: 'List all files in /tmp.',
    tool: [...streamShellCommandTool],
  },
});

// Spawned with shell: false, so args are
// never re-interpreted by a system shell.
// Denied commands throw TOOL_ARGUMENT_ERROR.

Want to learn more?

View Full Documentation

Ready to get started?

Join developers building AI apps with unified provider support.