ブログ
Tutorials3 分で読了

Qwen API Complete Guide: Max, Plus & Turbo Models

Introduction

Qwen is Alibaba's family of AI models offering strong multilingual capabilities, vision support, and competitive pricing. Through AI API Hub, you can access all Qwen models via the OpenAI-compatible API format.

Available Models

| Model | Input Price | Output Price | Context | Best For | |---|---|---|---|---| | Qwen-Max | $0.50/1M | $2.00/1M | 128K | Complex tasks, reasoning | | Qwen-Plus | $0.20/1M | $0.80/1M | 128K | Balanced performance | | Qwen-Turbo | $0.10/1M | $0.40/1M | 128K | Speed, cost-sensitive | | Qwen-VL-Max | $0.50/1M | $2.00/1M | 128K | Vision, multimodal |

Setup

import openai

client = openai.OpenAI(
    api_key="your-api-key",
    base_url="https://api.apiyihe.org/v1"
)

Basic Qwen-Max Call

response = client.chat.completions.create(
    model="qwen-max",
    messages=[
        {"role": "system", "content": "You are a multilingual assistant."},
        {"role": "user", "content": "Explain AI in 中文, English, and 日本語"}
    ],
    max_tokens=2000
)

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

Multilingual Support

Qwen excels at tasks requiring multiple languages:

languages = [
    ("Chinese", "用中文解释机器学习"),
    ("English", "Explain machine learning in English"),
    ("Japanese", "機械学習を日本語で説明してください"),
    ("Korean", "머신러닝을 한국어로 설명해주세요"),
    ("Arabic", "شرح التعلم الآلي باللغة العربية")
]

for lang, prompt in languages:
    response = client.chat.completions.create(
        model="qwen-max",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=500
    )
    print(f"\n=== {lang} ===\n{response.choices[0].message.content[:200]}")

Streaming

stream = client.chat.completions.create(
    model="qwen-max",
    messages=[{"role": "user", "content": "Write a Python tutorial"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Function Calling

import json

def translate(text, target_lang):
    # Simulated translation service
    return {"translated": f"[{target_lang}] {text}"}

functions = [{
    "name": "translate",
    "description": "Translate text to target language",
    "parameters": {
        "type": "object",
        "properties": {
            "text": {"type": "string"},
            "target_lang": {"type": "string"}
        },
        "required": ["text", "target_lang"]
    }
}]

response = client.chat.completions.create(
    model="qwen-max",
    messages=[{"role": "user", "content": "Translate 'Hello world' to Japanese"}],
    functions=functions,
    function_call="auto"
)

msg = response.choices[0].message
if msg.function_call:
    args = json.loads(msg.function_call.arguments)
    result = translate(**args)
    print(result)

Node.js Example

import OpenAI from "openai";
const client = new OpenAI({
  apiKey: "your-api-key",
  baseURL: "https://api.apiyihe.org/v1",
});
const r = await client.chat.completions.create({
  model: "qwen-max",
  messages: [{ role: "user", content: "你好!请介绍一下Qwen模型" }],
});
console.log(r.choices[0].message.content);

When to Use Each Model

| Use Case | Recommended Qwen Model | |---|---| | Enterprise applications | Qwen-Max | | Consumer chatbots | Qwen-Plus | | Real-time translation | Qwen-Turbo (fast + cheap) | | Image understanding | Qwen-VL-Max | | Chinese content | Qwen-Max (native quality) | | Budget projects | Qwen-Turbo ($0.10/1M input) |

FAQ

Q: Is Qwen good for Chinese content? A: Yes, Qwen is developed by Alibaba and excels at Chinese language processing, often better than GPT-4o for Chinese tasks.

Q: Can Qwen handle code generation? A: Yes, Qwen-Max and Qwen-Plus support code generation for Python, JavaScript, Java, and more.

Q: How does Qwen compare to DeepSeek? A: DeepSeek is cheaper for coding. Qwen is better for multilingual and Chinese content.

Q: What's the recommended model for startups? A: Qwen-Turbo at $0.10/1M input is the most affordable option for early-stage projects.

Get Your API Key Now

Start building with 50+ AI models through one unified gateway.

アカウント作成
APIキーを取得