Self-hosted Qwen Web protocol gateway with OpenAI, Anthropic, and Gemini compatible APIs.
GitHub · Docker Hub · Telegram · 中文说明
qwen2API converts Qwen Web capabilities into common API protocols and provides a local WebUI for account management, downstream API keys, runtime settings, model tests, image tests, and video tests.
Note
v1.0 was the legacy Python + FastAPI implementation. v2.0 is the current Go backend + React WebUI mainline and is the recommended version for Docker and local deployments.
| Area | Capability |
|---|---|
| OpenAI-compatible APIs | /v1/chat/completions, /v1/responses, /v1/models, /v1/files, /v1/images/generations, /v1/videos/generations |
| Anthropic-compatible APIs | /v1/messages, /anthropic/v1/messages, /v1/messages/count_tokens |
| Gemini-compatible APIs | /v1beta/models/{model}:generateContent, /v1beta/models/{model}:streamGenerateContent |
| WebUI | Accounts, API keys, runtime config, chat test, image test, video test |
| Account pool | Multi-account rotation, per-account concurrency, separate chat/image/video cooldown tracking |
| Operations | /healthz, /readyz, /keepalive, Docker healthcheck, multi-arch image publishing |
| Version | Stack | Status |
|---|---|---|
v1.0 |
Python + FastAPI/Uvicorn | Legacy version, kept only as historical context |
v2.0 |
Go backend + React WebUI | Current mainline |
For most deployments, use the Docker Hub image directly. Keep data and logs beside your compose file; Docker will mount them into the container so upgrades do not wipe your accounts, keys, or logs.
mkdir qwen2api
cd qwen2api
mkdir -p data logsCreate a small .env:
HOST_PORT=7860
HOST_DATA_DIR=./data
HOST_LOGS_DIR=./logs
ADMIN_KEY=replace-with-your-own-strong-random-keyCreate docker-compose.yml:
services:
qwen2api:
image: ${QWEN2API_IMAGE:-yujunzhixue/qwen2api:latest}
container_name: qwen2api
restart: unless-stopped
init: true
env_file:
- .env
ports:
- "${HOST_PORT:-7860}:${PORT:-7860}"
volumes:
- ${HOST_DATA_DIR:-./data}:/app/data
- ${HOST_LOGS_DIR:-./logs}:/app/logs
shm_size: "512m"
healthcheck:
test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:${PORT:-7860}/healthz || exit 1"]
interval: 30s
timeout: 10s
start_period: 120s
retries: 3You do not need to set paths for accounts.json, api_keys.json, or other internal files. The image already uses /app/data and /app/logs; the volume mapping above decides where those files live on your host.
Start it:
docker compose pull
docker compose up -d
docker compose logs -f qwen2apiOpen:
- WebUI:
http://127.0.0.1:7860 - Health check:
http://127.0.0.1:7860/healthz - Keepalive probe:
http://127.0.0.1:7860/keepalive
Use this path when you changed the source code and need to build your own image.
git clone https://github.com/YuJunZhiXue/qwen2API.git
cd qwen2API
cp .env.example .env
docker compose -f docker-compose.yml -f docker-compose.build.yml build
docker compose -f docker-compose.yml -f docker-compose.build.yml up -dflowchart LR
subgraph Clients["API Clients"]
OpenAI["OpenAI SDK / Chat Completions"]
Anthropic["Claude / Anthropic Messages"]
Gemini["Gemini-compatible clients"]
CLI["Claude Code / Codex / other CLI tools"]
end
subgraph App["qwen2API v2.0"]
WebUI["React WebUI"]
Router["Go HTTP Router"]
Adapter["Protocol Adapters"]
Tools["Tool-call / Context Pipeline"]
Pool["Qwen Account Pool"]
Store["JSON Stores / Data Files"]
end
subgraph Runtime["Runtime"]
Docker["Docker image"]
Data["./data volume"]
Logs["./logs volume"]
end
Qwen["Qwen Web Upstream"]
OpenAI --> Router
Anthropic --> Router
Gemini --> Router
CLI --> Router
WebUI --> Router
Router --> Adapter
Adapter --> Tools
Tools --> Pool
Pool --> Qwen
Pool --> Store
Store --> Data
Router --> Logs
Docker --> App
Do not commit real secrets. .env.example intentionally contains empty values and commented examples only.
| Variable | Description |
|---|---|
ADMIN_KEY |
WebUI and /api/admin/* management key. Set a strong private value. |
QWEN_API_KEY, QWEN_API_KEYS, QWEN_API_KEY_N |
Runtime-only downstream API keys injected from env. They are not saved to data/api_keys.json and cannot be deleted from WebUI. |
QWEN_ACCOUNT_N |
Runtime-only upstream Qwen account, format token;optional-email;optional-password. It is not saved to data/accounts.json. |
KEEPALIVE_URL, KEEPALIVE_INTERVAL |
Optional background keepalive task. Env values lock the same WebUI settings. |
TOOL_RECOVERY_MAX_ATTEMPTS |
Maximum automatic recovery attempts when an upstream response after a tool result fails to produce the next client tool call. Default 4, clamped to 1-8. |
HOST_DATA_DIR, HOST_LOGS_DIR |
Host paths mounted into Docker as /app/data and /app/logs. Defaults are ./data and ./logs. |
DATA_DIR, LOGS_DIR |
Local non-Docker path overrides. Leave empty to use the current project directory. |
- Go
1.26 - Node.js
20+ - npm
- Docker, only if you need container builds
go run start-all.gocd backend
go run .Verification:
cd backend
go test ./...
go build -trimpath -ldflags="-s -w" -o ..\bin\qwen2api-backend.exe .cd frontend
npm ci
npm run devProduction build:
cd frontend
npm run build- Keep the Go backend as the
v2.0runtime source of truth. - Keep Docker data paths container-internal as
/app/dataand/app/logs. - Control host paths through compose volume mappings instead of hard-coded workspace paths.
- Do not commit
data/,logs/,.env, real tokens, cookies, passwords, or downstream API keys. - Update README and
.env.examplewhen adding user-visible configuration.
- Report bugs through GitHub Issues.
- Submit feature requests through GitHub Issues.
- Open focused pull requests through GitHub Pull Requests.
- Include practical verification steps when possible.
go test ./...passes inbackend.npm run buildpasses infrontend.- Docker-related changes are reflected in
Dockerfile,docker-compose.yml, and README when needed. - No generated data, logs, local
.env, Qwen token, cookie, password, or downstream API key is included.
Thanks to everyone who helps improve qwen2API.
This project is released under the GPL-3.0 License.
- This project is provided as an open-source self-hosted gateway.
- Review your local laws, platform rules, and upstream account policies before deployment.
- Do not publish or share real account tokens, cookies, passwords, or downstream API keys.
- If you find a security issue, please avoid public secret disclosure and report it through a private channel first.
- 特别鸣谢: LinuxDo
If qwen2API helps you, consider giving the project a Star.
Made by YuJunZhiXue and contributors.