Qwen Web API Proxy
Qwen API Proxy exposes the upstream chat.qwen.ai service through an OpenAI-compatible API. It provides a local Flask server and a Python API for issuing chat completions programmatically.
Features:
- OpenAI-compatible
v1/chat/completionsendpoint - Python API
QwenApifor synchronous completions
Installation
Install dependencies:
pip install flask flask-cors requests
The service reads configuration from environment variables:
| Variable | Description | Default |
|---|---|---|
QWEN_AUTH_TOKEN |
Authorization token copied from chat.qwen.ai | required |
QWEN_BASE_URL |
Upstream API base URL | https://chat.qwen.ai |
PORT |
Port for the Flask server | 5000 |
QWEN_DEBUG |
Set to 1 to enable debug logging |
0 |
For authentication, you can either set the QWEN_AUTH_TOKEN environment variable or create a token.txt file in the current working directory with the token. To get the token, follow the steps:
- login to chat.qwen.ai;
- press F12 to open the browser's developer tools;
- navigate to the
Consoletab; - input
localStorage.getItem("token")and press Enter; - copy the token (without quotes) and paste it into the
token.txtfile or set theQWEN_AUTH_TOKENenvironment variable.
Usage
Run the server
python -m qwen.server
The app binds to 0.0.0.0:<PORT> and exposes the following endpoints:
GET /health– health checkGET /v1/models– list modelsPOST /v1/chat/completions– OpenAI-compatible chat completionsDELETE /v1/chats/<chat_id>– delete a stored chat session upstream
Python API
from qwen import QwenApi
messages = [{"role": "user", "content": "Hello, Qwen!"}]
client = QwenApi("qwen-flash")
response: str = client(
messages,
enable_thinking=True,
thinking_budget=2048,
)
print(response)
QwenApi raises ConfigurationError when the token is missing and QwenAPIError for upstream request issues.
Chat parameters
messages(list): List of messages in the format of [{"role": "user", "content": "Hello, Qwen!"}]. Or a single string containing the user query.model(str): Model name. The name mapping is defined inqwen/config.py, including:DEFAULT_MODEL_MAP: dict[str, str] = { "qwen": "qwen3-max", "qwen-think": "qwen3-235b-a22b", # 2507 "qwen-coder": "qwen3-coder-plus", "qwen-flash": "qwen-plus-2025-09-11", # next-80b-a3b "qwen-vl": "qwen3-vl-plus", # Qwen3-VL-235B-A22B }
enable_thinking(bool): SetTrueto request autodocumented reasoning. Defaults to the upstream user preference when omitted. Not available on all models.thinking_budget(int): Optional token budget for reasoning content. Only used whenenable_thinking=True.
Notes
- rate limit unknown - not recommended to use on main account
- currently only supports single user message
- streaming is not supported
License
GPLv3 License
Metadata
Release files for qwen-webapi 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qwen_webapi-0.1.2.tar.gz | 18.3 kB | Without provenance | Details for qwen_webapi-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qwen_webapi-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for qwen_webapi-0.1.2-py3-none-any.whl |
Total release size: 37.1 kB
Release files / qwen_webapi-0.1.2.tar.gz
| Download URL | qwen_webapi-0.1.2.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2dc2a032eb202cd82401d538a24df12713cdb6659f4cbfb52c0c559249fe577a
|
|
BLAKE2b-256 checksum How to use checksums |
b324391a02d191777b8b5cc31dc4421a824751a0494904d1f22dd344cd4b52a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.17
|
Release files / qwen_webapi-0.1.2-py3-none-any.whl
| Download URL | qwen_webapi-0.1.2-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49466a865c1da80f2957a3247923ebdc46b218f1eb4ef46b01df3a4d76930500
|
|
BLAKE2b-256 checksum How to use checksums |
fe5973578b649f3632b2eb663486179f5f9f02c6a54271399dbcda1bd0729bb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.17
|
Security for qwen-webapi 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.