Skip to content
Start here

Update a gateway

ai_gateway.update(strid, AIGatewayUpdateParams**kwargs) -> AIGatewayUpdateResponse
PUT/accounts/{account_id}/ai-gateway/gateways/{id}

Updates the configuration of an AI Gateway, such as its caching, rate limiting, logging, and authentication settings.

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
account_id: str
id: str

Unique identifier of the AI Gateway within the account.

maxLength64
minLength1
cache_invalidate_on_update: bool
cache_ttl: Optional[int]
minimum0
collect_logs: bool
rate_limiting_interval: Optional[int]
minimum0
rate_limiting_limit: Optional[int]
minimum0
authentication: Optional[bool]
byok_only: Optional[bool]

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

dlp: Optional[DLP]
One of the following:
class DLPUnionMember0: …
action: Literal["BLOCK", "FLAG"]
One of the following:
"BLOCK"
"FLAG"
enabled: bool
profiles: Sequence[str]
class DLPUnionMember1: …
enabled: bool
policies: Iterable[DLPUnionMember1Policy]
id: str
action: Literal["FLAG", "BLOCK"]
One of the following:
"FLAG"
"BLOCK"
check: List[Literal["REQUEST", "RESPONSE"]]
One of the following:
"REQUEST"
"RESPONSE"
enabled: bool
profiles: Sequence[str]
guardrails: Optional[Guardrails]
prompt: GuardrailsPrompt
p1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s10: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s11: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s12: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s13: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s2: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s3: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s4: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s5: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s6: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s7: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s8: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s9: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
response: GuardrailsResponse
p1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s10: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s11: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s12: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s13: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s2: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s3: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s4: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s5: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s6: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s7: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s8: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s9: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
log_classification: Optional[bool]
log_management: Optional[int]
maximum10000000
minimum10000
log_management_strategy: Optional[Literal["STOP_INSERTING", "DELETE_OLDEST"]]
One of the following:
"STOP_INSERTING"
"DELETE_OLDEST"
logpush: Optional[bool]
logpush_public_key: Optional[str]
maxLength1024
minLength16
otel: Optional[Iterable[Otel]]
headers: Dict[str, str]
url: str
formaturi
maxLength2048
authorization: Optional[str]
maxLength256
content_type: Optional[Literal["json", "protobuf"]]
One of the following:
"json"
"protobuf"
rate_limiting_technique: Optional[Literal["fixed", "sliding"]]
One of the following:
"fixed"
"sliding"
retry_backoff: Optional[Literal["constant", "linear", "exponential"]]

Backoff strategy for retry delays

One of the following:
"constant"
"linear"
"exponential"
retry_delay: Optional[int]

Delay between retry attempts in milliseconds (0-60000)

maximum60000
minimum0
retry_max_attempts: Optional[int]

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

maximum5
minimum1
spend_limits: Optional[SpendLimits]
enabled: Optional[bool]
rules: Optional[Iterable[SpendLimitsRule]]
limit: float
exclusiveMinimum
minimum0
limit_type: Literal["cost"]
window: int
exclusiveMinimum
minimum0
id: Optional[str]
minLength1
enabled: Optional[bool]
metadata: Optional[Dict[str, SpendLimitsRuleMetadata]]
One of the following:
class SpendLimitsRuleMetadataMode: …
mode: Literal["partition"]
class SpendLimitsRuleMetadataUnionMember1: …
mode: Literal["filter"]
values: Sequence[str]
model: Optional[SpendLimitsRuleModel]
mode: Literal["filter"]
values: Sequence[str]
provider: Optional[SpendLimitsRuleProvider]
mode: Literal["filter"]
values: Sequence[str]
technique: Optional[Literal["fixed", "sliding"]]
One of the following:
"fixed"
"sliding"
store_id: Optional[str]
stripe: Optional[Stripe]
authorization: str
usage_events: Iterable[StripeUsageEvent]
payload: str
workers_ai_billing_mode: Optional[Literal["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: Optional[bool]
ReturnsExpand Collapse
class AIGatewayUpdateResponse: …
id: str

Unique identifier of the AI Gateway within the account.

maxLength64
minLength1
cache_invalidate_on_update: bool
cache_ttl: Optional[int]
minimum0
collect_logs: bool
created_at: datetime
formatdate-time
modified_at: datetime
formatdate-time
rate_limiting_interval: Optional[int]
minimum0
rate_limiting_limit: Optional[int]
minimum0
authentication: Optional[bool]
byok_only: Optional[bool]

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

dlp: Optional[DLP]
One of the following:
class DLPUnionMember0: …
action: Literal["BLOCK", "FLAG"]
One of the following:
"BLOCK"
"FLAG"
enabled: bool
profiles: List[str]
class DLPUnionMember1: …
enabled: bool
policies: List[DLPUnionMember1Policy]
id: str
action: Literal["FLAG", "BLOCK"]
One of the following:
"FLAG"
"BLOCK"
check: List[Literal["REQUEST", "RESPONSE"]]
One of the following:
"REQUEST"
"RESPONSE"
enabled: bool
profiles: List[str]
guardrails: Optional[Guardrails]
prompt: GuardrailsPrompt
p1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s10: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s11: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s12: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s13: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s2: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s3: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s4: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s5: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s6: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s7: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s8: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s9: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
response: GuardrailsResponse
p1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s1: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s10: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s11: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s12: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s13: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s2: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s3: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s4: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s5: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s6: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s7: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s8: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
s9: Optional[Literal["FLAG", "BLOCK"]]
One of the following:
"FLAG"
"BLOCK"
is_default: Optional[bool]
log_classification: Optional[bool]
log_management: Optional[int]
maximum10000000
minimum10000
log_management_strategy: Optional[Literal["STOP_INSERTING", "DELETE_OLDEST"]]
One of the following:
"STOP_INSERTING"
"DELETE_OLDEST"
logpush: Optional[bool]
logpush_public_key: Optional[str]
maxLength1024
minLength16
otel: Optional[List[Otel]]
headers: Dict[str, str]
url: str
formaturi
maxLength2048
authorization: Optional[str]
maxLength256
content_type: Optional[Literal["json", "protobuf"]]
One of the following:
"json"
"protobuf"
rate_limiting_technique: Optional[Literal["fixed", "sliding"]]
One of the following:
"fixed"
"sliding"
retry_backoff: Optional[Literal["constant", "linear", "exponential"]]

Backoff strategy for retry delays

One of the following:
"constant"
"linear"
"exponential"
retry_delay: Optional[int]

Delay between retry attempts in milliseconds (0-60000)

maximum60000
minimum0
retry_max_attempts: Optional[int]

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

maximum5
minimum1
spend_limits: Optional[SpendLimits]
enabled: Optional[bool]
rules: Optional[List[SpendLimitsRule]]
limit: float
exclusiveMinimum
minimum0
limit_type: Literal["cost"]
window: int
exclusiveMinimum
minimum0
id: Optional[str]
minLength1
enabled: Optional[bool]
metadata: Optional[Dict[str, SpendLimitsRuleMetadata]]
One of the following:
class SpendLimitsRuleMetadataMode: …
mode: Literal["partition"]
class SpendLimitsRuleMetadataUnionMember1: …
mode: Literal["filter"]
values: List[str]
model: Optional[SpendLimitsRuleModel]
mode: Literal["filter"]
values: List[str]
provider: Optional[SpendLimitsRuleProvider]
mode: Literal["filter"]
values: List[str]
technique: Optional[Literal["fixed", "sliding"]]
One of the following:
"fixed"
"sliding"
store_id: Optional[str]
stripe: Optional[Stripe]
authorization: str
usage_events: List[StripeUsageEvent]
payload: str
workers_ai_billing_mode: Optional[Literal["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: Optional[bool]

Update a gateway

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
ai_gateway = client.ai_gateway.update(
    id="my-gateway",
    account_id="3ebbcb006d4d46d7bb6a8c7f14676cb0",
    cache_invalidate_on_update=True,
    cache_ttl=0,
    collect_logs=True,
    rate_limiting_interval=0,
    rate_limiting_limit=0,
)
print(ai_gateway.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
}