Understanding GitHub API Rate Limits: REST, GraphQL, and Beyond #163553
Pinned
devopsjester
started this conversation in
Discover
Replies: 2 comments
This comment was marked as spam.
This comment was marked as spam.
-
For those of you using Golang, you can use https://github.com/gofri/go-github-ratelimit to gracefully handle the limits running out. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Understanding GitHub API Rate Limits: REST, GraphQL, and Beyond
A deep dive into how API rate limits work on GitHub Enterprise Cloud, why they exist, and best practices for staying within the boundaries.
At GitHub, we strive to provide a reliable and performant API experience for every developer and organization. Whether you’re building automations, integrations, or developer tooling, understanding API rate limits helps ensure your apps run smoothly and fairly alongside millions of others.
In this post, we’ll walk you through the essentials of GitHub’s API rate limits for REST and GraphQL, and introduce the concept of secondary rate limits—what they are, why they matter, and how you can avoid running into them.
What are REST API Rate Limits—and Why Do We Have Them?
Every API request consumes resources on GitHub’s infrastructure. To ensure a responsive and stable service for all users, GitHub enforces rate limits—restrictions on how many requests you can make within a given time window.
How REST API Rate Limits Work
For most applications (including those using GitHub Enterprise Cloud), the REST API enforces a limit on the number of requests per hour per authenticated user or app. As of this writing:
Each request you make, whether to fetch repositories, manage issues, or trigger workflows, counts towards your quota. You can check your current usage by inspecting the
X-RateLimit-Remaining
andX-RateLimit-Reset
headers in API responses.Why Do Rate Limits Exist?
Rate limits are essential for:
What To Do If You Hit the Limit?
If you exceed your limit, you’ll receive a
403 Forbidden
error with a message indicating you’ve been rate limited. The best practice is to back off and retry after the reset time. Implementing exponential backoff and monitoring your app’s usage can help prevent disruptions.**Pro tip: **Use conditional requests (via ETags) and pagination to minimize unnecessary calls.
What About GraphQL API Rate Limits?
GitHub’s GraphQL API enables more efficient, flexible queries—but it comes with a different approach to rate limiting.
Instead of counting requests, GraphQL rate limits are based on a cost calculation for each query, measured in “points.” The default limit is:
Each field in your query has a computational cost, so complex or deeply nested queries consume more points. The API response includes detailed rate limit info so you can track your usage.
Best Practices for GraphQL Rate Limits
Introducing Secondary Rate Limits
In addition to primary rate limits, GitHub enforces secondary rate limits to protect the platform from sudden spikes, abusive patterns, or unexpected usage that could impact reliability.
What Triggers Secondary Rate Limits?
Secondary limits are more nuanced and can be triggered by:
Making too many requests too quickly* (even if you’re below the primary limit)
Repeatedly making the same request
Patterns that indicate automation gone awry
** No more than 900 points per minute are allowed for REST API endpoints, and no more than 2,000 points per minute are allowed for the GraphQL API endpoint.*
Unlike primary limits, secondary rate limits are dynamic and may change based on current GitHub load or risk factors. When triggered, you’ll receive a
403 Forbidden
response with a message indicating a secondary rate limit, and the affected requests may be temporarily blocked.How to Avoid Secondary Rate Limits
Recap and Resources
Understanding and respecting GitHub’s API rate limits is key to building robust, reliable integrations. Here’s a quick checklist:
For more details, check out the official docs:
Happy building! 🚀
Do you have questions or tips about working with API rate limits? Share your experience in the comments below!
Beta Was this translation helpful? Give feedback.
All reactions