Skip to content

Qwen API Examples

This page provides examples of using the Agentsflare Qwen API to help you quickly integrate and use Tongyi Qianwen series models.

Basic Configuration

Before starting to use the API, please ensure you have obtained an API Key. If not, please refer to Create API Key.

Basic Information

  • API Base URL: https://api.agentsflare.com/v1/chat/completions
  • Authentication Method: Bearer Token
  • Content Type: application/json

Request Examples

bash
curl -X POST "https://api.agentsflare.com/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-plus",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Hello!"}
    ],
    "max_tokens": 100,
    "temperature": 0.7
  }'
python
from openai import OpenAI

url = "https://api.agentsflare.com/v1"

client = OpenAI(
    base_url=url,
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="qwen-plus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"},
    ],
    stream=False
)

print(response.choices[0].message.content)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.AGENTSFLARE_API_KEY, 
  baseURL: "https://api.agentsflare.com/v1"    
});

async function main() {
  try {
    const res = await client.chat.completions.create({
      model: "qwen-plus",
      messages: [{ role: "user", content: "Hello, how are you?" }],
      max_tokens: 100,
      temperature: 0.7
    });

    console.log(res.choices?.[0]?.message?.content);
  } catch (err) {
    console.error(err?.response?.data ?? err);
  }
}

main();

Response Example

json
{
  "id": "chatcmpl-xxx",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Hello! How can I help you today?",
        "role": "assistant"
      }
    }
  ],
  "created": 1705651092,
  "model": "qwen-plus",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 10,
    "prompt_tokens": 16,
    "total_tokens": 26
  }
}

Supported Models

The following models are available through this interface (sorted by recommendation):

  • qwen-plus
  • qwen3.6-plus
  • qwen3.7-max New

💡 Tip

The model field in the request example can be replaced with any model name above.

This documentation is licensed under CC BY-SA 4.0.