Skip to content

API Reference

Complete API documentation for all aimatey packages.

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

View Bridge API →


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

View Router API →


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

View Middleware API →


Complete TypeScript type definitions.

  • IR types (IRChatRequest, IRChatResponse, etc.)
  • Adapter interfaces (BackendAdapter, FrontendAdapter)
  • Configuration types (BridgeConfig, RouterConfig)
  • Utility types and type guards

View Types API →


Complete error handling reference.

  • Error hierarchy (AdapterError, ProviderError, ValidationError, etc.)
  • Error codes and descriptions
  • Error handling patterns
  • Best practices

View Errors API →


The foundational package containing Bridge, Router, and core functionality.

Key Exports:

  • Bridge - Connect frontend and backend adapters → API
  • Router - Route requests to multiple backends → API
  • MiddlewareStack - Manage middleware chain

View Package Documentation →

TypeScript type definitions for all packages.

Key Types:

  • IRChatRequest - Intermediate Representation request format
  • IRChatResponse - IR response format
  • IRStreamChunk - Streaming chunk format
  • BackendAdapter - Backend interface
  • FrontendAdapter - Frontend interface
  • Middleware - Middleware function type

View Full API Documentation →

Error classes and utilities.

Key Exports:

  • AdapterError - Base error class for every adapter error
  • ProviderError - Provider API returned an error
  • NetworkError - Network request failed
  • RateLimitError - Rate limit exceeded
  • AuthenticationError - Invalid API key
  • ValidationError - Request validation failed

View Full API Documentation →

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

View Frontend 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

View All Backend Providers →

Built-in middleware for common use cases.

Available Middleware:

  • createLoggingMiddleware() - Request/response logging
  • createCachingMiddleware() - Response caching
  • createRetryMiddleware() - Automatic retry with backoff
  • createTransformMiddleware() - Request/response transformation
  • createCostTrackingMiddleware() - Track API costs
  • createOpenTelemetryMiddleware() - Distributed tracing (async)
  • createValidationMiddleware() - Request validation
  • createSecurityMiddleware() - PII redaction, sanitization, prompt-injection detection, HTTP header policy
  • createConversationHistoryMiddleware() - Conversation state

View Middleware Guide →

HTTP server integration for Express, Fastify, Hono, and Node.js http.

Key Exports:

  • ExpressMiddleware - Express.js integration
  • FastifyHandler - Fastify handler
  • HonoMiddleware - Hono middleware
  • NodeHTTPListener - Node.js http integration

View Examples →

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>;
}
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>;
}
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.

All packages include full TypeScript definitions. Import types:

import type {
IRChatRequest,
IRChatResponse,
IRStreamChunk,
BackendAdapter,
FrontendAdapter,
Middleware
} from '@johnhenry/aimatey-types';

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"
}
}

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

Found an issue with the API? Want to request a new feature?


Explore the API: