13

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
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
  • The rate limiting url you provided states each API response contains this information. So you can always update it. – osowskit Aug 01 '17 at 01:00
  • My response is saying I reached the limit, but shows nothing else: `b'{"error":{"code":403,"status":"Forbidden","message":"{\\"message\\":\\"API rate limit exceeded for myusername.\\",\\"documentation_url\\":\\"https://developer.github.com/v3/#rate-limiting\\"}"}}'`, How can I see a complete/full report as the big one on the question? I get that one from the example on the page https://developer.github.com/v3/rate_limit/ – Evandro Coan Aug 01 '17 at 01:03

2 Answers2

18

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
not2qubit
  • 14,531
  • 8
  • 95
  • 135
osowskit
  • 5,904
  • 2
  • 29
  • 38
  • How would be an example for this `Basic `? I need to type my password on plain text? How could I see my unauthenticated rate limit? – Evandro Coan Aug 01 '17 at 02:07
  • 1
    You can use multiple methods https://developer.github.com/v3/#basic-authentication – osowskit Aug 01 '17 at 02:36
  • 2
    If I put the `OAUTH-TOKEN` as in you question it throws the error: `curl: (6) Could not resolve host: token, curl: (6) Could not resolve host: OAUTH-TOKEN'`. If I use as `curl -H "Authorization: token OAUTH-TOKEN" -X GET https://api.github.com/rate_limit`, it does work correctly. Can you update the answer? – Evandro Coan Aug 02 '17 at 00:14
  • This really worked, also with the new GH API changes made last year. – not2qubit Jan 25 '22 at 18:37
1

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)

openwonk
  • 14,023
  • 7
  • 43
  • 39