GitHub Copilot Pro Premium Requests Status per API abfragen

Wie kann die 20% Zahl aus diesem VSCode Screenshot zur Copilot Pro AI Usage via API abgefragt werden?

Eigentlich gar nicht, geht offiziell nur für Enterprise / Org Accounts.

Mit dem inoffiziellen (unstable) Endpunkt https://api.github.com/copilot_internal/user klappt es trotzdem.

import requests

PAT = "github_pat_foobar"

response = requests.get(
    "https://api.github.com/copilot_internal/user",
    headers={
        "Authorization": f"token {PAT}",
        "Accept": "application/json",
    },
)

print(f"Status: {response.status_code}")
print(response.json())

Dazu einfach einen fine-grained personal access token mit der Berechtigung „Copilot Requests“ hier erstellen.