explaingit

xuya-dev/token-hub

16VueAudience · developerComplexity · 4/5ActiveLicenseSetup · hard

TLDR

Self-hosted marketplace that pools spare OpenAI, Anthropic, Google, and DeepSeek quota behind one sk-hub key with usage-based billing.

Mindmap

mindmap
  root((TokenHub))
    Inputs
      Upstream API keys
      OpenAI or Anthropic requests
      Redemption codes
    Outputs
      Unified sk-hub key
      Routed model responses
      Earnings cut
    Use Cases
      Share spare AI quota
      Pool model access
      Self host an AI gateway
    Tech Stack
      Java
      Spring Boot
      MySQL
      Redis
      Vue
      Vite

Things people build with this

USE CASE 1

Self-host a gateway that pools spare OpenAI and Anthropic quota for a team

USE CASE 2

Earn a cut by selling unused API quota to other callers under one sk-hub key

USE CASE 3

Point the official OpenAI or Anthropic SDK at one endpoint and let TokenHub route it

USE CASE 4

Track per-call billing with pre-deduction, settlement, and refund stages

Tech stack

JavaSpring BootMySQLRedisVueVite

Getting it running

Difficulty · hard Time to first run · 1day+

Needs Java 21, Node 20, MySQL 8, Redis 7, pnpm 10, plus secrets for JWT, AES-GCM encryption, and upstream API keys.

MIT, free to use, modify, and redistribute with attribution.

In plain English

TokenHub is a platform for sharing AI API access. The idea is that some people pay for accounts at OpenAI, Anthropic, Google, or DeepSeek and have spare quota sitting unused. They register that spare quota as a channel on TokenHub. Other people then use one unified key, in the format sk-hub-xxx, to call those models through TokenHub. The channel owner earns a configurable cut, between zero and fifty percent, every time their quota is used. For the caller side, the platform looks like an OpenAI or Anthropic endpoint. The README shows that pointing the official OpenAI or Anthropic SDK at TokenHub, by changing the base URL and API key, is enough to start using it. Behind that single endpoint, TokenHub routes the request to whichever channel has capacity, translates between OpenAI Chat Completions and Anthropic Messages formats when needed, and supports streaming responses through SSE. The billing model is described as three stages: a pre-deduction when the call starts, a real settlement based on actual token usage, and a refund if the call fails. Amounts are tracked in US dollars to eight decimal places. Users can earn free balance through a daily check-in, and admins can generate redemption codes to top up balances in bulk. The backend is Java 21 on Spring Boot 3.3.5, with MyBatis-Plus and Flyway for the database layer, Sa-Token for JWT and API-key authentication, Redis with Redisson for rate limiting and caching, and OkHttp for outbound calls. Upstream keys are stored encrypted with AES-GCM, and user keys are stored as SHA-256 hashes. The frontend is Vue 3 with Vite, TypeScript, Naive UI, UnoCSS, Pinia, and the SoybeanAdmin template. Installation needs Java 21, Node 20, MySQL 8, Redis 7, and pnpm 10. The README shows both a Maven dev-mode launch and a Docker Compose deployment, and lists the production environment variables for JWT secret, encryption key, CORS origins, and database credentials. License is MIT.

Copy-paste prompts

Prompt 1
Walk me through deploying TokenHub with Docker Compose and setting the JWT secret and encryption key
Prompt 2
Show me how a channel owner registers their OpenAI API key in TokenHub and sets the earnings cut
Prompt 3
Help me point the official Anthropic SDK at my TokenHub instance using an sk-hub key
Prompt 4
Explain how TokenHub translates between OpenAI Chat Completions and Anthropic Messages while streaming
Open on GitHub → Explain another repo

Generated 2026-05-22 · Model: sonnet-4-6 · Verify against the repo before relying on details.