
### **Python调用示例：**
```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"), # 如果您没有配置环境变量，请在此处用您的API Key进行替换
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
    model="qwen3-coder-plus",
    messages=[
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        {'role': 'user', 'content': '请编写一个Python函数 find_prime_numbers，该函数接受一个整数 n 作为参数，并返回一个包含所有小于 n 的质数（素数）的列表。质数是指仅能被1和其自身整除的正整数，如2, 3, 5, 7等。不要输出非代码的内容。'}],
    )
print("="*20+"回复内容"+"="*20)
print(completion.choices[0].message.content)
print("="*20+"Token消耗"+"="*20)
print(completion.usage)
```
**返回结果示例：**
````plaintext
====================回复内容====================
```python
def find_prime_numbers(n):
    if n <= 2:
        return []
    
    primes = []
    
    for num in range(2, n):
        is_prime = True
        for i in range(2, int(num ** 0.5) + 1):
            if num % i == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(num)
    
    return primes
```
====================Token消耗====================
CompletionUsage(completion_tokens=95, prompt_tokens=91, total_tokens=186, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=0))
````



curl调用示例：
```curl
curl -X POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3-coder-plus",
    "messages": [
        {
            "role": "system",
            "content": "You are a helpful assistant."
        },
        {
            "role": "user", 
            "content": "请编写一个Python函数 find_prime_numbers，该函数接受一个整数 n 作为参数，并返回一个包含所有小于 n 的质数（素数）的列表。质数是指仅能被1和其自身整除的正整数，如2, 3, 5, 7等。不要输出非代码的内容。"
        }
    ]
}'
```


返回结果示例：
```json
{
    "choices": [
        {
            "message": {
                "content": "```python\ndef find_prime_numbers(n):\n    if n <= 2:\n        return []\n    \n    primes = []\n    \n    for num in range(2, n):\n        is_prime = True\n        for i in range(2, int(num ** 0.5) + 1):\n            if num % i == 0:\n                is_prime = False\n                break\n        if is_prime:\n            primes.append(num)\n    \n    return primes\n```",
                "role": "assistant"
            },
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null
        }
    ],
    "object": "chat.completion",
    "usage": {
        "prompt_tokens": 91,
        "completion_tokens": 95,
        "total_tokens": 186,
        "prompt_tokens_details": {
            "cached_tokens": 0
        }
    },
    "created": 1753192010,
    "system_fingerprint": null,
    "model": "qwen3-coder-plus",
    "id": "chatcmpl-798c99c2-7410-9cc4-8385-6dfd757757fa"
}
```






























