13 KiB
TokenFactory
AI gateway you self-host: route many model providers through one API surface, with users, keys, quotas, and an admin UI.
Upstream (required reading)
TokenFactory is derived from the QuantumNous/new-api project (“New API”). That repository is the authoritative upstream for design, protocol coverage, and community history. This fork may diverge; for behavior and APIs, treat upstream docs as the baseline and verify against your build.
| Upstream repository | github.com/QuantumNous/new-api |
| License | GNU AGPL v3.0 — same for modifications here; see NOTICE |
| Network use | If you offer a modified version over a network to others, AGPL-3.0 section 13 requires you to provide the corresponding full source under the same license. |
简体中文 | 繁體中文 | English | Français | 日本語
Quick Start • Documentation • Languages • Deployment • License • Help
About this repository
TokenFactory is a self-hosted control plane for aggregating upstream AI vendors: one place to configure channels, map models, enforce access, and observe usage. You run the binary (or container), point clients at it, and manage everything from the web console.
This README describes this fork’s packaging and pointers. It does not replace the upstream feature list or legal notices—those remain tied to QuantumNous/new-api and the license files in this tree.
Compliance & disclaimer
- Use only in line with provider terms (e.g. OpenAI Terms of Use) and applicable law. No illegal or abusive use.
- In China, follow registration and compliance rules for generative AI services (e.g. 《生成式人工智能服务管理暂行办法》); do not offer unregistered public generative AI services where prohibited.
- No warranty: treat this as self-supported infrastructure unless you arrange your own support.
Quick Start
Using Docker Compose (Recommended)
# Clone the project
git clone https://github.com/QuantumNous/token-factory.git
cd token-factory
# Edit docker-compose.yml configuration
nano docker-compose.yml
# Start the service
docker-compose up -d
Using Docker Commands
# Pull the latest image
docker pull ghcr.io/fyinfor/token-factory:latest
# Using SQLite (default)
docker run --name token-factory -d --restart always \
-p 3000:3000 \
-e TZ=Asia/Shanghai \
-v ./data:/data \
ghcr.io/fyinfor/token-factory:latest
# Using MySQL
docker run --name token-factory -d --restart always \
-p 3000:3000 \
-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" \
-e TZ=Asia/Shanghai \
-v ./data:/data \
ghcr.io/fyinfor/token-factory:latest
💡 Tip:
-v ./data:/datawill save data in thedatafolder of the current directory, you can also change it to an absolute path like-v /your/custom/path:/data
When the stack is healthy, open http://localhost:3000. More install paths (bare metal, panels, etc.): installation docs.
Documentation
The QuantumNous/new-api ecosystem publishes the reference manuals for APIs, models, and operations. TokenFactory tracks that stack; use the docs as the source of truth and validate against your build.
| Manual (EN / ZH) | docs.newapi.pro — English · 简体中文 |
| Environment variables | Configuration reference |
| Relay / REST API | API documentation |
| Feature overview | Features introduction |
| FAQ & community | FAQ · Channels |
| Deep dive (third-party) | DeepWiki — QuantumNous/new-api |
This repository: report fork-specific bugs (packaging, defaults, CI) here. If the behavior matches upstream, reproduce on QuantumNous/new-api and follow their contribution guidelines.
What you get (at a glance)
Capabilities come from the upstream codebase; this is a summary, not an exhaustive spec:
- Relay — many vendor adapters behind a unified API surface (OpenAI-compatible and other formats per upstream).
- Console — channels, model mapping, users, keys, usage and billing configuration.
- Policies — quotas, rate limits, retries, and optional cache when Redis is enabled.
- Storage — SQLite, MySQL, or PostgreSQL; optional Redis for sessions/cache/crypto as documented upstream.
For model-by-model and endpoint-by-endpoint detail, use the API docs and QuantumNous/new-api releases.
Supported languages
| Code | Language |
|---|---|
zh-CN |
Chinese (Simplified) |
zh-TW |
Chinese (Traditional) |
en |
English |
fr |
French |
ru |
Russian |
ja |
Japanese |
vi |
Vietnamese |
id |
Indonesian |
ms |
Malay |
th |
Thai |
sw |
Swahili |
Deployment
[!TIP] Latest Docker image:
ghcr.io/fyinfor/token-factory:latest
📋 Deployment Requirements
| Component | Requirement |
|---|---|
| Local database | SQLite (Docker must mount /data directory) |
| Remote database | MySQL ≥ 5.7.8 or PostgreSQL ≥ 9.6 |
| Container engine | Docker / Docker Compose |
⚙️ Environment Variable Configuration
Common environment variable configuration
| Variable Name | Description | Default Value |
|---|---|---|
SESSION_SECRET |
Session secret (required for multi-machine deployment) | - |
CRYPTO_SECRET |
Encryption secret (required for Redis) | - |
SQL_DSN |
Database connection string | - |
REDIS_CONN_STRING |
Redis connection string | - |
STREAMING_TIMEOUT |
Streaming timeout (seconds) | 300 |
STREAM_SCANNER_MAX_BUFFER_MB |
Max per-line buffer (MB) for the stream scanner; increase when upstream sends huge image/base64 payloads | 64 |
MAX_REQUEST_BODY_MB |
Max request body size (MB, counted after decompression; prevents huge requests/zip bombs from exhausting memory). Exceeding it returns 413 |
32 |
AZURE_DEFAULT_API_VERSION |
Azure API version | 2025-04-01-preview |
ERROR_LOG_ENABLED |
Error log switch | false |
PYROSCOPE_URL |
Pyroscope server address | - |
PYROSCOPE_APP_NAME |
Pyroscope application name | token-factory |
PYROSCOPE_BASIC_AUTH_USER |
Pyroscope basic auth user | - |
PYROSCOPE_BASIC_AUTH_PASSWORD |
Pyroscope basic auth password | - |
PYROSCOPE_MUTEX_RATE |
Pyroscope mutex sampling rate | 5 |
PYROSCOPE_BLOCK_RATE |
Pyroscope block sampling rate | 5 |
HOSTNAME |
Hostname tag for Pyroscope | token-factory |
📖 Complete configuration: Environment Variables Documentation
🔧 Deployment Methods
Docker Compose: use the Quick Start commands above (clone → edit docker-compose.yml → docker-compose up -d).
Alternative: plain Docker run
Using SQLite:
docker run --name token-factory -d --restart always \
-p 3000:3000 \
-e TZ=Asia/Shanghai \
-v ./data:/data \
ghcr.io/fyinfor/token-factory:latest
Using MySQL:
docker run --name token-factory -d --restart always \
-p 3000:3000 \
-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" \
-e TZ=Asia/Shanghai \
-v ./data:/data \
ghcr.io/fyinfor/token-factory:latest
💡 Path explanation:
./data:/data- Relative path, data saved in the data folder of the current directory- You can also use absolute path, e.g.:
/your/custom/path:/data
BaoTa Panel
- Install BaoTa Panel (≥ 9.2.0 version)
- Search for TokenFactory in the application store
- One-click installation
⚠️ Multi-machine Deployment Considerations
[!WARNING]
- Must set
SESSION_SECRET- Otherwise login status inconsistent- Shared Redis must set
CRYPTO_SECRET- Otherwise data cannot be decrypted
🔄 Channel Retry and Cache
Retry configuration: Settings → Operation Settings → General Settings → Failure Retry Count
Cache configuration:
REDIS_CONN_STRING: Redis cache (recommended)MEMORY_CACHE_ENABLED: Memory cache
Lineage
| Repository | Role |
|---|---|
| QuantumNous/new-api | Upstream — New API (AGPL-3.0). Start here for history, issues that are not fork-specific, and feature design. |
| One API | Earlier MIT-licensed codebase in the same family tree. |
| Midjourney-Proxy | Optional Midjourney integration (see upstream docs). |
Tools maintained around the ecosystem (e.g. neko-api-key-tool) are documented upstream.
Help
📖 Documentation Resources
| Resource | Link |
|---|---|
| 📘 FAQ | FAQ |
| 💬 Community Interaction | Communication Channels |
| 🐛 Issue Feedback | Issue Feedback |
| 📚 Complete Documentation | Official Documentation |
🤝 Contribution Guide
Welcome all forms of contribution!
- 🐛 Report Bugs
- 💡 Propose New Features
- 📝 Improve Documentation
- 🔧 Submit Code
License
This project (TokenFactory) is licensed under the GNU Affero General Public License v3.0 (AGPLv3). Modifications and further derivatives remain under AGPL-3.0 unless you obtain a separate commercial license from the copyright holders.
Attribution: TokenFactory is derived from QuantumNous/new-api (New API), which is also under AGPL-3.0. The project chain includes One API (MIT License) as an earlier base. Please retain upstream notices and this repository’s LICENSE and NOTICE. Under AGPL-3.0 section 13, if you run a modified version as a network service for others, you must offer them the corresponding complete source code under the same license.
If your organization's policies do not permit the use of AGPLv3-licensed software, or if you wish to avoid the open-source obligations of AGPLv3, please contact us at: support@quantumnous.com
TokenFactory — self-hosted AI gateway (this fork).
Upstream: QuantumNous/new-api · Docs: docs.newapi.pro · This repo: issues
The New API project is developed by QuantumNous and contributors. JetBrains supports open-source development through free IDE licenses.
