---
title: Update an AI Gateway rate limit
description: Update a rate limit.
breadcrumbs: Docs > API > Update an AI Gateway rate limit
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Update an AI Gateway rate limit

## v2 (latest)

{% alert level="warning" %}
**Note**: This endpoint is in Preview and is subject to change.
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help.md).
{% /alert %}

| Datadog site      | API endpoint                                                |
| ----------------- | ----------------------------------------------------------- |
| app.datadoghq.com | PATCH https://api.datadoghq.com/api/v2/rate-limits/{id}     |
| us3.datadoghq.com | PATCH https://api.us3.datadoghq.com/api/v2/rate-limits/{id} |
| us5.datadoghq.com | PATCH https://api.us5.datadoghq.com/api/v2/rate-limits/{id} |
| app.datadoghq.eu  | PATCH https://api.datadoghq.eu/api/v2/rate-limits/{id}      |
| ap1.datadoghq.com | PATCH https://api.ap1.datadoghq.com/api/v2/rate-limits/{id} |
| ap2.datadoghq.com | PATCH https://api.ap2.datadoghq.com/api/v2/rate-limits/{id} |
| uk1.datadoghq.com | PATCH https://api.uk1.datadoghq.com/api/v2/rate-limits/{id} |
| app.ddog-gov.com  | PATCH https://api.ddog-gov.com/api/v2/rate-limits/{id}      |
| us2.ddog-gov.com  | PATCH https://api.us2.ddog-gov.com/api/v2/rate-limits/{id}  |

### Overview

Update a rate limit. Only the attributes sent are changed, and changes never reset current usage. Scope stays editable, except on a template rate limit, whose user_id, team_id, and tags are rejected with 400. Returns 409 when the rule was changed concurrently or the new scope duplicates another rule.

This endpoint requires the `ai_gateway_config_write` permission.

OAuth apps require the `ai_gateway_config_write` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#ai-gateway) to access this endpoint.

### Arguments

#### Path Parameters

| Field           | Type   | Description      |
| --------------- | ------ | ---------------- |
| id [*required*] | string | Rate limit UUID. |

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field         | Field                      | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| -------------------- | -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                      | data [*required*]          | object   | Data used to update an AI Gateway rate limit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| data                 | attributes [*required*]    | object   | Attributes used to update an AI Gateway rate limit. Only sent fields are changed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| attributes           | cost_microcents_per_minute | int64    | Spend limit in microcents per rolling minute. Set to 0 to remove the cost limit. Null is ignored. At least one limit, per-minute or in `window_limits`, must remain.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| attributes           | enabled                    | boolean  | Whether this rate limit is active.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| attributes           | input_tokens_per_minute    | int64    | Set to 0 to remove the input token limit. Null is ignored. At least one limit, per-minute or in `window_limits`, must remain.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| attributes           | mode                       | enum     | Action taken when request rate exceeds the limit. Allowed enum values: `ALERT`, `ENFORCE`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| attributes           | name                       | string   | Rate limit name.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| attributes           | output_tokens_per_minute   | int64    | Set to 0 to remove the output token limit. Null is ignored. At least one limit, per-minute or in `window_limits`, must remain.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| attributes           | requests_per_minute        | int64    | Set to 0 to remove the request limit. Null is ignored. At least one limit, per-minute or in `window_limits`, must remain.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| attributes           | tags                       | object   | Replaces all scope tags. An empty object clears them. Null is ignored.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| additionalProperties | <any-key>                  | string   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| attributes           | team_id                    | string   | Replaces the Team scope. An empty string clears it. Null is ignored.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| attributes           | user_id                    | string   | Replaces the user scope. An empty string clears it. Null is ignored.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| attributes           | window_limits              | [object] | Replaces all limits over rolling windows longer than a minute. If `window_limits` is null or omitted, the existing limits are unchanged. An empty array removes them all. This field is available only to organizations with the feature enabled. Other organizations receive a 400 Bad Request response for a non-empty list. The same rules as on create apply. A rule can have at most four limits in total, including any per-minute limits that are set. Each metric and window pair can appear only once, and for the same metric, a longer window must have a larger amount. In `ENFORCE` mode, if the list includes a `cost` limit, the gateway rejects requests to models with no pricing because their cost can't be counted. |
| window_limits        | amount [*required*]        | int64    | Maximum amount of the metric over the window. For `cost`, the amount is priced spend in microcents of 1e-8 USD each, as in `cost_microcents_per_minute`. For the same metric, a longer window must have a larger amount.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| window_limits        | metric [*required*]        | enum     | The metric that a window limit counts. `cost` counts priced spend in microcents. Allowed enum values: `requests`, `input_tokens`, `output_tokens`, `cost`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| window_limits        | window [*required*]        | enum     | The rolling window that a limit applies to. For per-minute limits, use the `*_per_minute` fields instead. Allowed enum values: `5m`, `15m`, `30m`, `1h`, `3h`, `6h`, `12h`, `24h`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| data                 | id [*required*]            | uuid     | Rate limit UUID. Must match the path parameter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| data                 | type [*required*]          | enum     | AI Gateway rate limit resource type. Allowed enum values: `rate-limits`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "cost_microcents_per_minute": "integer",
      "enabled": false,
      "input_tokens_per_minute": "integer",
      "mode": "ALERT",
      "name": "string",
      "output_tokens_per_minute": "integer",
      "requests_per_minute": "integer",
      "tags": {
        "<any-key>": "string"
      },
      "team_id": "string",
      "user_id": "string",
      "window_limits": [
        {
          "amount": 2000000000,
          "metric": "cost",
          "window": "24h"
        }
      ]
    },
    "id": "11111111-1111-1111-1111-111111111111",
    "type": "rate-limits"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="200" %}
OK

{% tabs %}
{% tab label="Model" %}
Response containing one AI Gateway rate limit.

| Parent field         | Field                            | Type      | Description                                                                                                                                                                                                                                                            |
| -------------------- | -------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                      | data [*required*]                | object    | AI Gateway rate limit resource.                                                                                                                                                                                                                                        |
| data                 | attributes [*required*]          | object    | Attributes of an AI Gateway rate limit.                                                                                                                                                                                                                                |
| attributes           | cost_microcents_per_minute       | int64     | Maximum priced spend per rolling minute, in microcents of 1e-8 USD each, shared by all matching traffic, or per counter for a template rate limit. Null when this rule does not limit cost.                                                                            |
| attributes           | created_at [*required*]          | date-time | Creation timestamp.                                                                                                                                                                                                                                                    |
| attributes           | created_by [*required*]          | string    | Email of the user who created this rate limit.                                                                                                                                                                                                                         |
| attributes           | enabled [*required*]             | boolean   | Whether this rate limit is active.                                                                                                                                                                                                                                     |
| attributes           | input_tokens_per_minute          | int64     | Maximum input tokens per rolling minute shared by all matching traffic, or per counter for a template rate limit. Null when this rule does not limit input tokens.                                                                                                     |
| attributes           | is_template [*required*]         | boolean   | Whether the selector gives each matching value its own allowance, that is, whether it has at least one per_value entry. Returned even when scope_restricted hides the selector.                                                                                        |
| attributes           | mode [*required*]                | enum      | Action taken when request rate exceeds the limit. Allowed enum values: `ALERT`, `ENFORCE`.                                                                                                                                                                             |
| attributes           | monitor_id                       | int64     | Datadog monitor that alerts on this rule. Null until one is provisioned.                                                                                                                                                                                               |
| attributes           | name [*required*]                | string    | Rate limit name.                                                                                                                                                                                                                                                       |
| attributes           | output_tokens_per_minute         | int64     | Maximum output tokens per rolling minute shared by all matching traffic, or per counter for a template rate limit. Null when this rule does not limit output tokens.                                                                                                   |
| attributes           | requests_per_minute              | int64     | Maximum requests per rolling minute shared by all matching traffic, or per counter for a template rate limit. Null when this rule does not limit requests.                                                                                                             |
| attributes           | revision [*required*]            | int64     | Increases on every change to the definition.                                                                                                                                                                                                                           |
| attributes           | scope_restricted [*required*]    | boolean   | Whether provider or model scope metadata was withheld. Omit unchanged scope fields on an unrelated update to preserve their saved values.                                                                                                                              |
| attributes           | selector                         | [object]  | Dimension rules for a template rate limit, which gives each matched user, Team, or value its own allowance with the rule's limits. Can't be combined with user_id, team_id, or tags, and can't be changed after creation. Omit for a rule with one shared allowance.   |
| selector             | dim [*required*]                 | string    | Dimension to match: user_id, team_id, model, provider, or tag:<key>. Reserved metadata tag keys are rejected.                                                                                                                                                          |
| selector             | per_value [*required*]           | boolean   | Give each matched value its own allowance when true. Otherwise, matched values share the allowance within the other separated dimensions. Default: `false`.                                                                                                            |
| selector             | values                           | [string]  | Allowed dimension values. Omit to match any value; with per_value true, a request must still carry the dimension to match. An explicit list must contain at least one value. Listed team_id values must be existing Teams without open membership.                     |
| attributes           | tags [*required*]                | object    | Optional scope tags, such as provider, model, ml_app, or custom dimensions. A request matches when it has all of these tags.                                                                                                                                           |
| additionalProperties | <any-key>                        | string    |                                                                                                                                                                                                                                                                        |
| attributes           | team_id                          | uuid      | Optional Team UUID. Count only requests attributed to this Datadog Team.                                                                                                                                                                                               |
| attributes           | template_split_dims [*required*] | [string]  | Dimensions of the selector's per_value entries, such as user_id or tag:env, each matching value of which gets its own allowance. Empty unless is_template is true. Returned even when scope_restricted hides the selector.                                             |
| attributes           | updated_at [*required*]          | date-time | Last modification timestamp.                                                                                                                                                                                                                                           |
| attributes           | updated_by [*required*]          | string    | Email of the user who last modified this rate limit.                                                                                                                                                                                                                   |
| attributes           | user_id                          | uuid      | Optional user UUID. Count only this user's requests.                                                                                                                                                                                                                   |
| attributes           | window_limits                    | [object]  | Limits over rolling windows longer than a minute. Each limit counts the rule's matching traffic, or each counter of a template rate limit, over its window. Per-minute limits are in the `*_per_minute` fields. This list is empty when the rule has no window limits. |
| window_limits        | amount [*required*]              | int64     | Maximum amount of the metric over the window. For `cost`, the amount is priced spend in microcents of 1e-8 USD each, as in `cost_microcents_per_minute`. For the same metric, a longer window must have a larger amount.                                               |
| window_limits        | metric [*required*]              | enum      | The metric that a window limit counts. `cost` counts priced spend in microcents. Allowed enum values: `requests`, `input_tokens`, `output_tokens`, `cost`.                                                                                                             |
| window_limits        | window [*required*]              | enum      | The rolling window that a limit applies to. For per-minute limits, use the `*_per_minute` fields instead. Allowed enum values: `5m`, `15m`, `30m`, `1h`, `3h`, `6h`, `12h`, `24h`.                                                                                     |
| data                 | id [*required*]                  | uuid      | Rate limit UUID.                                                                                                                                                                                                                                                       |
| data                 | type [*required*]                | enum      | AI Gateway rate limit resource type. Allowed enum values: `rate-limits`.                                                                                                                                                                                               |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "cost_microcents_per_minute": 100000000,
      "created_at": "2026-09-01T00:00:00Z",
      "created_by": "user@example.com",
      "enabled": true,
      "input_tokens_per_minute": 500000,
      "is_template": false,
      "mode": "ALERT",
      "monitor_id": 12345678,
      "name": "Default rate limit",
      "output_tokens_per_minute": 200000,
      "requests_per_minute": 1000,
      "revision": 1,
      "scope_restricted": false,
      "selector": [
        {
          "dim": "user_id",
          "per_value": true,
          "values": [
            "11111111-1111-1111-1111-111111111111"
          ]
        }
      ],
      "tags": {
        "<any-key>": "string"
      },
      "team_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
      "template_split_dims": [
        []
      ],
      "updated_at": "2026-09-15T14:30:00Z",
      "updated_by": "user@example.com",
      "user_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
      "window_limits": [
        {
          "amount": 2000000000,
          "metric": "cost",
          "window": "24h"
        }
      ]
    },
    "id": "33333333-3333-3333-3333-333333333333",
    "type": "rate-limits"
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Not Found

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="409" %}
Conflict

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Path parameters
export id="33333333-3333-3333-3333-333333333333"

# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X PATCH "https://api.${DD_SITE}/api/v2/rate-limits/${id}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "mode": "ALERT",
      "window_limits": [
        {
          "amount": 2000000000,
          "metric": "cost",
          "window": "24h"
        }
      ]
    },
    "id": "11111111-1111-1111-1111-111111111111",
    "type": "rate-limits"
  }
}
EOF
```
{% /tab %}
{% /tabs %}
