跳到主要内容

通过 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 访问大模型服务,只需要替换 baseURLapiKey 即可,以下是一个示例:

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()