gh api Call the GitHub API directly

Makes an authenticated request to the GitHub API and prints the response. Use it for anything gh has no dedicated command for, or to script against the API without managing tokens.

Synopsis

gh api ENDPOINT [FLAGS]

Common options

Option or formWhat it does
-X, --method METHODHTTP method such as GET (default), POST, PATCH or DELETE
-f, --raw-field KEY=VALUEAdd a text field to the request
-F, --field KEY=VALUEAdd a field, converting numbers and true/false, or @file
-q, --jq EXPRFilter the JSON response
--paginateFetch every page of results
-H, --header "K: V"Add a request header

Examples

Show your own account
gh api user --jq .login
octocat
Read a repository's details
gh api repos/octocat/Hello-World --jq .stargazers_count
List all open issues across pages
gh api repos/octocat/Hello-World/issues --paginate --jq ".[].title"
Create an issue comment
gh api repos/octocat/Hello-World/issues/12/comments -f body="Thanks, fixed."
Run a GraphQL query
gh api graphql -f query='{ viewer { login } }'

Notes

See also

Last reviewed 2026-10-09.