An OpenAI-compatible proxy server that routes requests from any OpenAI SDK client to Qwen models via chat.qwen.ai.
- Drop-in replacement for
api.openai.com - Streaming SSE support
- OpenAI tool calling compatibility
- Session persistence
- System prompt merging for Qwen compatibility
Qwen provides powerful models through chat.qwen.ai, but does not expose a fully OpenAI-compatible API.
This proxy allows existing OpenAI SDKs, coding agents, and developer tools to use Qwen models without modification.
- OpenAI-compatible API
- Streaming responses (SSE)
- Tool/function calling
- Conversation persistence
- Automatic system message merging
- Model aliases
- OpenCode support
- LangChain support
- Vision uploads
- Docker image
- Multi-account rotation
Works with:
- OpenCode
- Cline
- Continue.dev
- LangChain
- OpenAI SDK
- Roo Code
- OpenWebUI
- LibreChat
- AnythingLLM
- Cursor
Any OpenAI-compatible client should work.
- Node.js 18+
- npm or pnpm
npm install
npm run build
npm startServer runs at:
http://localhost:5000/v1npm run loginThis opens a browser window.
- Log in to
chat.qwen.ai - Press Enter in the terminal
- Tokens and cookies are extracted automatically
- Log in to
https://chat.qwen.ai - Open DevTools (
F12) - Go to Console tab
- Run:
localStorage.getItem("token")- Copy the token
- Open Network tab
- Copy the
Cookieheader from any request - Create
.env:
QWEN_AUTH_TOKEN=your_token_here
QWEN_COOKIE="your_cookie_here"curl http://localhost:5000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model":"qwen-coder",
"messages":[
{
"role":"user",
"content":"Write a Python web scraper"
}
]
}'import OpenAI from "openai"
const client = new OpenAI({
baseURL: "http://localhost:5000/v1",
apiKey: "dummy"
})
const response = await client.chat.completions.create({
model: "qwen-coder",
messages: [
{
role: "user",
content: "Hello"
}
]
})
console.log(response.choices[0].message)Add this to your opencode.json providers:
{
"model": "qwen-coder",
"messages": [
{
"role": "user",
"content": "Read config.json"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file",
"parameters": {
"type": "object",
"properties": {
"path": {
"type": "string"
}
},
"required": ["path"]
}
}
}
]
}| Alias | Upstream Model | Use Case |
|---|---|---|
qwen |
qwen-max-latest |
General purpose |
qwen-max |
qwen-max-latest |
General purpose |
qwen-think |
qwen3-235b-a22b |
Reasoning |
qwen-coder |
qwen3-coder-plus |
Coding |
qwen-flash |
qwen3-30b-a3b |
Fast responses |
qwen-vl |
qwen3-vl-plus |
Vision |
qwq |
qwq-32b |
Math/reasoning |
Direct upstream model IDs are also supported.
OpenAI-compatible chat completions endpoint.
Lists available models.
curl http://localhost:5000/v1/modelsDeletes stored chat sessions.
Refreshes Qwen authentication credentials.
| Variable | Default | Description |
|---|---|---|
QWEN_AUTH_TOKEN |
— | Qwen bearer token |
QWEN_COOKIE |
— | Browser cookie |
PORT |
5000 |
Server port |
HOST |
0.0.0.0 |
Bind address |
LOG_LEVEL |
info |
Logging level |
DATA_DIR |
./data |
Session storage |
RATE_LIMIT |
30 |
Requests/min/IP |
REQUEST_TIMEOUT |
120000 |
Upstream timeout |
Client (OpenAI SDK / OpenCode / LangChain)
↓
Qwen OpenAI Proxy
↓
chat.qwen.ai
↓
Qwen Modelssrc/
├── index.ts
├── auth/
├── client/
├── proxy/
├── streaming/
├── tools/
├── session/
└── utils/Qwen enforces a strict constraint:
- Maximum one system message
- System message must be first
The proxy automatically:
- merges multiple system prompts
- preserves tool messages
- preserves assistant messages
- fixes compatibility with OpenCode and similar agents
# Build
docker build -t qwenchat2api .
# Run
docker run -d \
-p 5000:5000 \
-e QWEN_AUTH_TOKEN=your_token \
-e QWEN_COOKIE="your_cookie" \
-v qwenchat2api-data:/app/data \
--name qwenchat2api \
qwenchat2apichat.qwen.aiis not an official public API- This project reverse-engineers the web interface
- Tokens expire periodically
- Rate limits are undocumented and account-dependent
- Some upstream model names may change
- Vision/image uploads
- Docker image
- WebSocket support
- Multi-account routing
- Better retry handling
- OAuth authentication flow
This project is unofficial and is not affiliated with Alibaba or Qwen.
Use responsibly and at your own risk.
MIT