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

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

# Create 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 | POST https://api.datadoghq.com/api/v2/rate-limits     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/rate-limits |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/rate-limits |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/rate-limits      |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/rate-limits |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/rate-limits |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/rate-limits |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/rate-limits      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/rate-limits  |

### Overview

Create a rate limit. All requests matching its scope share one allowance, unless a selector makes it a template, which gives each matched user, Team, or value its own allowance. Every matching rate limit applies. Returns 409 when another active rate limit has the same user, Team, tags, and selector, or when the organization already has the maximum number of rate limits.

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.

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field         | Field                      | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| -------------------- | -------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                      | data [*required*]          | object   | Data used to create an AI Gateway rate limit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| data                 | attributes [*required*]    | object   | Attributes used to create an AI Gateway rate limit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| attributes           | cost_microcents_per_minute | int64    | Maximum priced spend per rolling minute, in microcents of 1e-8 USD each. In `ENFORCE` mode, the gateway rejects requests to models with no pricing because their cost can't be counted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| attributes           | input_tokens_per_minute    | int64    | Maximum input tokens per rolling minute.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| attributes           | mode                       | enum     | Action taken when request rate exceeds the limit. Allowed enum values: `ALERT`, `ENFORCE`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| attributes           | name [*required*]          | string   | Rate limit name. Must not be empty.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| attributes           | output_tokens_per_minute   | int64    | Maximum output tokens per rolling minute.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| attributes           | requests_per_minute        | int64    | Maximum requests per rolling minute. At least one of `requests_per_minute`, `input_tokens_per_minute`, `output_tokens_per_minute`, `cost_microcents_per_minute`, or a non-empty `window_limits` is required.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| 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                       | object   | Optional scope tags, such as `provider`, `model`, `ml_app`, or custom dimensions. A request matches when it has all of these tags. The reserved metadata keys `name`, `budget_name`, and `span_filter` are rejected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| additionalProperties | <any-key>                  | string   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| attributes           | team_id                    | uuid     | Optional UUID. Count only requests attributed to this Datadog Team.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| attributes           | user_id                    | uuid     | Optional UUID. Count only this user's requests.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| attributes           | window_limits              | [object] | Limits over rolling windows longer than a minute, such as $20 of spend per 24 hours. This field is available only to organizations with the feature enabled. Other organizations receive a 400 Bad Request response for a non-empty list. Each limit counts the rule's matching traffic, or each counter of a template rate limit, over its window. Set per-minute limits in the `*_per_minute` fields. 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, the gateway rejects a request that exceeds any limit with HTTP 429 and a `Retry-After` header. If the list includes a `cost` limit, the gateway also 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                 | 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,
      "input_tokens_per_minute": "integer",
      "mode": "ALERT",
      "name": "Default rate limit",
      "output_tokens_per_minute": "integer",
      "requests_per_minute": 600,
      "selector": [
        {
          "dim": "user_id",
          "per_value": true,
          "values": [
            "11111111-1111-1111-1111-111111111111"
          ]
        }
      ],
      "tags": {
        "<any-key>": "string"
      },
      "team_id": "00000000-0000-4000-8000-000000000002",
      "user_id": "00000000-0000-4000-8000-000000000001",
      "window_limits": [
        {
          "amount": 2000000000,
          "metric": "cost",
          "window": "24h"
        }
      ]
    },
    "type": "rate-limits"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="201" %}
Created

{% 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="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
# 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 POST "https://api.${DD_SITE}/api/v2/rate-limits" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "cost_microcents_per_minute": 100000000,
      "mode": "ALERT",
      "name": "Default rate limit",
      "requests_per_minute": 600,
      "selector": [
        {
          "dim": "user_id",
          "per_value": true,
          "values": [
            "11111111-1111-1111-1111-111111111111"
          ]
        }
      ],
      "team_id": "00000000-0000-4000-8000-000000000002",
      "user_id": "00000000-0000-4000-8000-000000000001",
      "window_limits": [
        {
          "amount": 2000000000,
          "metric": "cost",
          "window": "24h"
        }
      ]
    },
    "type": "rate-limits"
  }
}
EOF
```
{% /tab %}
{% /tabs %}
