Skip to content

6639835/conduit

Repository files navigation

Conduit - Claude, OpenAI (ChatGPT), Gemini API Gateway with Analytics

A transparent, edge-first API gateway for Claude, OpenAI, and Gemini with built-in usage analytics, rate limiting, and beautiful dashboards.

Features

  • Transparent Proxy: Forwards Claude, OpenAI, and Gemini API requests without wrapping or modifying the API
  • Edge Runtime: Global distribution with Vercel Edge for ultra-low latency
  • Rate Limiting: Per-minute and per-day limits enforced at the edge with Vercel KV
  • Quota Management: Token-based quotas with real-time tracking
  • Usage Analytics: Detailed logging with cost tracking and model breakdowns
  • No User Auth: Users view usage by searching with their API key (no login required)
  • Admin Dashboard: Full control over API keys, quotas, and analytics
  • Streaming Support: SSE streaming responses with real-time token extraction

Quick Start

1. Install Dependencies

npm install

2. Set Up Environment

Create .env.local:

DATABASE_URL=postgresql://...neon.tech/conduit?sslmode=require
KV_REST_API_URL=https://....kv.vercel-storage.com
KV_REST_API_TOKEN=xxx
NEXTAUTH_SECRET=your-secret-32-chars
NEXTAUTH_URL=http://localhost:3000
CRON_SECRET=your-long-random-cron-secret
METRICS_SECRET=your-long-random-metrics-secret
API_KEY_ENCRYPTION_KEY=your-256-bit-hex-key
CLAUDE_API_KEY=sk-ant-your-key-here

3. Set Up Database

npm run db:push

4. Create Admin User

Create your first admin user to access the dashboard:

Interactive mode (recommended):

npm run db:seed

Or specify credentials directly:

npm run db:seed -- --email admin@example.com --password securepass --name "Admin User"

The script will:

  • ✅ Validate email format
  • ✅ Hash the password securely (bcrypt)
  • ✅ Create the admin user in the database
  • ✅ Warn if using a weak password

5. Run Development Server

npm run dev

Visit http://localhost:3000

Usage

Admin: Login and Create API Keys

  1. Login at http://localhost:3000/login with your admin credentials
  2. Go to http://localhost:3000/admin/keys
  3. Click "Create New Key"
  4. Enter your Claude API key and set limits
  5. Copy the generated key (shown once)

Users: View Usage

  1. Go to http://localhost:3000/usage
  2. Enter your API key
  3. View usage stats and remaining quota

Make Claude API Requests

curl -X POST http://localhost:3000/api/claude/v1/messages \
  -H "Authorization: Bearer sk-cond_xxx" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

### Make OpenAI API Requests (ChatGPT / Responses)

```bash
curl -X POST http://localhost:3000/api/openai/v1/responses \
  -H "Authorization: Bearer sk-cond_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.1-codex-mini",
    "input": "Explain what this repository does."
  }'

Make Gemini API Requests

curl -X POST http://localhost:3000/api/gemini/v1beta/models/gemini-1.5-flash:generateContent \
  -H "Authorization: Bearer sk-cond_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{ "role": "user", "parts": [{ "text": "Hello!" }] }]
  }'

## Tech Stack

- Next.js 16 + TypeScript
- Neon PostgreSQL
- Vercel KV (Redis)
- Drizzle ORM
- Tailwind CSS

## Project Structure

src/ ├── app/ │ ├── (public)/usage/ # User dashboard │ ├── (admin)/admin/ # Admin dashboard │ ├── api/ │ │ ├── claude/[...path]/ # Main proxy │ │ ├── openai/[...path]/ # OpenAI proxy │ │ ├── gemini/[...path]/ # Gemini proxy │ │ ├── admin/keys/ # Key management │ │ └── usage/ # Usage API │ └── page.tsx # Landing ├── lib/ │ ├── auth/ # API key validation │ ├── proxy/ # Proxy & streaming │ ├── rate-limit/ # Rate limiting │ ├── analytics/ # Usage tracking │ └── db/ # Database └── types/ # TypeScript types


## Deployment

### Vercel (Recommended)

```bash
vercel

Set up Neon PostgreSQL and Vercel KV in Vercel Dashboard > Storage.

Production Checklist

  • Set NEXTAUTH_SECRET, API_KEY_ENCRYPTION_KEY, CRON_SECRET, and METRICS_SECRET to strong random values
  • Set NEXTAUTH_URL and optionally NEXT_PUBLIC_APP_URL to your canonical HTTPS origin
  • Provision Neon PostgreSQL and Vercel KV before enabling traffic
  • Run npm run build in CI for every change
  • Configure the cron jobs in vercel.json
  • Keep .env.local local-only and use .env.example as the shareable template
  • Wire a real provider-backed cache warming implementation before enabling that admin workflow

Security Notes

⚠️ For Production:

  1. Admin routes are protected with NextAuth and proxy-level gating; restrict admin user creation operationally
  2. Rotate encryption keys regularly
  3. Never log full API keys
  4. Enable monitoring and alerts
  5. Use HTTPS everywhere

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages