DevOpsFinOpsGovernance

GitHub Enterprise Billing API: Fix 403 Errors and SAML SSO

Parveen Singh
December 2, 2026
13 min read
GitHub Enterprise Billing API: Fix 403 Errors and SAML SSO

You want GitHub Enterprise billing data in your own dashboard or cost report, so you call the billing usage API. Instead of usage rows, you get a 403 Forbidden. Or a 404 Not Found for an enterprise you know exists. Or, worst of all, a perfectly normal 200 with totals that don't match the invoice.

Each of those has a short list of causes, and GitHub's error messages rarely tell you which one you've hit. This post goes through all of them:

  • Which billing endpoints exist, who can call them, and which kinds of tokens work.
  • How to diagnose the problem from the response headers in one command.
  • A fix for each cause of a 403: the token's permissions, your role, fine-grained tokens, and SAML single sign-on.
  • Why a successful response can still give you the wrong number.
  • How to keep the integration working after the token, or the person who owns it, is gone.

I hit most of these while connecting GitHub billing to Unsave, the cloud cost and security tool I build, and every command here runs against the public GitHub REST API.


The Billing Endpoints and Who Can Call Them

GitHub's billing usage API has a few endpoints, and the enterprise ones are the ones most people need:

EndpointReturns
GET /enterprises/{enterprise}/settings/billing/usageItemized usage for the enterprise, one row per product, SKU and day
GET /enterprises/{enterprise}/settings/billing/usage/summaryUsage totals across the enterprise
GET /organizations/{org}/settings/billing/usageItemized usage for a single organization

There are also separate endpoints for Copilot premium requests and AI credits, but they're detail views. Adding them on top of the usage report counts the same spend twice, which I covered in GitHub's billed amount is a calendar month.

All of these belong to GitHub's enhanced billing platform. If your enterprise is still on the older billing system, these endpoints aren't available yet. Check Billing and licensing in your enterprise settings before you debug anything else.

Who can call the enterprise endpoints. According to GitHub's docs, the caller must be one of these:

  • An enterprise owner or billing manager
  • An organization owner of an organization in the enterprise
  • A custom role holder with fine-grained read access to enterprise billing
  • A GitHub App installed on the enterprise with the Enterprise billing read permission

Which tokens work. This is where most 403s come from:

Token typeWorks for enterprise billing?
Personal access token (classic) with manage_billing:enterpriseYes
Fine-grained personal access tokenNo. These endpoints aren't in GitHub's list of endpoints fine-grained tokens can call.
GitHub App installation token with Enterprise billing: readYes
GitHub CLI token from gh auth loginYes, once you add the manage_billing:enterprise scope

Two conditions have to be true at the same time: the token needs the right permission, and the person who owns it needs the right role. A classic token with manage_billing:enterprise that belongs to someone who isn't an owner or billing manager still gets a 403.


Diagnose Before You Fix

Don't guess. One request with the response headers saved tells you which problem you have. Set your enterprise slug and token, then run:

export GITHUB_ENTERPRISE="your-enterprise-slug"
export GITHUB_TOKEN="your-token"

curl -sS -D headers.txt -o usage.json -w "HTTP %{http_code}\n" \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2026-03-10" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  "https://api.github.com/enterprises/$GITHUB_ENTERPRISE/settings/billing/usage"

grep -iE '^(x-oauth-scopes|x-accepted-oauth-scopes|x-github-sso|x-accepted-github-permissions|github-authentication-token-expiration):' headers.txt

The enterprise slug is the part of your enterprise URL after /enterprises/, for example github.com/enterprises/contoso. The status code is printed first, and then whichever of these headers came back:

HeaderWhat it tells you
x-oauth-scopesThe scopes your classic token actually has
x-accepted-oauth-scopesThe scopes this endpoint accepts
x-github-ssoYour token isn't approved for an organization's SAML single sign-on, with a link to fix it
x-accepted-github-permissionsThe permissions a fine-grained token or GitHub App would need
github-authentication-token-expirationWhen the token expires. No header means it never expires.

Here's an example of what a token with a missing scope looks like:

HTTP 403
x-oauth-scopes: read:org, repo
x-accepted-oauth-scopes: manage_billing:enterprise
github-authentication-token-expiration: 2026-12-01 18:00:00 UTC

The token has read:org and repo, the endpoint wants manage_billing:enterprise, and the cause is Fix 1 below. Read the headers, find the matching fix, and skip the rest.


Fix 1: The Token Is Missing the Billing Scope

Symptom: a 403, and x-oauth-scopes doesn't include manage_billing:enterprise (or admin:enterprise, which includes it).

For a classic personal access token:

  • Go to Settings > Developer settings > Personal access tokens > Tokens (classic).
  • Open the token and tick manage_billing:enterprise.
  • Select Update token. The token value stays the same, so you don't need to replace it anywhere.

If you're testing with the GitHub CLI, add the scope to its token instead:

gh auth refresh -h github.com -s manage_billing:enterprise
gh api /enterprises/$GITHUB_ENTERPRISE/settings/billing/usage --jq '.usageItems | length'

The second command prints the number of usage rows. If it prints a number instead of an error, the scope was the problem.

Pro tip: Give the token only manage_billing:enterprise, plus read:org if your code also lists organizations. It doesn't need repo or admin:enterprise to read billing, and a narrow token is a much smaller problem if it leaks.


Fix 2: Your Account Doesn't Have a Billing Role

Symptom: a 403, even though x-oauth-scopes includes manage_billing:enterprise.

The token is fine, but the person who owns it can't see billing. Being an ordinary member of the enterprise, or even an owner of an organization outside it, isn't enough. An enterprise owner can make that person a billing manager, the narrowest role that can read billing:

  • Go to your enterprise and select People.
  • Under People, select Administrators.
  • Select Invite admin and find the person.
  • Choose Billing Manager and select Send Invitation.

The invitation has to be accepted before the role applies. If your enterprise uses Enterprise Managed Users, roles are assigned from your identity provider instead, so ask whoever manages it.

Warning: Don't make someone an enterprise owner just to unblock a billing report. Owners can change everything in the enterprise. Billing manager covers what a cost integration needs.


Fix 3: You're Using a Fine-Grained Token

Symptom: a 403, often with the message Resource not accessible by personal access token, and no x-oauth-scopes header, because that header only applies to classic tokens.

Fine-grained personal access tokens are the token type GitHub recommends for most things, which is why people reach for them first. But the enterprise billing usage endpoints aren't among the endpoints fine-grained tokens can call, so no combination of permissions will make one work.

You have two options:

  • A classic token with manage_billing:enterprise, as in Fix 1. Quickest, but it belongs to a person.
  • A GitHub App with the Enterprise billing permission, as in Fix 5. More setup, but it doesn't belong to a person.

Fix 4: The Token Isn't Approved for SAML Single Sign-On

Symptom: a 403 or a 404 when your organization uses SAML single sign-on (SSO), often with an x-github-sso header.

With SAML SSO, a classic personal access token has to be authorized for each organization that enforces it, separately from having the right scopes. GitHub's docs say an unauthorized token can get a 404 Not Found as well as a 403 Forbidden, which is why this one is so confusing: a 404 makes you check the enterprise name, when the name is fine.

To authorize a classic token:

  • Go to Settings > Developer settings > Personal access tokens > Tokens (classic).
  • Next to the token, select Configure SSO.
  • Next to the organization, select Authorize, and complete the sign-in with your identity provider.

If Configure SSO doesn't appear, sign in through your identity provider at least once first, by visiting https://github.com/orgs/ORG-NAME/sso.

There's also a shortcut. When the response is a 403, the x-github-sso header contains a URL that authorizes that token directly:

x-github-sso: required; url=https://github.com/orgs/contoso/sso?authorization_request=...

Open it in a browser while signed in as the token's owner. The link expires after one hour, so use it straight away.

Gotcha: A token used across several organizations can fail without an error. If some of them enforce SSO and the token isn't authorized for them, GitHub returns results only from the organizations it can see, and adds a header like x-github-sso: partial-results; organizations=21955855,20582480. You get a 200, the numbers are quietly incomplete, and the only clue is that header. Check for it in your code, not just the status code.

Gotcha: If your enterprise uses both an IP allow list and SSO, the IP address you authorize the token from must also be allowed at the enterprise level.

See which tokens are authorized

Organization owners can list every credential authorized for SSO in their organization, with its scopes, when it was last used and when it expires:

curl -sS \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2026-03-10" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  "https://api.github.com/orgs/YOUR-ORG/credential-authorizations"

This list is worth checking regularly anyway. It shows tokens that were authorized years ago and never used since, and tokens belonging to people who've left. You can revoke one with DELETE /orgs/YOUR-ORG/credential-authorizations/CREDENTIAL_ID.


Fix 5: Use a GitHub App Instead of a Personal Token

Every fix so far keeps a personal token alive, and personal tokens have a problem that has nothing to do with GitHub: people leave. When the owner of the token behind your billing report leaves the company, their account is removed, the token stops working, and the report goes blank.

A GitHub App installed on the enterprise avoids that, because it doesn't belong to anyone:

  • Create a GitHub App, owned by your enterprise or by an organization in it.
  • Under its permissions, set Enterprise billing to Read-only.
  • Install it on the enterprise.
  • Your integration signs in as the app and requests an installation access token to call the billing endpoints.

Installation access tokens last about an hour and are created on demand, so there's no long-lived token to rotate or leak. They also act as the app, not as a person, so there's no personal token to authorize for SSO. You may need an active SSO session when you install the app, but not afterwards.

The trade-off is setup. A GitHub App needs a private key and a little code to exchange it for installation tokens, where a classic token is a single string. For a one-off report, a classic token is fine. For anything that runs unattended for months, use an app.


Not a 403: The Numbers Are Too Low

Sometimes the call succeeds and the problem is the data. There are three common causes.

Cost centers. GitHub's docs say the enterprise /usage endpoint returns, by default, only usage that doesn't have a cost center. If your enterprise assigns organizations or repositories to cost centers, that spend is missing from the default response. You have two ways to get all of it:

# Totals across every cost center
gh api "/enterprises/$GITHUB_ENTERPRISE/settings/billing/usage/summary"

# Itemized rows for one cost center at a time
gh api "/enterprises/$GITHUB_ENTERPRISE/settings/billing/cost-centers" --jq '.costCenters[] | .id + "  " + .name'
gh api "/enterprises/$GITHUB_ENTERPRISE/settings/billing/usage?cost_center_id=COST_CENTER_ID"

For itemized data, call /usage once with no cost center and once for each cost center, then add the results together.

Silent SSO gaps. This is the partial-results header from Fix 4. Some organizations are simply missing from the response.

The date window. GitHub bills by UTC calendar month. A dashboard that shows "the last 30 days", or uses local time, will never match the invoice. I wrote a whole post on that: GitHub's billed amount is a calendar month.


Keep It Working

Most billing integrations don't break on day one. They break months later, when a token expires or its owner leaves. A few habits prevent that.

Read the expiry header on every call. GitHub returns github-authentication-token-expiration on requests made with an expiring token, in a format like 2026-12-01 18:00:00 UTC. If the header is missing, the token never expires, and that's a real state worth recording, not "unknown." Parse it as UTC:

export const TOKEN_EXPIRY_HEADER = "github-authentication-token-expiration";

// GitHub sends `2026-12-01 18:00:00 UTC`. Without the "Z", JavaScript treats
// the time as local, which can move the expiry date by a day.
export function parseTokenExpiryHeader(raw: string | null | undefined): Date | null {
  if (!raw) return null;
  const m = /^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})(?:\s*UTC)?$/.exec(raw.trim());
  if (!m) {
    const parsed = new Date(raw);
    return Number.isNaN(parsed.getTime()) ? null : parsed;
  }
  const parsed = new Date(`${m[1]}T${m[2]}Z`);
  return Number.isNaN(parsed.getTime()) ? null : parsed;
}

Warn early. I warn 45 days before a token expires, not 7. Rotating your own token takes a minute, but when the token belongs to someone else, you need time to reach them, get a new token and get it authorized for SSO again.

Test with the endpoint you actually use. A token that can call GET /user isn't proof it can read billing. Make the health check call the billing endpoint itself, and treat a 403 as a broken connection. Don't show $0: an empty month and a broken token should never look the same.

Know whose token it is. Record who owns the token. When that person changes roles or leaves, replace it before it breaks, or move to a GitHub App.


Quick Reference

SymptomLikely causeFix
403, x-accepted-oauth-scopes: manage_billing:enterpriseToken missing the billing scopeFix 1: add manage_billing:enterprise
403, token has the scopeOwner isn't an enterprise owner or billing managerFix 2: make them a billing manager
403, no x-oauth-scopes headerFine-grained tokenFix 3: use a classic token or a GitHub App
403 or 404 with x-github-ssoToken not authorized for SAML SSOFix 4: Configure SSO, then Authorize
200, x-github-sso: partial-resultsSome organizations not authorizedFix 4, for each listed organization
200, totals too lowCost centers, or a non-calendar date windowUse /usage/summary, or query each cost center
Works, then stops months laterToken expired, or its owner leftWatch the expiry header, or use a GitHub App

The Bigger Lesson

GitHub billing access isn't one permission. It's three separate checks: the token needs the right scope, the person behind it needs the right role, and, with SAML SSO, the token has to be authorized for each organization. A connection that passes one check can still fail the others, and GitHub's errors don't tell you which one failed.

So read the response headers before changing anything, give the token only the billing scope it needs, and for anything that runs unattended, use a GitHub App so the report doesn't depend on any one person's token.

Recommended Readings