Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

Baseten

最終更新 Markdown で表示Agent セットアップ

Baseten は、機械学習モデルを大規模に構築・デプロイするためのインフラを提供します。統一された chat completions API を通じて、さまざまな言語モデルにアクセスできます。

エンドポイント

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/baseten

前提条件

Baseten にリクエストを送るときは、次を用意してください。

  • AI Gateway の Account ID。
  • AI Gateway のゲートウェイ名。
  • 有効な Baseten API トークン。
  • 使う Baseten モデルの名前。

OpenAI 互換の chat completions API

Baseten は、対応モデル向けに OpenAI 互換の chat completions API を提供します。

cURL

fetch リクエストの例bash
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?"
      }
    ]
  }'

JavaScript で OpenAI SDK を使う

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 スキーマを使って Baseten モデルにもアクセスできます。リクエストの送信先は次のとおりです。

https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions

次を指定します。


{
"model": "baseten/{model}"
}

モデル固有のエンドポイント

OpenAI 互換 API を使わないモデルは、モデル固有のエンドポイントからアクセスできます。

cURL

fetch リクエストの例bash
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);

役に立ちましたか?