Skip to content
Latchkey

NuGet "Unable to load the service index ... 401" Private Feed in CI

The feed answered, but with 401 Unauthorized - NuGet reached the index endpoint and was rejected for lack of valid credentials. This is an auth problem: the runner has no token, an expired token, or the wrong username/password for the private feed. A managed self-healing runner will not fix a bad credential - 401 is deterministic until the token is corrected.

What this error means

Restore fails with "Unable to load the service index ... Response status code 401". It reproduces every run with the same credential - re-running does not help until the token is fixed.

dotnet
error : Unable to load the service index for source
https://nuget.pkg.github.com/contoso/index.json.
error :   Response status code does not indicate success: 401 (Unauthorized).

Common causes

No credentials were provided to the runner

The feed requires auth but the runner's nuget.config has no packageSourceCredentials, or the token env var is empty in CI.

The token is expired or wrong

A PAT expired, was rotated, or lacks read scope on the feed, so the feed rejects the request.

How to fix it

Provide a valid token from CI secrets

  1. Store the feed token as a CI secret and inject it into the environment.
  2. Reference it from nuget.config credentials, never inline plaintext.
  3. Re-run restore once the token is present.
nuget.config
<packageSourceCredentials>
  <github>
    <add key="Username" value="contoso-ci" />
    <add key="ClearTextPassword" value="${{ secrets.NUGET_TOKEN }}" />
  </github>
</packageSourceCredentials>

Rotate or re-scope the token

  1. Issue a new PAT with read (and the right package) scope on the feed.
  2. Update the CI secret with the new value.
  3. Confirm the token has not hit an org SSO/authorization requirement.

How to prevent it

  • Track PAT expiry and rotate before it lapses.
  • Grant the token the minimum scope the feed needs (package read).
  • Keep credentials in CI secrets, never committed to the repo.

Frequently asked questions

What causes ""... service index ... (401)""?
The feed requires auth but the runner's nuget.config has no packageSourceCredentials, or the token env var is empty in CI.
How do I fix "... service index ... (401)"?
Provide a valid token from CI secrets

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card