autorouter-ai
v0.1.0
Published
Auto-select the best AI model for your task
Maintainers
Readme
Autorouter
Auto-select the best AI model for your task based on natural language queries.
Installation
npm install autorouterQuick Start
import { AutoRouter } from 'autorouter';
const router = new AutoRouter({ apiKey: 'ar_live_your_api_key_here' });
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: 'llama2',
// downloads: 5000000,
// score: 0.95
// },
// ...
// ]API Reference
new AutoRouter(config)
Creates a new AutoRouter instance.
Parameters:
config.apiKey(required): Your Autorouter API keyconfig.baseUrl(optional): Custom API base URL (default:https://api.autorouter.ai)
selectModel(query, options?)
Searches for the best models matching your query.
Parameters:
query(string): Natural language description of your taskoptions.limit(number, optional): Number of results to return (1-20, default: 5)options.filter(object, optional): Filter results by metadata
Returns: Promise<ModelResult[]>
Example:
// Basic query
const models = await router.selectModel('generate images');
// With options
const models = await router.selectModel('summarize text', {
limit: 10,
filter: { license: 'apache-2.0' }
});Model Result
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
}Pricing
- Free Tier: 50 queries/month included
- Paid: $10 for 1,000 additional queries
- Pro: Custom pricing for high-volume usage
Get your API key at autorouter.ai
Error Handling
import { AutoRouter, AuthenticationError, InsufficientCreditsError } from 'autorouter';
try {
const models = await router.selectModel('transcribe audio');
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid API key');
} else if (error instanceof InsufficientCreditsError) {
console.error('Out of credits');
} else {
console.error('Request failed:', error.message);
}
}Use Cases
- Chatbot development:
"build a conversational chatbot" - Image generation:
"create realistic product photos" - Text summarization:
"summarize long documents" - Video generation:
"generate social media videos" - Code generation:
"generate Python scripts"
License
MIT
