跳转到内容
搜索文档

Baseten

最后更新 查看 MarkdownAgent 设置

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 模型名称。

兼容 OpenAI 的 chat completions API

Baseten 为受支持的模型提供兼容 OpenAI 的 chat completions API。

cURL

Example fetch requestbash
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?"
      }
    ]
  }'

使用 OpenAI SDK 与 JavaScript

JavaScriptjs
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);

OpenAI 兼容端点

你也可以通过 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

Example fetch requestbash
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
  }'

使用 JavaScript

JavaScriptjs
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);

这篇文档对您有帮助吗?