Rfym21/Qwen2API
让 QwenLM 物尽其用
Qwen‑Proxy (Qwen2API)
What it is – A self‑hosted proxy that turns Alibaba’s Qwen chat services (https://chat.qwen.ai and the Qwen CLI) into an OpenAI‑compatible (and partially Anthropic‑compatible) HTTP API. It lets any client that talks to the OpenAI API – e.g. ChatGPT‑Next‑Web, LobeChat, LangChain, Claude‑Code, etc. – use Qwen models without code changes.
Key capabilities
- OpenAI API surface –
/v1/models,/v1/chat/completions,/v1/images/*,/v1/videos, plus the Anthropic‑style/v1/messagesendpoint. - Function calling / tools – full support for OpenAI
toolsand Anthropictool_use, including streaming incrementalargumentsand stricttool_choice=requiredhandling. - Multi‑account rotation – configure several Qwen accounts; the proxy will round‑robin them (each can have its own outbound proxy) to avoid IP‑based bans.
- Per‑account outbound proxy – HTTP, HTTPS, SOCKS5/SOCKS5H proxies can be attached to individual accounts.
- 256 K context CLI endpoint – the
/cliroute exposes Qwen CLI models with very large context windows and tool support. - Multimodal – image/video generation, image editing, and video understanding are exposed through the OpenAI‑style endpoints.
- Web UI – a built‑in management dashboard for adding accounts, setting per‑account proxies, monitoring usage, and editing model mappings.
- Persistence options – in‑memory (default), JSON file, or Redis for storing account data, settings, and logs.
- Docker & binary distribution – official Docker image, Docker‑Compose files, and a single‑file Bun binary that bundles the runtime, backend, frontend, and tokeniser.
How to get started
- Docker (quickest)
docker run -d \ -p 3000:3000 \ -e API_KEY=sk-admin123,sk-user456 \ -e ACCOUNTS=user1@mail.com:pass1|http://proxy:8080 \ -e DATA_SAVE_MODE=none \ -v $(pwd)/caches:/app/caches \ --name qwen2api rfym21/qwen2api:latest - Docker‑Compose – pull the provided
docker-compose.ymland rundocker compose up -d. - Local source – clone the repo, install with Bun (
bun install --frozen-lockfile), copy.env.exampleto.env, edit the variables, thenbun run start. - Standalone binary – run
bun run build:binaryto produce a single executable (qwen2api‑windows‑x64.exe,qwen2api‑linux‑x64, etc.) that can be started directly after placing a.envfile next to it.
Configuration highlights
| Variable | Purpose |
|---|---|
API_KEY |
Comma‑separated list of API keys. The first key is an admin key (access to the UI); the rest are normal keys for API calls. |
ACCOUNTS |
List of Qwen accounts in email:password form, optionally followed by ` |
PROXY_URL |
Global outbound proxy used when an account does not define its own. |
DATA_SAVE_MODE |
none (default), file, or redis – where account data and settings are persisted. |
CACHE_MODE |
default (in‑memory) or file – where image cache files are stored. |
QWEN_CHAT_PROXY_URL / QWEN_CLI_PROXY_URL |
Override the upstream Qwen endpoints if you run your own mirrors. |
AGENT_TURN_MAX_ATTEMPTS |
Max retries for a tool‑calling round before returning an error. |
MODELS_CACHE_TTL |
Seconds to cache the upstream model list (0 = never expire). |
Typical usage (OpenAI‑compatible client)
curl -H "Authorization: Bearer sk-admin123" \
-H "Content-Type: application/json" \
-d '{"model":"Qwen3.6-Plus","messages":[{"role":"user","content":"你好"}],"stream":false}' \
http://localhost:3000/v1/chat/completions
The response follows the OpenAI schema (id, object, choices, usage).
Why you might need it
- Access Qwen’s powerful multimodal and 256 K‑context models while reusing existing OpenAI‑based tooling.
- Share a single Qwen subscription among multiple users or services without exposing raw credentials.
- Bypass IP‑based rate limits by rotating accounts and per‑account proxies.
- Run locally or in a container, keeping all traffic inside a trusted network.
Limitations / notes
- The proxy does not provide the original Qwen SDK; it merely forwards requests and adapts responses.
- Some Anthropic fields are only partially supported – the bridge aims for best‑effort compatibility, not a full Anthropic implementation.
- Persistent storage (file or Redis) is optional; without it, account tokens are kept only in memory and lost on restart.
- The service assumes a trusted environment – proxy URLs are returned verbatim in API responses.
TL;DR – Qwen‑Proxy is a Bun‑based server that lets any OpenAI‑compatible client talk to Alibaba’s Qwen models, with support for function calling, multimodal generation, account rotation, and a web UI. Deploy via Docker, Docker‑Compose, or a single binary, configure your Qwen accounts and API keys, and start using the familiar OpenAI endpoints.
Related
- Project
- Project
- Project
- Project
- Project