Skip to content

Repository files navigation

HonoBox - AI Gateway

Open-source LLM Gateway with real-time monitoring dashboard.

Preview

Dashboard

API Management

Features

  • Multi-model routing — OpenAI-compatible API, supports any provider (OpenAI, Anthropic, DeepSeek, local models)
  • Real-time monitoring — SSE-based live dashboard updates
  • API Key management — Database-backed keys with per-key rate limiting
  • Model management — CRUD models via API or dashboard
  • Request tracing — Full trace ID across all logs
  • PostgreSQL persistence — Request logs, API keys, and models

Tech Stack

Layer Tech
Runtime Node.js + TypeScript (strict)
Backend Hono + Drizzle ORM + PostgreSQL
Frontend React 19 + TanStack Query + Recharts
Real-time Server-Sent Events (SSE)
Testing Vitest (20 tests)
Monorepo pnpm workspace

Quick Start

Prerequisites

  • Node.js >= 20
  • pnpm >= 9
  • PostgreSQL (or Docker)

1. Start PostgreSQL

# Option A: Docker (recommended)
docker run -d --name ai-gateway-db \
  -p 5432:5432 \
  -e POSTGRES_DB=ai_gateway \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=postgres \
  postgres:16-alpine

# Option B: Use your local PostgreSQL
# Create database: ai_gateway

2. Install & Configure

# Install dependencies
pnpm install

# Configure environment
cp apps/gateway/.env.example apps/gateway/.env
# Edit apps/gateway/.env with your database credentials

3. Initialize Database

cd apps/gateway
npx drizzle-kit push

4. Start Development

pnpm dev

# Gateway: http://localhost:3000
# Dashboard: http://localhost:5173

5. Add a Model

# Via Dashboard: http://localhost:5173 -> Models -> Add Model

# Or via API:
curl -X POST http://localhost:3000/api/models \
  -H "Content-Type: application/json" \
  -d '{
    "name": "GPT-4o",
    "provider": "openai",
    "modelId": "gpt-4o",
    "baseUrl": "https://api.openai.com/v1",
    "apiKey": "sk-your-key"
  }'

6. Create API Key

# Via Dashboard: http://localhost:5173 -> API Keys -> Create Key

# Or via API:
curl -X POST http://localhost:3000/api/api-keys \
  -H "Content-Type: application/json" \
  -d '{"name": "My App"}'

API Usage

# List models
curl http://localhost:3000/v1/chat/models

# Chat completion
curl -X POST http://localhost:3000/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

# Chat completion (streaming)
curl -X POST http://localhost:3000/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'

# Health check
curl http://localhost:3000/health

Testing

pnpm test
 ✓ apps/gateway/src/lib/__tests__/request-store.test.ts (7 tests)
 ✓ apps/gateway/src/providers/__tests__/index.test.ts (5 tests)
 ✓ apps/gateway/src/routes/__tests__/health.test.ts (1 test)
 ✓ apps/gateway/src/routes/__tests__/chat.test.ts (3 tests)
 ✓ packages/shared/src/__tests__/types.test.ts (3 tests)

 Test Files  5 passed (5)
      Tests  20 passed (20)

Project Structure

honobox/
├── apps/
│   ├── gateway/          # Hono API server
│   │   ├── src/
│   │   │   ├── providers/    # Model provider abstraction
│   │   │   ├── routes/       # API routes
│   │   │   ├── middlewares/  # Auth, rate-limit, trace
│   │   │   ├── db/           # Drizzle schema & connection
│   │   │   └── lib/          # Logger, event-bus, request-store
│   │   └── drizzle.config.ts
│   │
│   └── dashboard/        # React frontend
│       └── src/
│           ├── features/     # Dashboard, API Keys, Models, Logs
│           ├── components/   # Layout, UI components
│           └── lib/          # SSE client
│
├── packages/
│   └── shared/           # Shared TypeScript types
│       └── src/
│
├── pnpm-workspace.yaml
└── package.json

Environment Variables

# apps/gateway/.env

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=ai_gateway

# Server
PORT=3000

License

MIT

About

Lightweight AI Gateway built on Hono — SSE proxy, tracing, rate limiting, LLM observability

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages