Why do I encounter a rate limit error when I have remaining API calls on GitHub?

I’m currently using the GitHub REST API and I’m facing an unusual issue. Every time I attempt to search for code, I receive rate limit exceeded errors, even though I still have several requests available.

Here’s the code I’m working with:

import requests

url = 'https://api.github.com/search/code?q=flask+in:file+language:python'
result = requests.get(url, headers=headers)

The error response I get is:

{
  "message": "API rate limit exceeded for ... (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) If you reach out to GitHub Support for help, please include the request ID ... and timestamp 2025-06-26 19:56:09 UTC.",
  "documentation_url": "https://docs.github.com/rest/overview/rate-limits-for-the-rest-api",
  "status": "403"
}

I am using a personal access token in my Authorization header, and checking my rate limits shows I have 60 requests remaining. This situation is confusing for me. Why does GitHub report that I’ve surpassed the limit when I still have requests left? Is there a specific aspect of the search API that I might not be aware of? Any assistance with resolving this would be highly appreciated.

GitHub’s search API has its own rate limiting - totally separate from regular REST endpoints. You’re hitting the secondary rate limit for search, which caps at 30 requests per minute. Your main API quota showing 60 remaining calls doesn’t matter here. I ran into this same issue building automation scripts last month. GitHub uses separate buckets for different API types - your general calls might be fine while search is maxed out. Check the X-RateLimit-Remaining header in your search responses instead of trusting the general rate limit status. FYI, unauthenticated search only gets 10 per minute, so your token’s working fine.

The search endpoint has its own rate limit that’s way more restrictive than the general API limit. Even authenticated, code search caps at 30 requests per minute - completely separate from your main API quota. I hit this same issue last year building a repo analysis tool. The error message doesn’t tell you which rate limit you’re hitting, which is annoying. You’ll need exponential backoff and need to space out search requests more. GitHub’s search API also has tricky pagination that’ll burn through your quota fast if you’re not careful with query parameters.