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

autorouter-sdk

v1.0.4

Published

Auto-select the best AI model based on your query

Readme

AutoRouter SDK

Auto-select the best AI model based on your query. This SDK automatically finds the most suitable models from Hugging Face based on semantic similarity to your task description.

Installation

npm install autorouter-sdk

Setup

AutoRouter requires OpenAI and Pinecone credentials. You'll need:

  • OpenAI API key for generating embeddings
  • Pinecone API key for vector database storage

Set them as environment variables:

export OPENAI_API_KEY='your-openai-key'
export PINECONE_API_KEY='your-pinecone-key'

Or use a .env file:

OPENAI_API_KEY=your-openai-key
PINECONE_API_KEY=your-pinecone-key
PINECONE_INDEX_NAME=autorouter-models

Initial Setup - Index Models

Before using the SDK, you need to index models into your Pinecone database. Run:

npx autorouter-sdk index-models

Or using the CLI directly:

autorouter-sdk index-models \
  --openai-key your-openai-key \
  --pinecone-key your-pinecone-key \
  --index-name autorouter-models

This will:

  1. Load the bundled model registry (12,000+ models)
  2. Generate embeddings for each model
  3. Index them into your Pinecone database

The process takes about 10-15 minutes. You only need to run this once.

Usage

Basic Usage

import { AutoRouter } from 'autorouter-sdk';

const router = new AutoRouter({
  openaiKey: 'your-openai-key',
  pineconeKey: 'your-pinecone-key',
  pineconeIndexName: 'autorouter-models' // optional, defaults to 'autorouter-models'
});

const models = await router.selectModel('build a chatbot');

console.log(models);
// [
//   {
//     id: 'meta-llama/Llama-2-7b-chat-hf',
//     name: 'Llama-2-7b-chat-hf',
//     description: 'A conversational AI model...',
//     task: 'text-generation',
//     provider: 'huggingface',
//     license: 'apache-2.0',
//     downloads: 5000000,
//     score: 0.95,
//     endpoint: 'https://api-inference.huggingface.co/models/...'
//   },
//   ...
// ]

Advanced Usage

// With options
const models = await router.selectModel('summarize text', {
  limit: 10,
  filter: { license: 'apache-2.0' }
});

// Get top 5 models
const topModels = await router.selectModel('generate images', { limit: 5 });

API Reference

AutoRouter

Constructor

new AutoRouter(config: AutoRouterConfig)
  • config.openaiKey (string): Your OpenAI API key
  • config.pineconeKey (string): Your Pinecone API key
  • config.pineconeIndexName (string, optional): Pinecone index name (defaults to 'autorouter-models')

Methods

selectModel(query, options?)

Returns an array of model recommendations sorted by relevance.

  • query (string): Description of your task (e.g., "build a chatbot", "generate images")
  • options (object, optional):
    • limit (number): Maximum number of results (default: 10)
    • filter (object): Filter options
      • license (string): Filter by license type (e.g., "apache-2.0", "mit")

ModelResult

interface ModelResult {
  id: string;           // Model identifier
  name: string;         // Model name
  description: string;  // Model description
  task: string;         // Task type (e.g., 'text-generation')
  provider: string;     // Provider (e.g., 'huggingface')
  license: string;      // License type
  downloads?: number;   // Download count
  score: number;        // Similarity score (0-1)
  endpoint?: string;    // Inference endpoint URL
}

Examples

Text Generation

const models = await router.selectModel('generate creative stories');

Image Generation

const models = await router.selectModel('generate anime artwork');

Text Classification

const models = await router.selectModel('sentiment analysis');

Open Source Only

const models = await router.selectModel('summarize documents', {
  filter: { license: 'apache-2.0' }
});

Customizing the Model Registry

The package includes a pre-built registry with 7,000+ models. You can customize which models are included by modifying scripts/generate-model-registry.ts and running:

npm run generate-registry

This will regenerate data/model-registry.json based on your changes. Then run the indexing process again:

npx autorouter-sdk index-models

Key parameters in generate-model-registry.ts:

  • modelsPerTask: Number of models to fetch per task type (default: 200)
  • taskCategories: Which task types to include
  • sortBy: How to sort models (default: 'downloads')

CLI Commands

Index Models

autorouter-sdk index-models

Options:

  • --openai-key <key>: OpenAI API key (or use OPENAI_API_KEY env var)
  • --pinecone-key <key>: Pinecone API key (or use PINECONE_API_KEY env var)
  • --index-name <name>: Pinecone index name (default: 'autorouter-models')
  • --registry-path <path>: Path to custom model registry JSON file

Error Handling

try {
  const models = await router.selectModel('build a chatbot');
} catch (error) {
  console.error('Failed to select model:', error);
}

License

MIT