カスタムドメインを使うと、デフォルトの gateway.ai.cloudflare.com エンドポイントではなく、ai.example.com など所有しているホスト名経由で AI Gateway へリクエストを送れます。
ホスト名がアカウントとゲートウェイを識別するため、リクエスト URL からアカウント ID とゲートウェイ ID を省略できます。リクエストは、AI Gateway のプロバイダーネイティブルートと、OpenAI 互換の compat ルートへ直接届きます。
カスタムドメインは、Cloudflare Access による ID 認識型コントロール の土台にもなります。ユーザーはゲートウェイを呼び出す前に、ID プロバイダーで認証できます。
たとえば、カスタムドメインが ai.example.com の場合、OpenAI プロバイダーへのリクエストは次の URL になります。
https://ai.example.com/openai/v1/chat/completions次の URL の代わりです。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/v1/chat/completionsOpenAI 互換エンドポイントも同じです。たとえば https://ai.example.com/compat/chat/completions は、同じゲートウェイの compat ルート経由で処理されます。
カスタムドメインを追加するには、次の手順を実行します。
- Cloudflare ダッシュボード ↗ で、AI > AI Gateway を開きます。
- 設定するゲートウェイを選択します。
- Domains タブを開きます。
- Add Domain を選択し、使うホスト名を入力します。必要に応じてサブドメインを選びます。
- AI Gateway がダッシュボード上に DNS レコードを自動作成します。
ドメインの設定後、そのホスト名へリクエストを送れます。ゲートウェイを呼び出す前にユーザー認証を求める場合は、ドメインで Cloudflare Access を設定 します。
Cloudflare API でも、カスタムドメインの作成と管理ができます。
ダッシュボードと異なり、API は DNS レコードを作成しません。カスタムドメインを作成したあと、返された cname_target を使って、ホスト名のプロキシ済み CNAME レコードを作成します。
curl "https://api.cloudflare.com/client/v4/accounts/%7Baccount_id%7D/ai-gateway/gateways/%7Bgateway_id%7D/custom-domains" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"domain": "ai.example.com",
"zone_id": "395566f4c8a5b9d2a5fc0d457b007c44"
}'レスポンスには、カスタムドメインのステータスと CNAME ターゲットが含まれます。
{
"success": true,
"result": {
"hostname": "ai.example.com",
"gateway_id": "my-gateway",
"status": "pending_dcv",
"cname_target": "<cname-target>",
"created_at": 1782925200000,
"modified_at": 1782925200000
}
}カスタムドメインを所有するゾーンに、プロキシ済みの CNAME レコードを作成します。content には、カスタムドメイン作成時に返された cname_target を設定します。
curl "https://api.cloudflare.com/client/v4/zones/%7Bzone_id%7D/dns_records" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"type": "CNAME",
"name": "ai",
"content": "<cname-target>",
"proxied": true
}'カスタムドメインは、ドメイン所有権の検証(domain control validation)が完了するまで pending_dcv のままです。
curl "https://api.cloudflare.com/client/v4/accounts/%7Baccount_id%7D/ai-gateway/gateways/%7Bgateway_id%7D/custom-domains" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"curl "https://api.cloudflare.com/client/v4/accounts/%7Baccount_id%7D/ai-gateway/gateways/%7Bgateway_id%7D/custom-domains/%7Bhostname%7D" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"curl "https://api.cloudflare.com/client/v4/accounts/%7Baccount_id%7D/ai-gateway/gateways/%7Bgateway_id%7D/custom-domains/%7Bhostname%7D" \
--request DELETE \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"パスにアカウント ID やゲートウェイ ID を含めず、カスタムドメインへリクエストを送ります。
curl -X POST "https://ai.example.com/openai/v1/chat/completions" \
--header "Content-Type: application/json" \
--data '{
"model": "gpt-4.1-mini",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'ドメインが Cloudflare Access で保護されている場合は、有効な Access トークンも必要です。詳細は Cloudflare Access を参照してください。
カスタムドメインは、Cloudflare REST API(api.cloudflare.com)経由で提供される新しい AI Gateway エンドポイントでは、まだ使えません。