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

@motleywildside/ai-sdk

v1.0.7

Published

TypeScript SDK for building AI apps with OpenAI, Gemini, OpenRouter, structured outputs, prompt management, caching and pipelines.

Readme

@motleywildside/ai-sdk

A TypeScript SDK for building AI apps with multiple LLM providers, structured outputs, prompt management, caching, and pipelines.


✨ Features

  • Unified API: One interface for OpenAI, Gemini, and OpenRouter (Anthropic, Meta Llama, Mistral, DeepSeek, Cohere, Qwen, and more via OpenRouter).
  • Smart Caching: Built-in read_through and refresh modes to save costs and latency.
  • Type-Safe Schema: Native Zod integration for schema-validated structured outputs. Parse failures and schema mismatches raise typed errors (LLMParseError / LLMSchemaError) for explicit handling.
  • Prompt Registry: Decouple prompts from code with versioning and variables.
  • Pipeline Orchestrator: Build complex, stateful AI workflows with ease.

🚀 Quick Start

1. Install

npm install @motleywildside/ai-sdk

2. Initialize

import { LMService, OpenAIProvider } from "@motleywildside/ai-sdk";

const llm = new LMService({
  providers: [new OpenAIProvider(process.env.OPENAI_API_KEY)],
  enableCache: true,
});

3. Register Prompts

Decouple your prompts from code using the built-in registry. Supports variables, versioning, and model defaults.

llm.promptRegistry.register({
  promptId: "hello_world",
  version: 1,
  systemPrompt: "You are a helpful assistant.",
  userPrompt: "Hello, {name}! How are you today?",
  output: { type: "text" },
  modelDefaults: {
    model: "gpt-4o",
    temperature: 0.7,
  },
});

llm.promptRegistry.register({
  promptId: "get_city_info",
  version: 1,
  systemPrompt: "You are a travel expert.",
  userPrompt: "Provide details about {city}.",
  output: { type: "json" }, // Enforces JSON mode
  modelDefaults: { model: "gemini-1.5-flash" },
});

4. Basic Call

const result = await llm.callText({
  promptId: "hello_world",
  variables: { name: "User" },
});

console.log(result.text);

5. Structured JSON (with Zod)

const result = await llm.callJSON({
  promptId: "get_city_info",
  variables: { city: "Paris" },
  jsonSchema: z.object({
    population: z.number(),
    landmark: z.string(),
  }),
});

console.log(result.data.landmark); // Fully typed

⛓️ Pipelines

Build complex multi-step workflows with the PipelineOrchestrator:

import { PipelineOrchestrator, ok } from "@motleywildside/ai-sdk";

const pipe = new PipelineOrchestrator({
  steps: [
    {
      name: "classify",
      run: async (ctx) => ok({ ctx: { ...ctx, category: "support" } }),
    },
    {
      name: "respond",
      run: async (ctx) => ok({ ctx: { ...ctx, reply: "How can I help?" } }),
    },
  ],
});

const { status, ctx } = await pipe.run({ input: "..." });

🛠️ Configuration

Full control over retries, logging, and custom providers:

const llm = new LMService({
  providers: [...],
  maxRetries: 3,
  logger: new MyCustomLogger(),
  cacheProvider: new RedisCacheProvider() // Easy to extend
});

💾 Caching

Optimize your costs and performance with flexible caching modes:

  • read_through: (Default) Checks cache first, calls LLM on miss, then stores the result.
  • bypass: Completely ignores the cache for both reading and writing.
  • refresh: Forces a fresh LLM call and updates the cache with the new value.
const result = await llm.callText({
  promptId: "expensive_query",
  cache: { mode: "read_through", ttlSeconds: 3600 },
});

Learn by example

The examples/ directory contains copy-paste-ready examples for every realistic integration shape — from a first call through custom providers, production pipelines, and framework integrations.

Curated starting points:

Browse the full index: examples/README.md


📄 License

MIT © MotleyWildside