Try Chat Free Docs Pricing AI Analysis Repo Insights Free Tools About Blog
Sign in Get started free
< Back to blog
Tutorial Velona Team ·9 September 2026 ·3 min read

How to Use Qwen API in Python: Complete Developer Guide

You can call Alibaba's Qwen models from Python with the standard OpenAI SDK. On Velona, Qwen3 Coder (qwen/qwen3-coder) costs ₹31.08 per 1M input tokens and Qwen3 Max (qwen/qwen3-max) costs ₹80.82, both with a 262K-token context window. You pay in rupees with UPI from ₹10, no international card needed.

Which Qwen model should you use?

Prices as of 4 October 2026. They follow the live exchange rate, so check each model page for today's figure.

ModelModel IDInput ₹ / 1MOutput ₹ / 1MBest for
Qwen3 Coderqwen/qwen3-coder₹31.08₹103.61Writing, fixing and explaining code, coding agents
Qwen3 Maxqwen/qwen3-max₹80.82₹404.08General reasoning, multilingual tasks, writing

For coding, start with Qwen3 Coder. For general chat and reasoning, Qwen3 Max is Qwen's flagship generalist. Browse the full list in the model catalogue.

Set up the project

pip install openai python-dotenv

Put your Velona API key in a .env file and add that file to .gitignore:

VELONA_API_KEY=your_key_here

No key yet? The 5-minute setup guide walks you through it, starting with ₹10 via UPI.

Your first Qwen request

import os
from dotenv import load_dotenv
from openai import OpenAI

load_dotenv()

client = OpenAI(
    api_key=os.environ["VELONA_API_KEY"],
    base_url="https://velona.in/v1",
)

response = client.chat.completions.create(
    model="qwen/qwen3-coder",
    messages=[
        {"role": "system", "content": "You are a senior Python developer. Be concise."},
        {"role": "user", "content": "Write a function that checks if a number is prime, with type hints."},
    ],
    max_tokens=500,
)

print(response.choices[0].message.content)
print(response.usage)

Explain or review existing code

code = open("app.py").read()

response = client.chat.completions.create(
    model="qwen/qwen3-coder",
    messages=[
        {"role": "user", "content": f"Review this code. List bugs first, then improvements:\n\n{code}"},
    ],
)

print(response.choices[0].message.content)

With a 262K-token context window, Qwen3 Coder can read large files, but sending only the relevant parts keeps requests fast and cheap.

Use Qwen3 Max for reasoning and multilingual work

response = client.chat.completions.create(
    model="qwen/qwen3-max",
    messages=[
        {"role": "user", "content": "Explain compound interest in simple Hindi with one example in rupees."},
    ],
    max_tokens=400,
)

print(response.choices[0].message.content)

A reusable helper with error handling

import openai

def ask_qwen(prompt, model="qwen/qwen3-coder", max_tokens=600):
    try:
        response = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": prompt}],
            max_tokens=max_tokens,
        )
        return response.choices[0].message.content
    except openai.AuthenticationError:
        return "Check your API key."
    except openai.APIStatusError as e:
        return f"API error {e.status_code}: {e.message}"

print(ask_qwen("Convert this to a list comprehension: result = []\nfor x in range(10):\n    result.append(x * x)"))

What Qwen costs per request

RequestTokens (in / out)Qwen3 CoderQwen3 Max
Generate a function500 / 500about ₹0.07about ₹0.24
Review a 300-line file5,000 / 1,000about ₹0.26about ₹0.81
One coding agent step30,000 / 1,000about ₹1.04about ₹2.83

Looking for something even cheaper for coding? DeepSeek V4 Flash costs ₹2.90 per 1M input tokens. Our guide to the cheapest models for coding agents compares 13 models on real rupee costs.

Use Qwen3 Coder in a coding agent

Tools like Cline, OpenCode, Roo Code and Zed accept any OpenAI-compatible provider. Set the base URL to https://velona.in/v1, paste your Velona key, and enter qwen/qwen3-coder as the model. Our coding agents setup guide has the exact settings.

Common problems

Frequently asked questions

How much does the Qwen API cost in India?

On Velona today, Qwen3 Coder costs ₹31.08 per 1M input tokens and ₹103.61 per 1M output tokens. Qwen3 Max costs ₹80.82 and ₹404.08.

Can I pay for Qwen with UPI?

Yes. Top up your Velona wallet with UPI, RuPay, a domestic card or net banking from ₹10.

Is Qwen3 Coder good for coding?

It is Alibaba's coding specialist, built for strong agentic coding, and it is priced in the budget-to-mid range. Test it on your own code against DeepSeek V4 Flash and V4 Pro to see which suits your work.

Create your Velona account and try Qwen in the next five minutes.