Skip to content

ljq/TokenHub

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

118 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TokenHub

TokenHub

TokenHub is a private enterprise AI gateway with role-based workspaces for users, team leaders, and administrators.

License Go 1.26 Next.js 16.2.9 React 19.2.7 SQLite first Docker Compose OpenAI Compatible i18n ZH EN JA

English | 简体中文 | 日本語

Screenshots

Login Console Gateway Overview
Login Console Gateway Overview
API Documentation Provider Channels
API Documentation Provider Channels
Model Catalog Routing Policies
Model Catalog Routing Policies
Usage Analytics System Settings
Usage Analytics System Settings

Designed Around Three Roles

TokenHub separates everyday model usage, team governance, and platform administration so enterprise users see the workflows that match their responsibility.

Role Workspace Focus Guide
User Find available models, create project-scoped API keys, call the model API, and review personal usage User Guide
Team Leader Manage project spaces, project members, project keys, team reports, and project cost attribution Team Leader Guide
Administrator Configure providers, model catalog, routing policies, identity sources, RBAC, audit, and cost controls Administrator Guide

Platform Capabilities

  • OpenAI-compatible model APIs: /v1/chat/completions, /v1/responses, /v1/embeddings.
  • Provider channels for OpenAI-compatible, Azure OpenAI, Anthropic, Gemini, DeepSeek, Qwen, local vLLM/Ollama, and custom upstreams.
  • Model catalog and routing policies with priority, weight, failover order, and route health diagnostics.
  • Project-scoped key management with team ownership, member permissions, quotas, and concurrency controls.
  • Usage analytics and request logs attributed to user, project, team, model, and cost center.
  • Identity source configuration for OAuth/OIDC enterprise sign-in, plus RBAC and audit trails.
  • Clean console with compact role-aware navigation, global search, light/dark mode, and split-view API documentation.
  • SQLite-first private deployment with Docker Compose support.
  • PostgreSQL support for production deployments with connection pooling. See the PostgreSQL setup guide.
  • Console language switching for English, Chinese, and Japanese.

Multi-Instance Architecture

The default installation starts one frontend and one backend with SQLite. For horizontal scaling, use deploy/docker-compose.remote-postgres.yml: it places Nginx in front of scalable frontend and backend replicas and stores shared state in a remote PostgreSQL database. A SQLite file must never be shared by multiple backend replicas.

TokenHub multi-instance architecture

In multi-instance mode:

  • Nginx load-balances console, API, and health-check traffic across healthy replicas.
  • Backend replicas keep durable configuration, OAuth sessions, quota buckets, audit data, cluster locks, and in-flight concurrency leases in PostgreSQL.
  • Lease expiry and ownership decisions use the PostgreSQL clock, avoiding early takeover caused by clock skew between hosts. Heartbeats cancel work when lease ownership is lost.
  • The mounted model catalog is synchronized on every backend startup; a cluster lease serializes the idempotent synchronization across replicas.
  • Coordination failures release provider capacity without incorrectly marking a healthy model provider as failed.

All backend replicas must use the same TOKENHUB_SECRET_KEY. Size TOKENHUB_DB_MAX_OPEN_CONNS per replica so the combined connection pool stays below the PostgreSQL limit.

docker compose --env-file deploy/.env \
  -f deploy/docker-compose.remote-postgres.yml up -d \
  --scale tokenhub-backend=3 \
  --scale tokenhub-frontend=2

See the deployment guide for configuration requirements, probes, and the real PostgreSQL E2E test.

Quick Start

cp deploy/.env.example deploy/.env
# Replace every change-me value in deploy/.env with a strong secret.
./deploy/install.sh

Open:

  • Admin console: http://localhost:3000
  • Backend API: http://localhost:8080
  • Health check: http://localhost:8080/healthz

Initial admin login:

  • Username: admin
  • Password: the value of TOKENHUB_BOOTSTRAP_ADMIN_PASSWORD

The deployment script validates production credentials before building. It reports each unsafe variable without printing secret values. If Compose fails because a backend container created or restarted by that attempt is unhealthy, the script automatically shows only that attempt's recent backend logs.

Local Development

Backend:

cd backend
go run ./cmd/tokenhub

Frontend:

cd frontend
npm install
npm run dev

Smoke-test the model API with the included SDK example:

cd sdk
npm install
npm run test:deepseek

Documentation

Star History

Star History Chart

License

TokenHub is licensed under the Apache License 2.0.

About

TokenHub is a private enterprise AI gateway with role-based workspaces for users, team leaders, and administrators.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 48.2%
  • Go 39.1%
  • CSS 10.9%
  • Shell 1.1%
  • Other 0.7%