Baseten ↗ 提供用于大规模构建和部署机器学习模型的基础设施。Baseten 通过统一的 chat completions API 提供对多种语言模型的访问。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten向 Baseten 发送请求时,请确保具备以下条件:
- 你的 AI Gateway Account ID。
- 你的 AI Gateway gateway 名称。
- 有效的 Baseten API 令牌。
- 要使用的 Baseten 模型名称。
Baseten 为受支持的模型提供兼容 OpenAI 的 chat completions API。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten/v1/chat/completions \
--header 'Authorization: Bearer {baseten_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "openai/gpt-oss-120b",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'import OpenAI from "openai";
const apiKey = "{baseten_api_token}";
const accountId = "{account_id}";
const gatewayId = "{gateway_id}";
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/baseten`;
const openai = new OpenAI({
apiKey,
baseURL,
});
const model = "openai/gpt-oss-120b";
const messages = [{ role: "user", content: "What is Cloudflare?" }];
const chatCompletion = await openai.chat.completions.create({
model,
messages,
});
console.log(chatCompletion);你也可以通过 REST API 使用 OpenAI API schema 访问 Baseten 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "baseten/{model}"
}对于不使用兼容 OpenAI API 的模型,你可以通过其特定的模型端点进行访问。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten/model/{model_id} \
--header 'Authorization: Bearer {baseten_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "What is Cloudflare?",
"max_tokens": 100
}'const accountId = "{account_id}";
const gatewayId = "{gateway_id}";
const basetenApiToken = "{baseten_api_token}";
const modelId = "{model_id}";
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/baseten`;
const response = await fetch(`${baseURL}/model/${modelId}`, {
method: "POST",
headers: {
"Authorization": `Bearer ${basetenApiToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "What is Cloudflare?",
max_tokens: 100,
}),
});
const result = await response.json();
console.log(result);