Baseten ↗ は、機械学習モデルを大規模に構築・デプロイするためのインフラを提供します。統一された chat completions API を通じて、さまざまな言語モデルにアクセスできます。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/basetenBaseten にリクエストを送るときは、次を用意してください。
- AI Gateway の Account ID。
- AI 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 スキーマを使って 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);