Alibaba Cloud Bailian Coding Plan API Tutorial: How Programmers Integrate Tongyi Qianwen Large Model
Alibaba Cloud Bailian Coding Plan API Tutorial: How Programmers Integrate Tongyi Qianwen Large Model

Article Author: Programmer Wan Feng | AI Programming Evangelist | Focused on AI Tool Reviews and Teaching

400k+ followers across platforms, 6 years Python development experience, author of open source project python-office

💡 Technology is not high-cold, AI is very easy to use 👉 Click to integrate Tongyi Qianwen

Hello everyone, this is programmer Wan Feng.

Today brings you Alibaba Cloud Bailian API integration tutorial, hand-holding you through integrating Tongyi Qianwen into your own projects.

1. Preparation

1. Activate Service

First make sure you've activated Alibaba Cloud Bailian Coding Plan:
👉 Click to activate

2. Get API-KEY

  1. Enter Alibaba Cloud Bailian console
  2. Find "API-KEY"
  3. Create API-KEY, save it

2. API Call Examples

Python Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests

# Configuration
api_key = "Your API-KEY"

# Call Tongyi Qianwen API
def call_qwen(prompt):
url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"

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

data = {
"model": "qwen-turbo",
"messages": [
{"role": "user", "content": prompt}
]
}

response = requests.post(url, json=data, headers=headers)
return response.json()

# Usage
result = call_qwen("Help me write Python quicksort")
print(result)

JavaScript Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Node.js calls Tongyi Qianwen
const axios = require('axios');

async function callQwen(prompt) {
const response = await axios.post(
'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions',
{
model: 'qwen-turbo',
messages: [
{ role: 'user', content: prompt }
]
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer Your API-KEY'
}
}
);
return response.data;
}

// Usage
const result = await callQwen('Help me write JS debounce function');
console.log(result);

3. Usage in E-commerce Projects


🎓 AI Programming Course

Want to learn AI programming systematically? Check out CoderWanFeng's AI Programming Course!


🎓 AI 编程实战课程

程序员晚枫专注AI编程培训,通过 《30讲 · AI编程训练营》,让小白也能用AI做出实际项目。帮你从零上手!