API Reference
Complete API documentation for all aimatey packages.
Core API
Section titled “Core API”Comprehensive reference for the core aimatey APIs:
Complete reference for the Bridge class - connecting frontend and backend adapters.
- Constructor and configuration
- Request/response methods (chat, chatStream, execute)
- Middleware management
- Event handling
- Error handling
Complete reference for the Router class - intelligent multi-backend routing.
- Routing strategies (round-robin, priority, weighted, custom)
- Backend management
- Health monitoring
- Failover and fallback
- Advanced routing patterns
Complete reference for all built-in middleware and the Middleware interface.
- Logging, caching, retry, transform
- Cost tracking, validation, security
- OpenTelemetry tracing
- Creating custom middleware
- Middleware composition
Complete TypeScript type definitions.
- IR types (IRChatRequest, IRChatResponse, etc.)
- Adapter interfaces (BackendAdapter, FrontendAdapter)
- Configuration types (BridgeConfig, RouterConfig)
- Utility types and type guards
Complete error handling reference.
- Error hierarchy (AdapterError, ProviderError, ValidationError, etc.)
- Error codes and descriptions
- Error handling patterns
- Best practices
Core Packages
Section titled “Core Packages”@johnhenry/aimatey-core
Section titled “@johnhenry/aimatey-core”The foundational package containing Bridge, Router, and core functionality.
Key Exports:
Bridge- Connect frontend and backend adapters → APIRouter- Route requests to multiple backends → APIMiddlewareStack- Manage middleware chain
@johnhenry/aimatey-types
Section titled “@johnhenry/aimatey-types”TypeScript type definitions for all packages.
Key Types:
IRChatRequest- Intermediate Representation request formatIRChatResponse- IR response formatIRStreamChunk- Streaming chunk formatBackendAdapter- Backend interfaceFrontendAdapter- Frontend interfaceMiddleware- Middleware function type
@johnhenry/aimatey-errors
Section titled “@johnhenry/aimatey-errors”Error classes and utilities.
Key Exports:
AdapterError- Base error class for every adapter errorProviderError- Provider API returned an errorNetworkError- Network request failedRateLimitError- Rate limit exceededAuthenticationError- Invalid API keyValidationError- Request validation failed
Adapter Packages
Section titled “Adapter Packages”Frontend Adapters
Section titled “Frontend Adapters”Parse different input formats into IR.
- @johnhenry/aimatey-frontend/openai - OpenAI chat completion format
- @johnhenry/aimatey-frontend/anthropic - Anthropic messages API format
- @johnhenry/aimatey-frontend/gemini - Google Gemini format
- @johnhenry/aimatey-frontend/mistral - Mistral format
- @johnhenry/aimatey-frontend/ollama - Ollama format
- @johnhenry/aimatey-frontend/chrome-ai - Chrome built-in AI format
- @johnhenry/aimatey-frontend/generic - Generic IR format
Backend Adapters
Section titled “Backend Adapters”Convert IR to provider-specific formats and execute requests.
24 Supported Providers:
- @johnhenry/aimatey-backend/openai
- @johnhenry/aimatey-backend/anthropic
- @johnhenry/aimatey-backend/gemini
- @johnhenry/aimatey-backend/mistral
- @johnhenry/aimatey-backend/ollama
- @johnhenry/aimatey-backend/groq
- … and 18 more
Middleware Packages
Section titled “Middleware Packages”@johnhenry/aimatey-middleware
Section titled “@johnhenry/aimatey-middleware”Built-in middleware for common use cases.
Available Middleware:
createLoggingMiddleware()- Request/response loggingcreateCachingMiddleware()- Response cachingcreateRetryMiddleware()- Automatic retry with backoffcreateTransformMiddleware()- Request/response transformationcreateCostTrackingMiddleware()- Track API costscreateOpenTelemetryMiddleware()- Distributed tracing (async)createValidationMiddleware()- Request validationcreateSecurityMiddleware()- PII redaction, sanitization, prompt-injection detection, HTTP header policycreateConversationHistoryMiddleware()- Conversation state
Integration Packages
Section titled “Integration Packages”@johnhenry/aimatey-http
Section titled “@johnhenry/aimatey-http”HTTP server integration for Express, Fastify, Hono, and Node.js http.
Key Exports:
ExpressMiddleware- Express.js integrationFastifyHandler- Fastify handlerHonoMiddleware- Hono middlewareNodeHTTPListener- Node.js http integration
Quick Links
Section titled “Quick Links”By Use Case
Section titled “By Use Case”- Building a Chat App? → Tutorial: Building a Chat API
- HTTP API? → Examples
- Multi-Provider Routing? → Tutorial: Multi-Provider
- Need Caching? → Middleware Package
- Testing? → Testing Guide
By Package
Section titled “By Package”- @johnhenry/aimatey-core - Bridge, Router, Middleware
- @johnhenry/aimatey-frontend - Frontend adapters
- @johnhenry/aimatey-backend - Backend adapters
- @johnhenry/aimatey-middleware - Middleware
- All 23 published packages - HTTP, React, patterns, MCP, wrappers, CLI, native backends, and more
Common Interfaces
Section titled “Common Interfaces”BackendAdapter Interface
Section titled “BackendAdapter Interface”interface BackendAdapter { readonly metadata: AdapterMetadata; fromIR(request: IRChatRequest): unknown; toIR(response: unknown, originalRequest: IRChatRequest, latencyMs: number): IRChatResponse; execute(request: IRChatRequest, signal?: AbortSignal): Promise<IRChatResponse>; /** Returns the stream itself, not a Promise */ executeStream(request: IRChatRequest, signal?: AbortSignal): IRChatStream; healthCheck?(): Promise<boolean>;}FrontendAdapter Interface
Section titled “FrontendAdapter Interface”interface FrontendAdapter { readonly metadata: AdapterMetadata; toIR(request: unknown): Promise<IRChatRequest>; fromIR(response: IRChatResponse): Promise<unknown>; fromIRStream(stream: IRChatStream): AsyncGenerator<unknown, void, undefined>; validate?(request: unknown): Promise<void>;}Middleware Interface
Section titled “Middleware Interface”type Middleware = ( context: MiddlewareContext, next: () => Promise<IRChatResponse>) => Promise<IRChatResponse>;
// context.request is the IR request (readable and replaceable),// context.state is a per-request scratch object shared between middleware.TypeScript Support
Section titled “TypeScript Support”All packages include full TypeScript definitions. Import types:
import type { IRChatRequest, IRChatResponse, IRStreamChunk, BackendAdapter, FrontendAdapter, Middleware} from '@johnhenry/aimatey-types';Version Compatibility
Section titled “Version Compatibility”All aimatey packages use synchronized versioning. Always use matching versions across packages:
{ "dependencies": { "@johnhenry/aimatey-core": "^0.2.0", "@johnhenry/aimatey-frontend": "^0.2.0", "@johnhenry/aimatey-backend": "^0.2.0" }}Auto-Generated Documentation
Section titled “Auto-Generated Documentation”Detailed API documentation is auto-generated from TypeScript source code using TypeDoc:
- View All Packages → - Complete directory of all 23 published packages, with symbol-level reference generated from source
Contributing
Section titled “Contributing”Found an issue with the API? Want to request a new feature?
Explore the API: