Name | qwen-webapi JSON |
Version |
0.1.2
JSON |
| download |
home_page | None |
Summary | OpenAI-compatible API proxy for chat.qwen.ai with Flask server and Python API |
upload_time | 2025-10-08 03:06:04 |
maintainer | None |
docs_url | None |
author | Starreeze |
requires_python | >=3.10 |
license | GPL-3.0-only |
keywords |
qwen
api
proxy
openai
chat
llm
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Qwen Web API Proxy
Qwen API Proxy exposes the upstream [chat.qwen.ai](https://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/completions` endpoint
- Python API `QwenApi` for synchronous completions
## Installation
Install dependencies:
```bash
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:
1. login to [chat.qwen.ai](https://chat.qwen.ai);
2. press F12 to open the browser's developer tools;
3. navigate to the `Console` tab;
4. input `localStorage.getItem("token")` and press Enter;
5. copy the token (without quotes) and paste it into the `token.txt` file or set the `QWEN_AUTH_TOKEN` environment variable.
## Usage
### Run the server
```bash
python -m qwen.server
```
The app binds to `0.0.0.0:<PORT>` and exposes the following endpoints:
- `GET /health` – health check
- `GET /v1/models` – list models
- `POST /v1/chat/completions` – OpenAI-compatible chat completions
- `DELETE /v1/chats/<chat_id>` – delete a stored chat session upstream
### Python API
```python
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 in `qwen/config.py`, including:
```python
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): Set `True` to 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 when `enable_thinking=True`.
## Notes
1. rate limit unknown - not recommended to use on main account
2. currently only supports single user message
3. streaming is not supported
## License
GPLv3 License
Raw data
{
"_id": null,
"home_page": null,
"name": "qwen-webapi",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "qwen, api, proxy, openai, chat, llm",
"author": "Starreeze",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/b3/24/391a02d191777b8b5cc31dc4421a824751a0494904d1f22dd344cd4b52a5/qwen_webapi-0.1.2.tar.gz",
"platform": null,
"description": "# Qwen Web API Proxy\n\nQwen API Proxy exposes the upstream [chat.qwen.ai](https://chat.qwen.ai) service through an OpenAI-compatible API. It provides a local Flask server and a Python API for issuing chat completions programmatically.\n\nFeatures:\n\n- OpenAI-compatible `v1/chat/completions` endpoint\n- Python API `QwenApi` for synchronous completions\n\n## Installation\n\nInstall dependencies:\n\n```bash\npip install flask flask-cors requests\n```\n\nThe service reads configuration from environment variables:\n\n| Variable | Description | Default |\n| ----------------- | -------------------------------------------- | ---------------------- |\n| `QWEN_AUTH_TOKEN` | Authorization token copied from chat.qwen.ai | _required_ |\n| `QWEN_BASE_URL` | Upstream API base URL | `https://chat.qwen.ai` |\n| `PORT` | Port for the Flask server | `5000` |\n| `QWEN_DEBUG` | Set to `1` to enable debug logging | `0` |\n\nFor 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:\n\n1. login to [chat.qwen.ai](https://chat.qwen.ai);\n2. press F12 to open the browser's developer tools;\n3. navigate to the `Console` tab;\n4. input `localStorage.getItem(\"token\")` and press Enter;\n5. copy the token (without quotes) and paste it into the `token.txt` file or set the `QWEN_AUTH_TOKEN` environment variable.\n\n## Usage\n\n### Run the server\n\n```bash\npython -m qwen.server\n```\n\nThe app binds to `0.0.0.0:<PORT>` and exposes the following endpoints:\n\n- `GET /health` \u2013 health check\n- `GET /v1/models` \u2013 list models\n- `POST /v1/chat/completions` \u2013 OpenAI-compatible chat completions\n- `DELETE /v1/chats/<chat_id>` \u2013 delete a stored chat session upstream\n\n### Python API\n\n```python\nfrom qwen import QwenApi\n\nmessages = [{\"role\": \"user\", \"content\": \"Hello, Qwen!\"}]\nclient = QwenApi(\"qwen-flash\")\nresponse: str = client(\n messages,\n enable_thinking=True,\n thinking_budget=2048,\n)\nprint(response)\n```\n\n`QwenApi` raises `ConfigurationError` when the token is missing and `QwenAPIError` for upstream request issues.\n\n#### Chat parameters\n\n- `messages` (list): List of messages in the format of [{\"role\": \"user\", \"content\": \"Hello, Qwen!\"}]. Or a single string containing the user query.\n- `model` (str): Model name. The name mapping is defined in `qwen/config.py`, including:\n ```python\n DEFAULT_MODEL_MAP: dict[str, str] = {\n \"qwen\": \"qwen3-max\",\n \"qwen-think\": \"qwen3-235b-a22b\", # 2507\n \"qwen-coder\": \"qwen3-coder-plus\",\n \"qwen-flash\": \"qwen-plus-2025-09-11\", # next-80b-a3b\n \"qwen-vl\": \"qwen3-vl-plus\", # Qwen3-VL-235B-A22B\n }\n ```\n- `enable_thinking` (bool): Set `True` to request autodocumented reasoning. Defaults to the upstream user preference when omitted. Not available on all models.\n- `thinking_budget` (int): Optional token budget for reasoning content. Only used when `enable_thinking=True`.\n\n## Notes\n\n1. rate limit unknown - not recommended to use on main account\n2. currently only supports single user message\n3. streaming is not supported\n\n## License\n\nGPLv3 License\n",
"bugtrack_url": null,
"license": "GPL-3.0-only",
"summary": "OpenAI-compatible API proxy for chat.qwen.ai with Flask server and Python API",
"version": "0.1.2",
"project_urls": null,
"split_keywords": [
"qwen",
" api",
" proxy",
" openai",
" chat",
" llm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fe5973578b649f3632b2eb663486179f5f9f02c6a54271399dbcda1bd0729bb2",
"md5": "13339fd57bb04e2d95a8f2da8f7b0f50",
"sha256": "49466a865c1da80f2957a3247923ebdc46b218f1eb4ef46b01df3a4d76930500"
},
"downloads": -1,
"filename": "qwen_webapi-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "13339fd57bb04e2d95a8f2da8f7b0f50",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 18780,
"upload_time": "2025-10-08T03:06:03",
"upload_time_iso_8601": "2025-10-08T03:06:03.258614Z",
"url": "https://files.pythonhosted.org/packages/fe/59/73578b649f3632b2eb663486179f5f9f02c6a54271399dbcda1bd0729bb2/qwen_webapi-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b324391a02d191777b8b5cc31dc4421a824751a0494904d1f22dd344cd4b52a5",
"md5": "a3d1efdcbe545db5f31700b441ffbf8f",
"sha256": "2dc2a032eb202cd82401d538a24df12713cdb6659f4cbfb52c0c559249fe577a"
},
"downloads": -1,
"filename": "qwen_webapi-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "a3d1efdcbe545db5f31700b441ffbf8f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 18273,
"upload_time": "2025-10-08T03:06:04",
"upload_time_iso_8601": "2025-10-08T03:06:04.841418Z",
"url": "https://files.pythonhosted.org/packages/b3/24/391a02d191777b8b5cc31dc4421a824751a0494904d1f22dd344cd4b52a5/qwen_webapi-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-08 03:06:04",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "qwen-webapi"
}