Skip to content

Instantly share code, notes, and snippets.

@RoCry
Created January 17, 2025 09:17
Show Gist options
  • Select an option

  • Save RoCry/7380f6b83cde6d8a9a0254a3c6fe0e20 to your computer and use it in GitHub Desktop.

Select an option

Save RoCry/7380f6b83cde6d8a9a0254a3c6fe0e20 to your computer and use it in GitHub Desktop.

Revisions

  1. RoCry created this gist Jan 17, 2025.
    43 changes: 43 additions & 0 deletions cursor_usage.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    import requests


    def get_cookie() -> str:
    import browser_cookie3

    return browser_cookie3.arc(domain_name="cursor.com")


    def req(url: str, cookies: list[str]) -> requests.Response:
    headers = {
    "accept": "*/*",
    "accept-language": "en-US,en;q=0.9,zh;q=0.8,zh-HK;q=0.7,zh-TW;q=0.6",
    "dnt": "1",
    "priority": "u=1, i",
    "referer": "https://www.cursor.com/settings",
    "sec-ch-ua": '"Chromium";v="131", "Not_A Brand";v="24"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"macOS"',
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
    }

    return requests.get(url, headers=headers, cookies=cookies)


    def print_usage(user_id: str, show_small: bool = False):
    resp = req(f"https://www.cursor.com/api/usage?user={user_id}", get_cookie())
    data = resp.json()
    preminum = (
    f"{data['gpt-4']['numRequestsTotal']} / {data['gpt-4']['maxRequestUsage']}"
    )
    if show_small:
    small = f"{data['gpt-3.5-turbo']['numRequestsTotal']} / {data['gpt-3.5-turbo'].get('maxRequestUsage') or 'No Limit'}"
    print(f"Premium: {preminum}, small: {small}")
    else:
    print(f"Premium: {preminum}")


    if __name__ == "__main__":
    print_usage("user_01J68RXCAB64YCKP8FQ55Z010H")