Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check my GitHub current rate limit?

The GitHub page https://developer.github.com/v3/rate_limit/ shows a rate limit status as example:

Response

Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4999
X-RateLimit-Reset: 1372700873
{
  "resources": {
    "core": {
      "limit": 5000,
      "remaining": 4999,
      "reset": 1372700873
    },
    "search": {
      "limit": 30,
      "remaining": 18,
      "reset": 1372697452
    }
  },
  "rate": {
    "limit": 5000,
    "remaining": 4999,
    "reset": 1372700873
  }
}

But only says I need to check this GET /rate_limit. But how to use that? Should I do a command like this bellow?

curl -i https://api.github.com/users/octocat GET /rate_limit

How would be this command?


Related questions:

  1. GitHub API limit exceeded: how to increase the rate limit in front-end apps
  2. jspm saying "github rate limit reached" - how to fix?
  3. Github API: Fetch issues with exceeds rate limit prematurely
  4. https://developer.github.com/v3/#rate-limiting
like image 565
user Avatar asked Aug 01 '17 00:08

user


People also ask

What is the GitHub rate limit?

Requests from GitHub Actions When using GITHUB_TOKEN , the rate limit is 1,000 requests per hour per repository. For requests to resources that belong to an enterprise account on GitHub.com, GitHub Enterprise Cloud's rate limit applies, and the limit is 15,000 requests per hour per repository.

How do I fix rate limit exceeded?

If you receive an error message like “API rate limit exceeded” or “You are being rate limited”, that is the website telling you it's time to slow down. On Cryptowatch, this issue is indicated by error #803 . Typically, slowing down is all you need to do to solve the issue.


2 Answers

You can call this endpoint using

curl -H "Authorization: token YOUR-OAUTH-TOKEN" -X GET https://api.github.com/rate_limit

or similar in Ruby

    require 'uri' 
    require 'net/http'    
    
    url = URI("https://api.github.com/rate_limit")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    
    request = Net::HTTP::Get.new(url)     
    request["Authorization"] = 'token YOUR-OAUTH-TOKEN'

    response = http.request(request) 
    puts response.read_body
like image 104
osowskit Avatar answered Dec 31 '22 21:12

osowskit


Here's the Python equivalent using requests.

Replace TOKEN with your token. (I use the Github personal access token found here)

import requests

headers = {
    'Authorization': 'token TOKEN',
}

response = requests.get('https://api.github.com/rate_limit', headers=headers)

print(response.text)

like image 28
openwonk Avatar answered Dec 31 '22 19:12

openwonk