Skip to content

fenwei-dev/fenwei-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fenwei-proxy

An LLM inference proxy that forwards OpenAI-compatible chat completion requests to upstream providers, with a management UI for configuring providers, API keys, client access, and request logging.

Quick Start

bun install
bun dev

Opens on http://localhost:3000 by default.

Build

bun compile

Compiles the project into a single standalone executable at dist/fenwei-proxy. The executable includes the Bun runtime, all source code, and the admin UI — no dependencies needed at runtime.

ADMIN_PASSWORD=mysecret PORT=8080 ./dist/fenwei-proxy

Configuration

Environment variables (create a .env file or set directly):

Variable Default Description
PORT 3000 Server port
DB_PATH fenwei.db SQLite database path
ADMIN_PASSWORD (auto-generated) Admin UI password. If not set, a random password is printed to stdout on startup.

Usage

Admin UI

Visit http://localhost:3000/admin and log in with the admin password. The UI has three tabs:

  • Upstream Providers — name, alias (for URL routing), base URL (include path prefix like /v1), multiple API keys (round-robin)
  • Client API Keys — generate and distribute to clients for authenticated access
  • Request Logs — view all proxied requests with filters by provider, model, client key, and stream type. Streaming requests store chunks individually.

Proxy Endpoint

POST /api/{alias}/v1/chat/completions
Authorization: Bearer <client-key>
Content-Type: application/json

Supports both streaming ("stream": true) and non-streaming requests. The request body is forwarded as-is to the upstream provider.

Key Passthrough

When enabled on a provider, non-fw- keys sent by clients are forwarded directly to the upstream provider without validation. fw- keys are still validated against client keys.

Example

curl http://localhost:3000/api/gpt4/v1/chat/completions \
  -H "Authorization: Bearer fw-xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4",
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Admin API

All endpoints under /admin/api/ require authentication (cookie or Bearer <token>).

Endpoint Method Description
/admin/api/login POST Login (set session cookie)
/admin/api/logout POST Logout (clear cookie)
/admin/api/providers GET List all providers
/admin/api/providers POST Create provider
/admin/api/providers/:id PUT Update provider
/admin/api/providers/:id DELETE Delete provider
/admin/api/providers/:id/keys POST Add a provider key
/admin/api/providers/keys/:id DELETE Delete a provider key
/admin/api/keys GET List all client keys
/admin/api/keys POST Generate a new client key
/admin/api/keys/:id DELETE Delete a client key
/admin/api/logs GET List request logs (paginated, filterable)
/admin/api/logs/filters GET Get distinct filter values
/health GET Health check

Project Structure

src/
  env.ts          # Environment variable configuration
  db.ts           # SQLite schema, migrations, and data access
  proxy.ts        # Request proxying (streaming & non-streaming)
  admin.ts        # Admin API handlers
  index.ts        # Server entry point
  frontend/
    admin.html    # Management UI (HTML)
    admin.css     # Management UI (styles)
    admin.ts      # Management UI (TypeScript)

Tech

  • Bun runtime with built-in SQLite
  • Zero external dependencies

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors