# Repository Briefing: songquanpeng/one-api
> Source: https://repoforai.com/repo/songquanpeng/one-api (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/songquanpeng/one-api
- **Official Docs / Website**: https://oneapi.justsong.cn/
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: JavaScript
- **License**: MIT
- **Engineering Health**: B (62/100 · Maintenance 6/35 · Adoption 25/25 · Releases 11/20 · License 20/20)
- **Latest Release**: v0.6.10 (2025-02-02) — https://github.com/songquanpeng/one-api/releases
- **Review Snapshot**: 2026-12-03
- **Deployment / Stack Signals**: Docker, Self-Hosted, API
- **Momentum**: 37,512 ★ total (+4 24h / +56 7d) · 6,890 forks
- **Topics**: `api`, `api-gateway`, `azure-openai-api`, `chatgpt`, `claude`, `ernie-bot`, `gemini`, `gpt`, `openai`, `openai-api`, `proxy`
- **When to Use**: Best for: Teams with several OpenAI-compatible clients that need to share approved upstream providers without distributing provider credentials to each application. Skip if: You need local inference, immediate access to provider-native APIs, or only one provider and no central token, quota, or routing requirements.

## Overview
```text
### Architecture & Core Mechanics
One API is a self-hosted relay, not an inference engine. The service starts at `main.go`, targets Go 1.20 in `go.mod`, and depends on Gin; the JavaScript frontend is built from `web/default` before compiling the single executable. The tree separates `router/`, `middleware/`, `controller/`, `model/`, and `relay/`, while the dependency manifest includes a Redis client and the AWS Bedrock Runtime SDK.

Clients authenticate to the gateway with a One API token and request a model through an OpenAI-compatible endpoint. The gateway selects an eligible upstream channel and uses that channel's credentials. For compatible upstreams it relays the request; for other providers it adapts the request and response bodies. The client-facing protocol stays consistent, but the available operations and behavior still depend on the selected provider adapter.

### Key Capabilities & Differentiators
One API lets existing OpenAI-compatible clients use configured channels for OpenAI and Azure OpenAI, Anthropic Claude including AWS-backed access, Google Gemini, DeepSeek, and Ollama, among other providers. The gateway supports streaming, and default load balancing spreads requests across eligible channels. An explicit channel override is available with administrator-created tokens. Operators can also schedule channel availability checks and balance updates.

The web console separates upstream credential management from downstream token issuance. Token limits are distinct from account limits. Quota accounting weights prompt tokens plus completion tokens adjusted by a completion multiplier, then applies model and group ratios. This is a gateway usage policy, not a substitute for reconciling upstream invoices. Model names and provider-specific behavior still need testing on the intended route.

### Trade-offs & Limitations
Compared with direct provider SDKs, One API reduces duplicate client integrations and centralizes who can use which upstream credentials. In return, it adds a network hop, a shared failure point, and a compatibility layer that may not expose native features as soon as a provider SDK does. Load balancing distributes traffic; it does not remove upstream rate limits. Unlike Ollama, the gateway does not run model weights or make a cloud-backed setup work offline.

Start with SQLite for a small single instance and prefer MySQL for higher concurrency or multiple nodes. Redis is useful when database access is slow, but caching and batched writes can delay the visibility of configuration or quota changes. Benchmark with the expected request mix and stream concurrency rather than sizing for model parameters. Because traffic and upstream credentials pass through the gateway, restrict admin access and define a log retention policy before production use.

### Hardware & Deployment Guide
Start with a release binary or a Docker image from `justsong/one-api` or `ghcr.io/songquanpeng/one-api`. The default port is `3000`; mount `/data` for SQLite persistence and set `--log-dir` if logs need a separate path. The supplied Compose example uses MySQL via `SQL_DSN`, Redis via `REDIS_CONN_STRING`, and a health check against `/api/status`. Before exposing the service, replace the initial administrator password and sample secrets, and terminate HTTPS at a reverse proxy configured for streaming requests.

Use shared MySQL and the same strong `SESSION_SECRET` on every node in the documented multi-node setup. Mark secondary nodes with `NODE_TYPE=slave` and tune `SYNC_FREQUENCY` if caching is enabled. PostgreSQL is listed as still being adapted, so verify it before treating it as a production substitute. Pin and test the release you deploy: v0.6.10 (2025-02-02) added Replicate chat models, OpenAI o1, and `gemini-2.0-flash-exp`; v0.6.9 added SiliconFlow and updated Ollama embeddings to accept multiple input texts.
```

## Key Capabilities
```text
- Relay architecture: A Go/Gin service and web console separate upstream channel credentials from client-facing tokens.
- Protocol adaptation: OpenAI-shaped requests are forwarded to compatible upstreams or translated by provider adapters, with streaming on supported routes.
- Channel routing: Model and group eligibility determine the available channels for load balancing; tokens created by administrators can explicitly select a channel.
- Quota accounting: Account and token limits are separate, and metered usage applies group and model ratios plus a completion-token multiplier.
- Persistence and caching: SQLite supports a single-instance setup; the Compose example uses MySQL and Redis, and `LOG_SQL_DSN` can separate log storage.
- Release coverage: v0.6.10 added Replicate chat models, OpenAI o1, and `gemini-2.0-flash-exp`; v0.6.9 updated Ollama embeddings for multiple input texts.
```

## Quick Start / Clone
```bash
# 使用 SQLite 的部署命令：
docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api
# 使用 MySQL 的部署命令，在上面的基础上添加 `-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"`，请自行修改数据库连接参数，不清楚如何修改请参见下面环境变量一节。
# 例如：
docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api
```
