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

💡 Want to systematically understand Coding Plans from various vendors? 👉 Click to view Coding Plan comparison summary

Hello everyone, this is programmer Wan Feng.

Today brings you a practical tutorial on Tencent Cloud Coding Plan, hand-holding you through Hunyuan large model API integration.

1. Preparation

Things You Need

  1. A Tencent Cloud account
  2. Real-name authentication (required for domestic services)
  3. Python environment (3.8+)

2. Get API Key

Step 1: Visit Official Website

👉 Click to view Tencent Cloud Coding Plan details

Find Tencent Cloud entrance and go to Hunyuan large model page.

Step 2: Activate Service

  1. Log in to Tencent Cloud console
  2. Search "Hunyuan Large Model"
  3. Activate service
  4. Get SecretId and SecretKey

Step 3: Install SDK

1
pip install tencentcloud-sdk-hunyuan

3. Code Calling Practice

Basic Call

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from tencentcloud.common import credential
from tencentcloud.hunyuan.v20230901 import hunyuan_client

# Initialize authentication
cred = credential.Credential(
"SecretId",
"SecretKey"
)

# Initialize client
client = hunyuan_client.HunyuanClient(cred, "ap-guangzhou")

# Call Hunyuan
response = client.ChatCompletions({
"Model": "hunyuan-turbo",
"Messages": [
{"Role": "user", "Content": "Help me write a Python quicksort"}
]
})

print(response)

Code Completion Example

1
2
3
4
5
6
7
8
9
10
11
12
def code_completion(prompt):
response = client.ChatCompletions({
"Model": "hunyuan-turbo",
"Messages": [
{"Role": "system", "Content": "You are a Python code assistant"},
{"Role": "user", "Content": f"Complete the following code:\n{prompt}"}
]
})
return response["Choices"][0]["Message"]["Content"]

result = code_completion("def quick_sort(arr):")
print(result)

4. WeChat Ecosystem Integration

Mini Program AI Assistant

Tencent Cloud's AI services can be easily integrated into mini programs:

1
2
3
4
5
6
7
8
9
10
11
// Call Hunyuan API
wx.cloud.callContainer({
config: {
env: 'your-env-id'
},
path: '/hunyuan/chat',
method: 'POST',
data: {
messages: [{role: 'user', content: 'Help me write a mini program'}]
}
})

5. FAQ

Q1: What versions of Hunyuan models are available?

VersionDescription
hunyuan-turboFast speed, good results, recommended
hunyuan-proHigh intelligence, suitable for complex tasks
hunyuan-standardStandard version

Q2: Is there free quota?

New users have free trial quota, check official website for details.

Q3: Is the response speed fast?

Domestic access, response speed is usually within 1-3 seconds.



📢 More Coding Plan comparisons: 👉 Click to view all vendors' Coding Plans


Author: Programmer Wan Feng, same name across all platforms, focused on AI tool reviews and Python office automation teaching.

🎓 AI Programming Course

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