大模型API接入教程

快速接入混元、GLM、Kimi等大模型能力

本教程涵盖Python、Node.js等主流语言的API接入方法,帮你快速构建AI应用。

1

接入前准备

📋 准备工作

第一步:注册腾讯云账号,完成实名认证。

第二步:开通大模型服务,获取SecretId和SecretKey。

第三步:选择适合你的编程语言和SDK。

第四步:阅读API文档,了解接口规范。

2

Python 接入教程

🐍 安装 SDK
pip install tencentcloud-sdk-python
💬

对话接口示例

from tencentcloud.common import credential
from tencentcloud.hunyuan.v20230901 import hunyuan_client

cred = credential.Credential(
    "你的SecretId",
    "你的SecretKey"
)

client = hunyuan_client.HunyuanClient(cred, "ap-beijing")

response = client.ChatCompletion({
    "Messages": [
        {"Role": "user", "Content": "你好"}
    ]
})

print(response.Choices[0].Message.Content)
🧠

流式输出示例

response = client.ChatCompletion({
    "Messages": [
        {"Role": "user", "Content": "写一首诗"}
    ],
    "Stream": True
})

for event in response:
    print(event.Choices[0].Delta.Content, end="")
3

Node.js 接入教程

📦 安装 SDK
npm install tencentcloud-sdk-nodejs
💬

对话接口示例

const tencentcloud = require("tencentcloud-sdk-nodejs");

const HunyuanClient = tencentcloud.hunyuan.v20230901.Client;

const client = new HunyuanClient({
    credential: {
        secretId: "你的SecretId",
        secretKey: "你的SecretKey"
    },
    region: "ap-beijing"
});

const response = await client.ChatCompletion({
    Messages: [{ Role: "user", Content: "你好" }]
});

console.log(response.Choices[0].Message.Content);
4

常用模型对比

模型 特点 适用场景 推荐指数
Tencent HY 2.0 代码生成强,长上下文 Coding Agent、文档自动化 ⭐⭐⭐⭐⭐
GLM-5 复杂系统工程 长程Agent任务、编程 ⭐⭐⭐⭐
Kimi-K2.5 多模态、思考模式 对话、视觉理解 ⭐⭐⭐⭐
MiniMax-M2.5 生产力场景优化 办公、复杂多步任务 ⭐⭐⭐⭐
DeepSeek-V4-Flash 高并发、低延迟 生产级应用、经济之选 ⭐⭐⭐

💡 还想查看更多模型的价格和参数对比?我们的 AI模型服务对比 页面汇总了腾讯云、智谱GLM、MiniMax、Kimi、DeepSeek等平台的详细价格和模型参数,一页看懂。

5

常见问题

是的,默认QPS限制为10次/秒。如需更高频率,可以在控制台申请提升配额。

1个Token约等于0.7个中文汉字或1个英文单词。输入和输出分别计费。

建议使用Token Plan套餐,比按量计费便宜50%-80%。同时可以缓存常用响应,减少重复调用。

立即开通大模型服务

新用户最高享100万免费Tokens

立即开通
🔥 限时优惠 · CodeBuddy 首月 ¥40 ¥7.9 省¥32.1
🔥 立即抢购
🎯 限时特惠 · 仅限本站访客

⏳ 别急着走!
首月特惠马上结束

已有 5,000+ 开发者通过本站购买

12 小时
00 分钟
00
¥40 ¥7.9 /首月
💰 省 ¥32.1 · 优惠仅限本站专属链接
🤖 全功能 Coding Plan 🔄 无限Token调用 📱 多工具支持 💬 中文优化
🔥 立即抢购 · 首月仅 ¥7.9
🔒 安全支付 ⭐ 开发者推荐 🛡️ 官方授权