GitHub API Permissions and Failure Handling
Separate identity, permission and budget
Use the minimum repository access and endpoint permissions needed for the task. A token can be expired, revoked, restricted by organization policy or valid but underprivileged. Do not automatically request broader permissions. Choose an approved token or GitHub App installation for automation and protect credentials in the authorized secret store.
Classify before retrying
401 suggests authentication needs review. A 403 can reflect authorization or a rate limit; 404 can indicate an absent resource or hidden private resource. Inspect status, response body and relevant headers. 422 often calls for input review, not repeated submission. A transient 5xx may justify a bounded retry for safe reads; never blindly repeat a write with an unknown outcome.
Respect rate limits
For rate-limited REST responses, honor Retry-After if present and the primary reset time when remaining is zero; wait at least as long as required by both applicable constraints. For secondary limits without timing hints, GitHub advises waiting at least a minute, then increasing delays if necessary. Bound attempts and stop when the budget is exhausted. Our fixture computes decisions without sleeping or making requests.
Practice safe diagnostics
Inspect sanitized status and selected rate headers only. The offline classifier distinguishes authorization failures, hidden or absent resources, primary and secondary rate limiting, GraphQL errors in HTTP 200, transient read failures and uncertain write outcomes. It does not grant permissions or retry anything. Never log tokens, Authorization headers or private response contents by default.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
GitHub API Permissions and Failure Handling — knowledge check
Reason about GitHub CLI and API response handling.
What is the first action for an ordinary 401?
What can a 404 for a private resource mean?
How should a 429 with Retry-After be handled?
What should an unknown write outcome trigger?
What should logs omit by default?