Skip to content

Commit

Permalink
Centralize, update, and restructure some information about rate limit…
Browse files Browse the repository at this point in the history
…s for REST API requests (github#23685)
  • Loading branch information
mattpollard authored Jan 25, 2022
1 parent a6d1796 commit 5af0764
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ If you need a token that requires permissions that aren't available in the `GITH

1. Use or create a token with the appropriate permissions for that repository. For more information, see "[Creating a personal access token](/github/authenticating-to-github/creating-a-personal-access-token)."
1. Add the token as a secret in your workflow's repository, and refer to it using the {%raw%}`${{ secrets.SECRET_NAME }}`{% endraw %} syntax. For more information, see "[Creating and using encrypted secrets](/github/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)."

### Further reading

- "[Resources in the REST API](/rest/overview/resources-in-the-rest-api#rate-limiting)"
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,70 @@ topics:
- GitHub Apps
shortTitle: Rate limits
---
## Server-to-server requests

{% ifversion ghec %}
{% data reusables.enterprise.rate_limit %}

{% data reusables.rest-api.always-check-your-limit %}

The rate limits for server-to-server requests made by {% data variables.product.prodname_github_apps %} depend on where the app is installed. If the app is installed on organizations or repositories owned by an enterprise on {% data variables.product.product_location %}, then the rate is higher than for installations outside an enterprise.
{% ifversion ghec or fpt %}

### Normal server-to-server rate limits
## About rate limits for apps

Rate limits for {% data variables.product.prodname_github_apps %} and {% data variables.product.prodname_oauth_apps %} depend on the plan for the organization where you install the application. For more information, see "[{% data variables.product.company_short %}'s products](/get-started/learning-about-github/githubs-products)" and "[Types of {% data variables.product.company_short %} accounts](/get-started/learning-about-github/types-of-github-accounts#organization-accounts)."

{% endif %}

{% data reusables.apps.api-rate-limits-non-ghec %}
## Server-to-server requests

{% ifversion ghec %}
{% ifversion ghec or fpt %}

### Default server-to-server rate limits for {% data variables.product.prodname_dotcom_the_website %}

{% endif %}

{% data variables.product.prodname_github_apps %} making server-to-server requests use the installation's minimum rate limit of 5,000 requests per hour. If an application is installed on an organization with more than 20 users, the application receives another 50 requests per hour for each user. Installations that have more than 20 repositories receive another 50 requests per hour for each repository. The maximum rate limit for an installation is 12,500 requests per hour.

{% ifversion fpt or ghec %}

### {% data variables.product.prodname_ghe_cloud %} server-to-server rate limits
### Server-to-server rate limits for {% data variables.product.prodname_ghe_cloud %}

{% data variables.product.prodname_github_apps %} that are installed on an organization or repository owned by an enterprise on {% data variables.product.product_location %} have a rate limit of 15,000 requests per hour for server-to-server requests.
{% endif %}

{% ifversion fpt or ghec %}

{% data variables.product.prodname_github_apps %} that are installed on an organization or a repository within an enterprise on {% data variables.product.product_location %} are subject to a limit of 15,000 requests per hour.

{% endif %}

## User-to-server requests

{% data variables.product.prodname_github_apps %} can also act [on behalf of a user](/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/#identifying-and-authorizing-users-for-github-apps), making user-to-server requests.
{% data variables.product.prodname_github_apps %} and {% data variables.product.prodname_oauth_apps %} can also act on behalf of a user, making user-to-server requests after the user authorizes the app. For more information, see "[Authorizing {% data variables.product.prodname_github_apps %}](/authentication/keeping-your-account-and-data-secure/authorizing-github-apps)" and "[Authorizing {% data variables.product.prodname_oauth_apps %}](/authentication/keeping-your-account-and-data-secure/authorizing-oauth-apps)."

User-to-server requests from {% data variables.product.prodname_oauth_apps %} are authenticated with an OAuth token. User-to-server requests from {% data variables.product.prodname_github_apps %} are authenticated with either an OAuth token or an expiring user access token. For more information, see "[Identifying and authorizing users for {% data variables.product.prodname_github_apps %}](/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps#identifying-and-authorizing-users-for-github-apps)" and "[Authorizing {% data variables.product.prodname_oauth_apps %}](/developers/apps/building-oauth-apps/authorizing-oauth-apps)."

{% ifversion fpt or ghec %}

### Default user-to-server rate limits for {% data variables.product.prodname_dotcom_the_website %}

{% endif %}

{% ifversion ghec %}

The rate limits for user-to-server requests made by {% data variables.product.prodname_github_apps %} depend on where the app is installed. If the app is installed on organizations or repositories owned by an enterprise on {% data variables.product.product_location %}, then the rate is higher than for installations outside an enterprise.

### Normal user-to-server rate limits

{% endif %}

User-to-server requests are rate limited at {% ifversion ghae %}15,000{% else %}5,000{% endif %} requests per hour and per authenticated user. All OAuth applications authorized by that user, personal access tokens owned by that user, and requests authenticated with that user's{% ifversion ghae %} token{% else %} username and password{% endif %} share the same quota of 5,000 requests per hour for that user.
{% data reusables.apps.user-to-server-rate-limits %}

{% ifversion ghec %}
{% ifversion fpt or ghec %}

### {% data variables.product.prodname_ghe_cloud %} user-to-server rate limits
### User-to-server rate limits for {% data variables.product.prodname_ghe_cloud %}

When a user belongs to an enterprise on {% data variables.product.product_location %}, user-to-server requests to resources owned by the same enterprise are rate limited at 15,000 requests per hour and per authenticated user. All OAuth applications authorized by that user, personal access tokens owned by that user, and requests authenticated with that user's username and password share the same quota of 5,000 requests per hour for that user.
{% data reusables.apps.user-to-server-rate-limits-ghec %}

{% endif %}

For more detailed information about rate limits, see "[Rate limiting](/rest/overview/resources-in-the-rest-api#rate-limiting)" for REST API and "[Resource limitations]({% ifversion ghec %}/free-pro-team@latest{% endif %}/graphql/overview/resource-limitations)" for GraphQL API.
## Further reading

- "[Rate limiting](/rest/overview/resources-in-the-rest-api#rate-limiting)" in the REST API documentation
- "[Resource limitations]({% ifversion ghec %}/free-pro-team@latest{% endif %}/graphql/overview/resource-limitations)" in the GraphQL API documentation
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ An _authorized_ OAuth App has access to all of the user's or organization owner'
| A GitHub App can request an installation access token by using a private key with a JSON web token format out-of-band. | An OAuth app can exchange a request token for an access token after a redirect via a web request. |
| An installation token identifies the app as the GitHub Apps bot, such as @jenkins-bot. | An access token identifies the app as the user who granted the token to the app, such as @octocat. |
| Installation tokens expire after a predefined amount of time (currently 1 hour). | OAuth tokens remain active until they're revoked by the customer. |
| {% data reusables.apps.api-rate-limits-non-ghec %}{% ifversion fpt or ghec %} Higher rate limits apply for {% data variables.product.prodname_ghe_cloud %}. For more information, see "[Rate limits for GitHub Apps](/developers/apps/rate-limits-for-github-apps)."{% endif %} | OAuth tokens use the user's rate limit of 5,000 requests per hour. |
| {% data variables.product.prodname_github_apps %} installed on organizations or repositories are subject to rate limits for server-to-server requests. For more information, see "[Rate limits for {% data variables.product.prodname_github_apps %}](/developers/apps/building-github-apps/rate-limits-for-github-apps)." | OAuth tokens use the user's rate limit of {% ifversion fpt or ghec or ghes %}5,000{% elsif ghae %}15,000{% endif %} requests per hour. |
| Rate limit increases can be granted both at the GitHub Apps level (affecting all installations) and at the individual installation level. | Rate limit increases are granted per OAuth App. Every token granted to that OAuth App gets the increased limit. |
| {% data variables.product.prodname_github_apps %} can authenticate on behalf of the user, which is called user-to-server requests. The flow to authorize is the same as the OAuth App authorization flow. User-to-server tokens can expire and be renewed with a refresh token. For more information, see "[Refreshing user-to-server access tokens](/apps/building-github-apps/refreshing-user-to-server-access-tokens/)" and "[Identifying and authorizing users for GitHub Apps](/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/)." | The OAuth flow used by {% data variables.product.prodname_oauth_apps %} authorizes an {% data variables.product.prodname_oauth_app %} on behalf of the user. This is the same flow used in {% data variables.product.prodname_github_app %} user-to-server authorization. |
| {% data variables.product.prodname_github_apps %} can authenticate on behalf of the user, which is called a user-to-server request. The flow to authorize is the same as the OAuth App authorization flow. User-to-server tokens can expire and be renewed with a refresh token. For more information, see "[Refreshing user-to-server access tokens](/apps/building-github-apps/refreshing-user-to-server-access-tokens/)" and "[Identifying and authorizing users for GitHub Apps](/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps/)." | The OAuth flow used by {% data variables.product.prodname_oauth_apps %} authorizes an {% data variables.product.prodname_oauth_app %} on behalf of the user. This is the same flow used in {% data variables.product.prodname_github_app %} user-to-server authorization. |

## Requesting permission levels for resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ See these pages for details on how to authenticate when using the {% data variab

{% note %}

**Note:** [Rate limits for the REST API](/rest#rate-limiting) apply to all {% data variables.product.prodname_marketplace %} API endpoints.
**Note:** [Rate limits for the REST API](/rest/overview/resources-in-the-rest-api#rate-limiting) apply to all {% data variables.product.prodname_marketplace %} API endpoints.

{% endnote %}
2 changes: 1 addition & 1 deletion content/rest/guides/best-practices-for-integrators.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ end

In this example the `closed` action is checked first before calling the `process_closed` method. Any unidentified actions are logged for future reference.

{% ifversion fpt or ghec %}
{% ifversion fpt or ghec or ghae %}

## Dealing with rate limits

Expand Down
2 changes: 1 addition & 1 deletion content/rest/guides/getting-started-with-the-rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Keep learning with the next API guide [Basics of Authentication][auth guide]!
[issues-api]: /rest/reference/issues
[link-header]: https://www.w3.org/wiki/LinkHeader
[conditional-requests]: /rest#conditional-requests
[rate-limiting]: /rest#rate-limiting
[rate-limiting]: /rest/overview/resources-in-the-rest-api#rate-limit-http-headers
[users api]: /rest/reference/users#get-a-user
[auth user api]: /rest/reference/users#get-the-authenticated-user
[defunkt github]: https://github.com/defunkt
Expand Down
53 changes: 42 additions & 11 deletions content/rest/overview/resources-in-the-rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ versions:
ghes: '*'
ghae: '*'
ghec: '*'
miniTocMaxHeadingLevel: 3
topics:
- API
---
Expand Down Expand Up @@ -123,7 +124,7 @@ Read [more about OAuth2](/apps/building-oauth-apps/). Note that OAuth2 tokens c
curl -u my_client_id:my_client_secret '{% data variables.product.api_url_pre %}/user/repos'
```

Using your `client_id` and `client_secret` does _not_ authenticate as a user, it will only identify your OAuth application to increase your rate limit. Permissions are only granted to users, not applications, and you will only get back data that an unauthenticated user would see. For this reason, you should only use the OAuth2 key/secret in server-to-server scenarios. Don't leak your OAuth application's client secret to your users.
Using your `client_id` and `client_secret` does _not_ authenticate as a user, it will only identify your OAuth App to increase your rate limit. Permissions are only granted to users, not applications, and you will only get back data that an unauthenticated user would see. For this reason, you should only use the OAuth2 key/secret in server-to-server scenarios. Don't leak your OAuth App's client secret to your users.

{% ifversion ghes %}
You will be unable to authenticate using your OAuth2 key and secret while in private mode, and trying to authenticate will return `401 Unauthorized`. For more information, see "[Enabling private mode](/admin/configuration/configuring-your-enterprise/enabling-private-mode)".
Expand Down Expand Up @@ -356,21 +357,53 @@ Name | Description
## Rate limiting
For API requests using Basic Authentication or OAuth, you can make up to 5,000 requests per hour. Authenticated requests are associated with the authenticated user, regardless of whether [Basic Authentication](#basic-authentication) or [an OAuth token](#oauth2-token-sent-in-a-header) was used. This means that all OAuth applications authorized by a user share the same quota of 5,000 requests per hour when they authenticate with different tokens owned by the same user.
Different types of API requests to {% data variables.product.product_location %} are subject to different rate limits.
Additionally, the Search API has dedicated limits. For more information, see "[Search](/rest/reference/search#rate-limit)" in the REST API documentation.
{% data reusables.enterprise.rate_limit %}
{% data reusables.rest-api.always-check-your-limit %}
### Requests from user accounts
Direct API requests that you authenticate with a personal access token are user-to-server requests. An OAuth App or GitHub App can also make a user-to-server request on your behalf after you authorize the app. For more information, see "[Creating a personal access token](/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)," "[Authorizing OAuth Apps](/authentication/keeping-your-account-and-data-secure/authorizing-oauth-apps)," and "[Authorizing GitHub Apps](/authentication/keeping-your-account-and-data-secure/authorizing-github-apps)."
{% data variables.product.product_name %} associates all user-to-server requests with the authenticated user. For OAuth Apps and GitHub Apps, this is the user who authorized the app. All user-to-server requests count toward the authenticated user's rate limit.
{% data reusables.apps.user-to-server-rate-limits %}
{% ifversion fpt or ghec %}
For users that belong to a {% data variables.product.prodname_ghe_cloud %} account, requests made using an OAuth token to resources owned by the same {% data variables.product.prodname_ghe_cloud %} account have an increased limit of 15,000 requests per hour.
{% data reusables.apps.user-to-server-rate-limits-ghec %}
{% ifversion fpt or ghec or ghes %}
For unauthenticated requests, the rate limit allows for up to 60 requests per hour. Unauthenticated requests are associated with the originating IP address, and not the person making requests.
{% endif %}
When using the built-in `GITHUB_TOKEN` in GitHub Actions, the rate limit is 1,000 requests per hour per repository. For organizations that belong to a GitHub Enterprise Cloud account, this limit is 15,000 requests per hour per repository.
{% endif %}
For unauthenticated requests, the rate limit allows for up to 60 requests per hour. Unauthenticated requests are associated with the originating IP address, and not the user making requests.
### Requests from GitHub Apps
{% data reusables.enterprise.rate_limit %}
Requests from a GitHub App may be either user-to-server or server-to-server requests. For more information about rate limits for GitHub Apps, see "[Rate limits for GitHub Apps](/developers/apps/building-github-apps/rate-limits-for-github-apps)."
### Requests from GitHub Actions
You can use the built-in `GITHUB_TOKEN` to authenticate requests in GitHub Actions workflows. For more information, see "[Automatic token authentication](/actions/security-guides/automatic-token-authentication)."
When using `GITHUB_TOKEN`, the rate limit is 1,000 requests per hour per repository.{% ifversion fpt or ghec %} For requests to resources that belong to an enterprise account on {% data variables.product.product_location %}, {% data variables.product.prodname_ghe_cloud %}'s rate limit applies, and the limit is 15,000 requests per hour per repository.{% endif %}
Note that [the Search API has custom rate limit rules](/rest/reference/search#rate-limit).
### Checking your rate limit status
The Rate Limit API and a response's HTTP headers are authoritative sources for the current number of API calls available to you or your app at any given time.
#### Rate Limit API
You can use the Rate Limit API to check your rate limit status without incurring a hit to the current limit. For more information, see "[Rate limit](/rest/reference/rate-limit)."
#### Rate limit HTTP headers
The returned HTTP headers of any API request show your current rate limit status:
Expand Down Expand Up @@ -411,11 +444,9 @@ If you exceed the rate limit, an error response returns:
> }
```
You can [check your rate limit status](/rest/reference/rate-limit) without incurring an API hit.
### Increasing the unauthenticated rate limit for OAuth applications
### Increasing the unauthenticated rate limit for OAuth Apps
If your OAuth application needs to make unauthenticated calls with a higher rate limit, you can pass your app's client ID and secret before the endpoint route.
If your OAuth App needs to make unauthenticated calls with a higher rate limit, you can pass your app's client ID and secret before the endpoint route.
```shell
$ curl -u my_client_id:my_client_secret {% data variables.product.api_url_pre %}/user/repos
Expand Down
2 changes: 1 addition & 1 deletion content/rest/reference/rate-limit.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ objects:

* The `integration_manifest` object provides your rate limit status for the [GitHub App Manifest code conversion](/apps/building-github-apps/creating-github-apps-from-a-manifest/#3-you-exchange-the-temporary-code-to-retrieve-the-app-configuration) endpoint.

For more information on the headers and values in the rate limit response, see "[Rate limiting](/rest#rate-limiting)."
For more information on the headers and values in the rate limit response, see "[Resources in the REST API](/rest/overview/resources-in-the-rest-api#rate-limit-http-headers)."

{% include rest_operations_at_current_path %}
4 changes: 2 additions & 2 deletions content/rest/reference/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Unless another sort option is provided as a query parameter, results are sorted

### Rate limit

{% data reusables.enterprise.rate_limit %}

The Search API has a custom rate limit. For requests using [Basic
Authentication](/rest#authentication), [OAuth](/rest#authentication), or [client
ID and secret](/rest#increasing-the-unauthenticated-rate-limit-for-oauth-applications), you can make up to
30 requests per minute. For unauthenticated requests, the rate limit allows you
to make up to 10 requests per minute.

{% data reusables.enterprise.rate_limit %}

See the [rate limit documentation](/rest/reference/rate-limit) for details on
determining your current rate limit status.

Expand Down
1 change: 0 additions & 1 deletion data/reusables/apps/api-rate-limits-non-ghec.md

This file was deleted.

Loading

0 comments on commit 5af0764

Please sign in to comment.