Open-source AI gateway for managing LLM requests with intelligent routing and fallbacks.
Layer sits between your application and AI providers (OpenAI, Anthropic, Google), giving you a unified API to manage models, track costs, and implement routing strategies—all from a single interface.
- Unified API - One interface for OpenAI, Anthropic, and Google models
- Fallback Support - Automatic failover when primary models are unavailable
- Load Balancing - Distribute requests across multiple models with round-robin
- Request Logging - Track all requests, costs, and performance metrics
- Configuration Management - Define gates (model configs) via YAML or SDK
- CLI Tool - Manage everything from the command line
- TypeScript SDK - Type-safe client library for Node.js applications
- Self-Hostable - Run on your own infrastructure
npm install @layer-ai/sdk @layer-ai/cliimport { Layer } from '@layer-ai/sdk';
const layer = new Layer({
apiKey: process.env.LAYER_API_KEY,
baseUrl: 'http://localhost:3001'
});
// Complete a request through a gate
const response = await layer.complete({
gate: 'my-gate',
prompt: 'What is the capital of France?'
});
console.log(response.text);# Initialize a new config file
npx layer init
# Login to your Layer instance
npx layer login
# Create a gate
npx layer gates create
# Sync gates to/from config file
npx layer pull
npx layer pushLayer consists of three main components:
- API Server (
packages/api) - REST API for managing gates, keys, and completions - SDK (
packages/sdk) - TypeScript client library - CLI (
packages/cli) - Command-line interface for management
Define your gates in layer.config.yaml:
gates:
- name: default
model: gpt-4o
description: Default gate for general queries
temperature: 0.7
maxTokens: 1000
routingStrategy: fallback
fallbackModels:
- claude-sonnet-4
- gemini-2.0-flash-exp- Single - Use one model
- Fallback - Try backup models if primary fails
- Round-robin - Distribute requests across multiple models
Layer is designed to be self-hosted. See the deployment guide for instructions on running Layer on your own infrastructure.
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run API server
pnpm --filter @layer-ai/api dev
# Run tests
pnpm testWe welcome contributions! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.