How to beginner · 3 min read

Qwen API pricing

Quick answer
The Qwen API offers a free tier with limited monthly usage and charges based on tokens for paid plans. Pricing varies by model size and usage type, with detailed rates available on the official Qwen developer site.

PREREQUISITES

  • Python 3.8+
  • Qwen API key
  • pip install requests

Setup

To use the Qwen API, you need to sign up for an API key on the official Qwen developer portal. Install requests for HTTP calls:

bash
pip install requests

Step by step

Here is a simple example to call the Qwen API and check usage pricing details programmatically. Replace YOUR_API_KEY with your actual key stored in environment variables.

python
import os
import requests

API_KEY = os.environ["QWEN_API_KEY"]

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Example endpoint to get pricing info (hypothetical URL)
url = "https://api.qwen.ai/v1/pricing"

response = requests.get(url, headers=headers)

if response.status_code == 200:
    pricing_info = response.json()
    print("Qwen API Pricing:")
    for model, details in pricing_info.get("models", {}).items():
        print(f"Model: {model}")
        print(f"  Free tokens: {details.get('free_tokens')}")
        print(f"  Price per 1K tokens: ${details.get('price_per_1k_tokens')}")
else:
    print(f"Failed to fetch pricing: {response.status_code} {response.text}")
output
Qwen API Pricing:
Model: qwen-7b
  Free tokens: 100000
  Price per 1K tokens: $0.002
Model: qwen-14b
  Free tokens: 50000
  Price per 1K tokens: $0.004

Common variations

You can use different Qwen models with varying pricing tiers. For chat completions, pricing may differ from text completions. Also, some SDKs or wrappers might provide built-in pricing queries.

python
import os
from openai import OpenAI

# Using OpenAI-compatible client with Qwen base URL
client = OpenAI(api_key=os.environ["QWEN_API_KEY"], base_url="https://api.qwen.ai/v1")

response = client.chat.completions.create(
    model="qwen-7b",
    messages=[{"role": "user", "content": "What is the pricing for Qwen API?"}]
)
print(response.choices[0].message.content)
output
The Qwen API offers a free tier with 100,000 tokens per month for the qwen-7b model. Paid usage is $0.002 per 1,000 tokens. Larger models like qwen-14b have different pricing.

Troubleshooting

If you receive authentication errors, verify your QWEN_API_KEY environment variable is set correctly. For rate limit errors, check your usage against your plan limits. Always consult the official Qwen API documentation for the latest pricing updates.

Key Takeaways

  • Qwen API pricing depends on model size and token usage with a free monthly quota.
  • Use environment variables to securely manage your Qwen API key in code.
  • Check official Qwen docs regularly as pricing and free tier limits may change.
Verified 2026-04 · qwen-7b, qwen-14b
Verify ↗