Skip to content
Start here

Create a gateway

client.aiGateway.create(AIGatewayCreateParams { account_id, id, cache_invalidate_on_update, 23 more } params, RequestOptionsoptions?): AIGatewayCreateResponse { id, cache_invalidate_on_update, cache_ttl, 25 more }
POST/accounts/{account_id}/ai-gateway/gateways

Creates an AI Gateway in the account with the specified caching, rate limiting, logging, and authentication settings. The gateway ID appears in request URLs and must be unique within the account.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
AI Gateway Write
ParametersExpand Collapse
params: AIGatewayCreateParams { account_id, id, cache_invalidate_on_update, 23 more }
account_id: string

Path param

id: string

Body param: Unique identifier of the AI Gateway within the account.

maxLength64
minLength1
cache_invalidate_on_update: boolean

Body param

cache_ttl: number | null

Body param

minimum0
collect_logs: boolean

Body param

rate_limiting_interval: number | null

Body param

minimum0
rate_limiting_limit: number | null

Body param

minimum0
authentication?: boolean

Body param

byok_only?: boolean

Body param: Requires customer-provided provider credentials and prevents fallback to Unified Billing.

dlp?: UnionMember0 { action, enabled, profiles } | UnionMember1 { enabled, policies }

Body param

One of the following:
UnionMember0 { action, enabled, profiles }
action: "BLOCK" | "FLAG"
One of the following:
"BLOCK"
"FLAG"
enabled: boolean
profiles: Array<string>
UnionMember1 { enabled, policies }
enabled: boolean
policies: Array<Policy>
id: string
action: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
check: Array<"REQUEST" | "RESPONSE">
One of the following:
"REQUEST"
"RESPONSE"
enabled: boolean
profiles: Array<string>
guardrails?: Guardrails | null

Body param

prompt: Prompt { P1, S1, S10, 11 more }
P1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S10?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S11?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S12?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S13?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S2?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S3?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S4?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S5?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S6?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S7?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S8?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S9?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
response: Response { P1, S1, S10, 11 more }
P1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S10?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S11?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S12?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S13?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S2?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S3?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S4?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S5?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S6?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S7?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S8?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S9?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
log_classification?: boolean

Body param

log_management?: number | null

Body param

maximum10000000
minimum10000
log_management_strategy?: "STOP_INSERTING" | "DELETE_OLDEST" | null

Body param

One of the following:
"STOP_INSERTING"
"DELETE_OLDEST"
logpush?: boolean

Body param

logpush_public_key?: string | null

Body param

maxLength1024
minLength16
otel?: Array<Otel> | null

Body param

headers: Record<string, string>
url: string
formaturi
maxLength2048
authorization?: string
maxLength256
content_type?: "json" | "protobuf"
One of the following:
"json"
"protobuf"
rate_limiting_technique?: "fixed" | "sliding" | null

Body param

One of the following:
"fixed"
"sliding"
retry_backoff?: "constant" | "linear" | "exponential" | null

Body param: Backoff strategy for retry delays

One of the following:
"constant"
"linear"
"exponential"
retry_delay?: number | null

Body param: Delay between retry attempts in milliseconds (0-60000)

maximum60000
minimum0
retry_max_attempts?: number | null

Body param: Maximum number of retry attempts for failed requests (1-5)

maximum5
minimum1
spend_limits?: SpendLimits | null

Body param

enabled?: boolean
rules?: Array<Rule>
limit: number
exclusiveMinimum
minimum0
limitType: "cost"
window: number
exclusiveMinimum
minimum0
id?: string
minLength1
enabled?: boolean
metadata?: Record<string, Mode { mode } | UnionMember1 { mode, values } >
One of the following:
Mode { mode }
mode: "partition"
UnionMember1 { mode, values }
mode: "filter"
values: Array<string>
model?: Model { mode, values }
mode: "filter"
values: Array<string>
provider?: Provider { mode, values }
mode: "filter"
values: Array<string>
technique?: "fixed" | "sliding"
One of the following:
"fixed"
"sliding"
store_id?: string | null

Body param

stripe?: Stripe | null

Body param

authorization: string
usage_events: Array<UsageEvent>
payload: string
workers_ai_billing_mode?: "postpaid" | "unified"

Body param: Controls how Workers AI inference calls routed through this gateway are billed. ‘postpaid’ bills the account directly through Workers AI; ‘unified’ deducts credits via AI Gateway using neuron-based pricing and delegates billing to AI Gateway.

One of the following:
"postpaid"
"unified"
zdr?: boolean

Body param

ReturnsExpand Collapse
AIGatewayCreateResponse { id, cache_invalidate_on_update, cache_ttl, 25 more }
id: string

Unique identifier of the AI Gateway within the account.

maxLength64
minLength1
cache_invalidate_on_update: boolean
cache_ttl: number | null
minimum0
collect_logs: boolean
created_at: string
formatdate-time
modified_at: string
formatdate-time
rate_limiting_interval: number | null
minimum0
rate_limiting_limit: number | null
minimum0
authentication?: boolean
byok_only?: boolean

Requires customer-provided provider credentials and prevents fallback to Unified Billing.

dlp?: UnionMember0 { action, enabled, profiles } | UnionMember1 { enabled, policies }
One of the following:
UnionMember0 { action, enabled, profiles }
action: "BLOCK" | "FLAG"
One of the following:
"BLOCK"
"FLAG"
enabled: boolean
profiles: Array<string>
UnionMember1 { enabled, policies }
enabled: boolean
policies: Array<Policy>
id: string
action: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
check: Array<"REQUEST" | "RESPONSE">
One of the following:
"REQUEST"
"RESPONSE"
enabled: boolean
profiles: Array<string>
guardrails?: Guardrails | null
prompt: Prompt { P1, S1, S10, 11 more }
P1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S10?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S11?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S12?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S13?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S2?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S3?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S4?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S5?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S6?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S7?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S8?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S9?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
response: Response { P1, S1, S10, 11 more }
P1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S1?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S10?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S11?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S12?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S13?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S2?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S3?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S4?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S5?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S6?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S7?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S8?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
S9?: "FLAG" | "BLOCK"
One of the following:
"FLAG"
"BLOCK"
is_default?: boolean
log_classification?: boolean
log_management?: number | null
maximum10000000
minimum10000
log_management_strategy?: "STOP_INSERTING" | "DELETE_OLDEST" | null
One of the following:
"STOP_INSERTING"
"DELETE_OLDEST"
logpush?: boolean
logpush_public_key?: string | null
maxLength1024
minLength16
otel?: Array<Otel> | null
headers: Record<string, string>
url: string
formaturi
maxLength2048
authorization?: string
maxLength256
content_type?: "json" | "protobuf"
One of the following:
"json"
"protobuf"
rate_limiting_technique?: "fixed" | "sliding" | null
One of the following:
"fixed"
"sliding"
retry_backoff?: "constant" | "linear" | "exponential" | null

Backoff strategy for retry delays

One of the following:
"constant"
"linear"
"exponential"
retry_delay?: number | null

Delay between retry attempts in milliseconds (0-60000)

maximum60000
minimum0
retry_max_attempts?: number | null

Maximum number of retry attempts for failed requests (1-5)

maximum5
minimum1
spend_limits?: SpendLimits | null
enabled?: boolean
rules?: Array<Rule>
limit: number
exclusiveMinimum
minimum0
limitType: "cost"
window: number
exclusiveMinimum
minimum0
id?: string
minLength1
enabled?: boolean
metadata?: Record<string, Mode { mode } | UnionMember1 { mode, values } >
One of the following:
Mode { mode }
mode: "partition"
UnionMember1 { mode, values }
mode: "filter"
values: Array<string>
model?: Model { mode, values }
mode: "filter"
values: Array<string>
provider?: Provider { mode, values }
mode: "filter"
values: Array<string>
technique?: "fixed" | "sliding"
One of the following:
"fixed"
"sliding"
store_id?: string | null
stripe?: Stripe | null
authorization: string
usage_events: Array<UsageEvent>
payload: string
workers_ai_billing_mode?: "postpaid" | "unified"

Controls how Workers AI inference calls routed through this gateway are billed. ‘postpaid’ bills the account directly through Workers AI; ‘unified’ deducts credits via AI Gateway using neuron-based pricing and delegates billing to AI Gateway.

One of the following:
"postpaid"
"unified"
zdr?: boolean

Create a gateway

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted
});

const aiGateway = await client.aiGateway.create({
  account_id: '3ebbcb006d4d46d7bb6a8c7f14676cb0',
  id: 'my-gateway',
  cache_invalidate_on_update: true,
  cache_ttl: 0,
  collect_logs: true,
  rate_limiting_interval: 0,
  rate_limiting_limit: 0,
});

console.log(aiGateway.id);
{
  "result": {
    "id": "my-gateway",
    "cache_invalidate_on_update": true,
    "cache_ttl": 0,
    "collect_logs": true,
    "created_at": "2019-12-27T18:11:19.117Z",
    "modified_at": "2019-12-27T18:11:19.117Z",
    "rate_limiting_interval": 0,
    "rate_limiting_limit": 0,
    "authentication": true,
    "byok_only": true,
    "dlp": {
      "action": "BLOCK",
      "enabled": true,
      "profiles": [
        "string"
      ]
    },
    "guardrails": {
      "prompt": {
        "P1": "FLAG",
        "S1": "FLAG",
        "S10": "FLAG",
        "S11": "FLAG",
        "S12": "FLAG",
        "S13": "FLAG",
        "S2": "FLAG",
        "S3": "FLAG",
        "S4": "FLAG",
        "S5": "FLAG",
        "S6": "FLAG",
        "S7": "FLAG",
        "S8": "FLAG",
        "S9": "FLAG"
      },
      "response": {
        "P1": "FLAG",
        "S1": "FLAG",
        "S10": "FLAG",
        "S11": "FLAG",
        "S12": "FLAG",
        "S13": "FLAG",
        "S2": "FLAG",
        "S3": "FLAG",
        "S4": "FLAG",
        "S5": "FLAG",
        "S6": "FLAG",
        "S7": "FLAG",
        "S8": "FLAG",
        "S9": "FLAG"
      }
    },
    "is_default": true,
    "log_classification": true,
    "log_management": 10000,
    "log_management_strategy": "STOP_INSERTING",
    "logpush": true,
    "logpush_public_key": "xxxxxxxxxxxxxxxx",
    "otel": [
      {
        "headers": {
          "foo": "string"
        },
        "url": "https://example.com",
        "authorization": "authorization",
        "content_type": "json"
      }
    ],
    "rate_limiting_technique": "fixed",
    "retry_backoff": "constant",
    "retry_delay": 0,
    "retry_max_attempts": 1,
    "spend_limits": {
      "enabled": true,
      "rules": [
        {
          "limit": 1,
          "limitType": "cost",
          "window": 1,
          "id": "x",
          "enabled": true,
          "metadata": {
            "foo": {
              "mode": "partition"
            }
          },
          "model": {
            "mode": "filter",
            "values": [
              "string"
            ]
          },
          "provider": {
            "mode": "filter",
            "values": [
              "string"
            ]
          },
          "technique": "fixed"
        }
      ]
    },
    "store_id": "store_id",
    "stripe": {
      "authorization": "authorization",
      "usage_events": [
        {
          "payload": "payload"
        }
      ]
    },
    "workers_ai_billing_mode": "postpaid",
    "zdr": true
  },
  "success": true
}
Returns Examples
{
  "result": {
    "id": "my-gateway",
    "cache_invalidate_on_update": true,
    "cache_ttl": 0,
    "collect_logs": true,
    "created_at": "2019-12-27T18:11:19.117Z",
    "modified_at": "2019-12-27T18:11:19.117Z",
    "rate_limiting_interval": 0,
    "rate_limiting_limit": 0,
    "authentication": true,
    "byok_only": true,
    "dlp": {
      "action": "BLOCK",
      "enabled": true,
      "profiles": [
        "string"
      ]
    },
    "guardrails": {
      "prompt": {
        "P1": "FLAG",
        "S1": "FLAG",
        "S10": "FLAG",
        "S11": "FLAG",
        "S12": "FLAG",
        "S13": "FLAG",
        "S2": "FLAG",
        "S3": "FLAG",
        "S4": "FLAG",
        "S5": "FLAG",
        "S6": "FLAG",
        "S7": "FLAG",
        "S8": "FLAG",
        "S9": "FLAG"
      },
      "response": {
        "P1": "FLAG",
        "S1": "FLAG",
        "S10": "FLAG",
        "S11": "FLAG",
        "S12": "FLAG",
        "S13": "FLAG",
        "S2": "FLAG",
        "S3": "FLAG",
        "S4": "FLAG",
        "S5": "FLAG",
        "S6": "FLAG",
        "S7": "FLAG",
        "S8": "FLAG",
        "S9": "FLAG"
      }
    },
    "is_default": true,
    "log_classification": true,
    "log_management": 10000,
    "log_management_strategy": "STOP_INSERTING",
    "logpush": true,
    "logpush_public_key": "xxxxxxxxxxxxxxxx",
    "otel": [
      {
        "headers": {
          "foo": "string"
        },
        "url": "https://example.com",
        "authorization": "authorization",
        "content_type": "json"
      }
    ],
    "rate_limiting_technique": "fixed",
    "retry_backoff": "constant",
    "retry_delay": 0,
    "retry_max_attempts": 1,
    "spend_limits": {
      "enabled": true,
      "rules": [
        {
          "limit": 1,
          "limitType": "cost",
          "window": 1,
          "id": "x",
          "enabled": true,
          "metadata": {
            "foo": {
              "mode": "partition"
            }
          },
          "model": {
            "mode": "filter",
            "values": [
              "string"
            ]
          },
          "provider": {
            "mode": "filter",
            "values": [
              "string"
            ]
          },
          "technique": "fixed"
        }
      ]
    },
    "store_id": "store_id",
    "stripe": {
      "authorization": "authorization",
      "usage_events": [
        {
          "payload": "payload"
        }
      ]
    },
    "workers_ai_billing_mode": "postpaid",
    "zdr": true
  },
  "success": true
}