ai.matey Documentation
Welcome to ai.matey - the Universal AI Adapter System that lets you write once and run anywhere.
What is ai.matey?
Section titled βWhat is ai.matey?βai.matey is a comprehensive TypeScript/JavaScript framework that provides a unified interface for interacting with multiple AI providers. Write your code once using any standard format (OpenAI, Anthropic, Google, etc.) and seamlessly switch between 24+ AI providers without changing your application code.
import { Bridge } from 'ai.matey.core';import { OpenAIFrontendAdapter } from 'ai.matey.frontend/openai';import { AnthropicBackendAdapter } from 'ai.matey.backend/anthropic';
// Write code in OpenAI format, execute with Anthropicconst bridge = new Bridge( new OpenAIFrontendAdapter(), new AnthropicBackendAdapter({ apiKey: 'your-key' }));
const response = await bridge.chat({ model: 'gpt-4', messages: [{ role: 'user', content: 'Hello!' }]});Key Features
Section titled βKey Featuresβπ Universal Compatibility
Section titled βπ Universal Compatibilityβ- 24+ AI Providers: OpenAI, Anthropic, Google Gemini, Cohere, Groq, DeepSeek, Ollama, and more
- 7 Input Formats: Write in your preferred API format
- Seamless Switching: Change providers without changing code
π― Smart Routing
Section titled βπ― Smart Routingβ- Load Balancing: Round-robin, weighted, priority-based routing
- Automatic Failover: Built-in redundancy and error recovery
- Cost Optimization: Route to cheapest provider based on quality requirements
- Custom Strategies: Build your own routing logic
π§ Powerful Middleware
Section titled βπ§ Powerful Middlewareβ- Logging: Track all requests and responses
- Caching: Reduce costs with intelligent caching
- Retry Logic: Automatic retries with exponential backoff
- Cost Tracking: Monitor API spending in real-time
- Transforms: Modify requests/responses on-the-fly
π Production Ready
Section titled βπ Production Readyβ- 100% Test Coverage: All core packages fully tested
- TypeScript First: Complete type safety
- Edge Compatible: Deploy to Cloudflare Workers, Vercel Edge, Deno Deploy
- Framework Agnostic: Works with Express, Hono, Next.js, and more
Quick Start
Section titled βQuick StartβGet started with ai.matey in under 5 minutes:
- Installation - Install packages and set up your environment
- Quick Start - Your first Bridge in 30 seconds
- Core Concepts - Understand the architecture
- Examples - 34 runnable examples from basic to advanced
Architecture Overview
Section titled βArchitecture Overviewβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Your Application ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Frontend Adapter ββ (OpenAI, Anthropic, Google, Ollama, etc.) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Intermediate Representation (IR) ββ (Universal Format Layer) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Middleware Stack ββ (Logging, Caching, Retry, Transform, etc.) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Backend Adapter ββ (OpenAI, Anthropic, Gemini, Groq, Ollama, etc.) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ AI Provider ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββUse Cases
Section titled βUse CasesβProvider Migration
Section titled βProvider MigrationβSwitch from OpenAI to Anthropic (or any provider) with zero code changes:
// Beforeconst bridge = new Bridge( new OpenAIFrontendAdapter(), new OpenAIBackendAdapter({ apiKey }));
// After - just change the backendconst bridge = new Bridge( new OpenAIFrontendAdapter(), new AnthropicBackendAdapter({ apiKey }));Cost Optimization
Section titled βCost OptimizationβRoute simple queries to cheaper models, complex ones to powerful models:
const router = new Router(new OpenAIFrontendAdapter(), { backends: [deepseek, groq, openai, anthropic], strategy: 'custom', customStrategy: (request) => { const complexity = analyzeComplexity(request); if (complexity < 25) return 0; // DeepSeek (cheapest) if (complexity < 50) return 1; // Groq if (complexity < 80) return 2; // OpenAI return 3; // Anthropic (most capable) }});High Availability
Section titled βHigh AvailabilityβAutomatic failover when providers go down:
const router = new Router(new OpenAIFrontendAdapter(), { backends: [primary, secondary, tertiary], strategy: 'priority', fallbackOnError: true, healthCheck: { enabled: true, interval: 60000 }});Packages Overview
Section titled βPackages Overviewβai.matey is built as a monorepo with 21 specialized packages:
| Package | Purpose | Status |
|---|---|---|
| ai.matey.core | Bridge & Router | β Production |
| ai.matey.frontend | 7 input format adapters | β Production |
| ai.matey.backend | 24 provider adapters | β Production |
| ai.matey.middleware | Logging, caching, retry, etc. | β Production |
| ai.matey.http | HTTP server integrations | β Production |
| ai.matey.wrapper | Drop-in SDK replacements | β Production |
| ai.matey.cli | Command-line interface | β Production |
| ai.matey.react.hooks | React hooks | β Production |
| ai.matey.utils | Shared utilities | β Production |
| ai.matey.types | TypeScript definitions | β Production |
Community & Support
Section titled βCommunity & Supportβ- GitHub - Source code, issues, discussions
- npm - Package registry
- Examples - 34 working examples
- API Reference - Complete API documentation
Whatβs Next?
Section titled βWhatβs Next?βReady to get started? Here are some recommended paths:
For Beginners
Section titled βFor Beginnersβ- Read the Core Concepts
- Follow the Quick Start Guide
- Try the Hello World Example
For Production
Section titled βFor Productionβ- Review Production Patterns
- Explore Integration Patterns
- Check Testing Strategies
For Developers
Section titled βFor Developersβ- Study the IR Format
- Browse Provider Documentation
- Review the API Reference
Ready to build? Start with Installation β