A Python API wrapper for interacting with Qwen chat service.
To use this API, you need to obtain your authentication token from the Qwen chat platform:
-
Navigate to chat.qwen.ai and log in to your account
-
Open Developer Tools by pressing F12
-
Find the "Applications" tab at the top of the developer tools panel
-
Locate "Local Storage" in the left sidebar and expand the dropdown menu
-
Select chat.qwen.ai from the list
-
Find the "token" value in the right panel and copy the entire value - this is your
QWEN_AUTH_TOKEN
from qwen_api import QwenAPI
# Initialize the API client with your token
client = QwenAPI(auth_token="YOUR_QWEN_AUTH_TOKEN")
# Send a message
response = client.send_message("Hello, how can you help me today?")
print(response)
# Create a new conversation
conversation = client.create_conversation()
# Continue an existing conversation
response = client.send_message(
"What's the weather like?",
conversation_id=conversation.id
)pip install -r requirements.txtFor security, it's recommended to store your token as an environment variable:
export QWEN_AUTH_TOKEN="your_token_here"Then in your code:
import os
from qwen_api import QwenAPI
client = QwenAPI(auth_token=os.getenv("QWEN_AUTH_TOKEN"))- Python 3.7+
- Required dependencies listed in
requirements.txt
MIT License