通过 API 调用
前往 云开发平台/环境配置/API Key 配置页面 即可新建 API Key。
获取到 API Key 后,即可进行 HTTP API 调用,只需要在 HTTP 请求中附带 Authorization: Bearer <您的 API Key>
请求头。
可用的 HTTP API 包括:
大模型调用
cURL 示例
以下是一个使用 cURL 调用大模型 HTTP API 的示例:
curl -X POST 'https://your-env-id.api.tcloudbasegateway.com/v1/ai/deepseek/v1/chat/completions' \
-H 'Authorization: Bearer <您的 API Key>' \
-H 'Content-Type: application/json' \
-H 'Accept: text/event-stream' \
-d '{
"model": "deepseek-r1",
"messages": [
{
"role": "user",
"content": "介绍一下你自己"
}
],
"stream": true
}'
OpenAI SDK 示例
获取到 API Key 后,也可以使用 OpenAI SDK 访问大模型服务,只需要替换 baseURL
及 apiKey
即可,以下是一个示例:
const OpenAI = require("openai");
const client = new OpenAI({
apiKey: "您的 API Key",
baseURL: "https://your-env-id.api.tcloudbasegateway.com/v1/ai/deepseek/v1",
});
async function main() {
const completion = await client.chat.completions.create({
model: "deepseek-r1",
messages: [{ role: "user", content: "你好" }],
temperature: 0.3,
stream: true,
});
for await (const chunk of completion) {
console.log(chunk);
}
}
main();
AI Agent 调用
cURL 示例
以下是一个使用 cURL 调用 AI Agent HTTP API 的示例:
curl 'https://<your-envId>.api.tcloudbasegateway.com/v1/aibot/bots/<your-botId>/send-message' \
-H 'Authorization: Bearer <您的 API Key>' \
-H 'Accept: text/event-stream' \
-H 'Content-Type: application/json' \
--data-raw '{"msg":"hi"}'
知识库调用
cURL 示例
以下是一个使用 cURL 调用 知识库 HTTP API 的示例:
curl 'https://<your-envId>.api.tcloudbasegateway.com/v1/knowlege/send-message' \
-H 'Authorization: Bearer <您的 API Key>' \
-H 'Accept: text/event-stream' \
-H 'Content-Type: application/json' \
-d '{
"collectionView": "ykfty_6fWO",
"search": {
"content": "云开发 AI+ 最新有哪些新功能?",
"limit": "5"
}
}'