diff --git a/changelog.mdx b/changelog.mdx index 9ea061518..c4eeca9f2 100644 --- a/changelog.mdx +++ b/changelog.mdx @@ -7,6 +7,18 @@ keywords: ["changelog", "API updates", "release notes", "what's new", "API chang To subscribe to updates, please [**“Turn on notifications”**](https://help.x.com/en/managing-your-account/notifications-on-mobile-devices#:~:text=In%20the%20top%20menu,%20you,you%20would%20like%20to%20receive) for [**@API**](https://x.com/api). You can also follow this changelog in your feed reader via the [**RSS feed**](https://docs.x.com/changelog/rss.xml). + + ### `x-request-id`, `Retry-After`, and actionable `429` error details + + X API v2 responses now include standard request correlation and rate-limit retry metadata to make debugging and automated retries more reliable: + + - **`x-request-id` header:** Every response (`2xx`, `4xx`, and `5xx`) now returns a unique 16-character hex `x-request-id` header. Log it in your client and include it when troubleshooting or contacting support. + - **`retry-after` header on `429`:** `429 Too Many Requests` responses now include an RFC 9110 `retry-after` header with delta seconds until the blocking window resets — covering 1-second, 15-minute, and 24-hour limits without client clock skew. + - **Actionable `429` Problem Details:** While preserving `"type": "about:blank"`, `"title": "Too Many Requests"`, and `"status": 429`, the `detail` message now explains which limit was reached and when it resets, alongside structured `limit_scope`, `limit_window`, `limit`, `remaining`, `reset`, and `retry_after` fields. + + No request changes are needed. See [Rate Limits](/x-api/fundamentals/rate-limits#checking-your-limits) and [Response Codes & Errors](/x-api/fundamentals/response-codes-and-errors#request-id-and-rate-limit-headers). + + ### Zero-downtime OAuth 2.0 credential rotation diff --git a/fundamentals/rate-limits.mdx b/fundamentals/rate-limits.mdx index f9ccea12f..e00e1207c 100644 --- a/fundamentals/rate-limits.mdx +++ b/fundamentals/rate-limits.mdx @@ -51,22 +51,29 @@ x-rate-limit-reset: 1705420800 | Header | Description | |:-------|:------------| -| `x-rate-limit-limit` | Maximum requests allowed in the current window | -| `x-rate-limit-remaining` | Requests remaining in the current window | -| `x-rate-limit-reset` | Unix timestamp when the limit resets | +| `x-rate-limit-limit` | Maximum requests allowed in the current 15-minute window | +| `x-rate-limit-remaining` | Requests remaining in the current 15-minute window | +| `x-rate-limit-reset` | Unix timestamp when the 15-minute limit resets | +| `retry-after` | Sent on `429 Too Many Requests` with delta seconds until the blocking window (`1s`, `15m`, or `24h`) resets | --- ## Rate limit errors -When you exceed a rate limit, you'll receive a **429 Too Many Requests** response: +When you exceed a rate limit on X API v2, you'll receive a **429 Too Many Requests** response with a `retry-after` header and structured Problem Details: ```json { - "errors": [{ - "code": 88, - "message": "Rate limit exceeded" - }] + "type": "about:blank", + "title": "Too Many Requests", + "detail": "Rate limit exceeded: the per-app limit of 450 requests per 15 minutes for this endpoint has been reached (0 requests remaining). Resets at 2026-12-02T01:15:00Z (in 42 seconds).", + "status": 429, + "limit_scope": "app", + "limit_window": "15m", + "limit": 450, + "remaining": 0, + "reset": 1796174100, + "retry_after": 42 } ``` diff --git a/x-api/fundamentals/rate-limits.mdx b/x-api/fundamentals/rate-limits.mdx index 444cf71b8..8a2a647f4 100644 --- a/x-api/fundamentals/rate-limits.mdx +++ b/x-api/fundamentals/rate-limits.mdx @@ -32,9 +32,40 @@ x-rate-limit-reset: 1705420800 | Header | Description | |:-------|:------------| -| `x-rate-limit-limit` | Maximum requests allowed | -| `x-rate-limit-remaining` | Requests remaining in window | -| `x-rate-limit-reset` | Unix timestamp when window resets | +| `x-rate-limit-limit` | Maximum requests allowed in the 15-minute window | +| `x-rate-limit-remaining` | Requests remaining in the 15-minute window | +| `x-rate-limit-reset` | Unix epoch timestamp (seconds) when the 15-minute window resets | +| `x-app-limit-24hour-limit` / `-remaining` / `-reset` | Quota, remaining requests, and reset timestamp for app-level 24-hour limits (when applicable) | +| `x-user-limit-24hour-limit` / `-remaining` / `-reset` | Quota, remaining requests, and reset timestamp for user-level 24-hour limits (when applicable) | +| `retry-after` | Sent on `429 Too Many Requests` responses with delta seconds until the blocking window resets (covers 1-second, 15-minute, and 24-hour limits without client clock skew) | + +### 429 Too Many Requests response body + +When a rate limit is exceeded, X API v2 returns HTTP `429` with `retry-after` and structured RFC 7807 Problem Details identifying which limit was hit and when it resets: + +```json title="Example 429 response" lines wrap icon="/icons/xds/icon-brackets.svg" +{ + "type": "about:blank", + "title": "Too Many Requests", + "detail": "Rate limit exceeded: the per-app limit of 450 requests per 15 minutes for this endpoint has been reached (0 requests remaining). Resets at 2026-12-02T01:15:00Z (in 42 seconds).", + "status": 429, + "limit_scope": "app", + "limit_window": "15m", + "limit": 450, + "remaining": 0, + "reset": 1796174100, + "retry_after": 42 +} +``` + +| Field | Description | +|:------|:------------| +| `limit_scope` | Bucket that blocked the request: `app` or `user` | +| `limit_window` | Window that blocked the request: `1s`, `15m`, or `24h` | +| `limit` | Total requests allowed in that window | +| `remaining` | Requests remaining in that window | +| `reset` | Unix epoch timestamp (seconds) when the blocking window resets (present when known) | +| `retry_after` | Seconds to wait before retrying, matching the `retry-after` header (present when known) | --- @@ -425,8 +456,8 @@ When you hit a rate limit, you'll receive a 429 response: ### Recovery strategy -1. Check `x-rate-limit-reset` for when the window resets -2. Wait until that time before retrying +1. Check the `retry-after` header (seconds to wait) first; it accounts for 1-second, 15-minute, and 24-hour limits without clock skew +2. Fall back to `x-rate-limit-reset` (or the 24-hour reset header) if `retry-after` is absent 3. Use exponential backoff if needed ```python title="Example" lines wrap icon="python" @@ -436,8 +467,12 @@ def make_request_with_backoff(url, headers): response = requests.get(url, headers=headers) if response.status_code == 429: - reset_time = int(response.headers.get('x-rate-limit-reset', 0)) - wait_time = max(reset_time - time.time(), 60) + retry_after = response.headers.get("retry-after") + if retry_after and retry_after.isdigit(): + wait_time = max(int(retry_after), 1) + else: + reset_time = int(response.headers.get("x-rate-limit-reset", 0)) + wait_time = max(reset_time - time.time(), 60) time.sleep(wait_time) return make_request_with_backoff(url, headers) diff --git a/x-api/fundamentals/response-codes-and-errors.mdx b/x-api/fundamentals/response-codes-and-errors.mdx index 0b2b5b7fa..154600661 100644 --- a/x-api/fundamentals/response-codes-and-errors.mdx +++ b/x-api/fundamentals/response-codes-and-errors.mdx @@ -131,7 +131,8 @@ This happens when requesting multiple resources and some are unavailable. **Rate limited:** -- Check `x-rate-limit-reset` header for when to retry +- Wait for the duration in the `retry-after` response header (covers 1-second, 15-minute, and 24-hour limits without clock skew), or fall back to `x-rate-limit-reset` +- Inspect `limit_scope`, `limit_window`, `limit`, `remaining`, `reset`, and `retry_after` in the JSON body to see which bucket blocked the request - Implement exponential backoff - Consider caching responses - Spread requests across the time window @@ -167,11 +168,12 @@ This happens when requesting multiple resources and some are unavailable. --- -## Rate limit headers +## Request ID and rate limit headers -Every response includes rate limit information: +Every X API v2 response includes a unique correlation ID in `x-request-id`, along with rate limit headers: ``` +x-request-id: 48485a3953bb6124 x-rate-limit-limit: 900 x-rate-limit-remaining: 847 x-rate-limit-reset: 1705420800 @@ -179,9 +181,11 @@ x-rate-limit-reset: 1705420800 | Header | Description | |:-------|:------------| -| `x-rate-limit-limit` | Max requests in current window | -| `x-rate-limit-remaining` | Requests remaining | -| `x-rate-limit-reset` | Unix timestamp when window resets | +| `x-request-id` | Unique 16-character hex request identifier stamped on every response (`2xx`, `4xx`, `5xx`). Log this value and include it when troubleshooting or contacting support. | +| `x-rate-limit-limit` | Max requests in current 15-minute window | +| `x-rate-limit-remaining` | Requests remaining in current 15-minute window | +| `x-rate-limit-reset` | Unix epoch timestamp (seconds) when the 15-minute window resets | +| `retry-after` | Present on `429 Too Many Requests`; delta seconds until the blocking window (`1s`, `15m`, or `24h`) resets | --- @@ -208,6 +212,7 @@ x-rate-limit-reset: 1705420800 When posting questions about errors, include: +- The `x-request-id` response header value - The API endpoint URL - Request headers (sanitize credentials) - Full error response