Skip to main content

Personal provider connections

Some providers license access per person rather than per company. GitHub Copilot is the provider the gateway supports this way today. Instead of one shared token that everybody's requests go through, an admin creates a credential marked as per-user, each user connects their own account to it once, and from then on their requests to models on that credential use their own access. The gateway stores each user's token encrypted, and refuses requests from users who have not connected.

What this is for​

Shared tokens break per-seat licensing and make it impossible to tell who used what. Personal connections keep the convenience of one gateway, one model name and one virtual key per user, while the provider still sees each person's own account. When someone leaves, their connection is removed and nobody else is affected.

Scenario​

An engineering team has GitHub Copilot seats and wants to reach Copilot models through the gateway, with budgets, logging and guardrails like every other model. The admin creates one per-user credential and one model on it. Each engineer opens the Admin UI once, connects their account by entering a short code on the provider's device page, and then uses the gateway with their own virtual key. An engineer who moves teams clicks Disconnect.

Steps​

  1. Create the per-user credential (admin). In the Admin UI open Models + Endpoints, pick the Add Model tab, choose GitHub Copilot as the Provider, set Auth Type: to Per-user GitHub OAuth and click Create credential. The add credential dialog opens with the provider fixed, so give it the Credential Name copilot-engineering and click Add Credential. From the command line:

    curl -X POST http://localhost:4000/credentials \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{
    "credential_name": "copilot-engineering",
    "display_name": "Copilot, engineering",
    "credential_values": {"github_copilot_auth_type": "per_user_oauth"},
    "credential_info": {"custom_llm_provider": "github_copilot"}
    }'
  2. Add a model on it (admin). Still on the Add Model tab, pick the model, make sure Existing Credentials shows copilot-engineering, and click Add Model. From the command line:

    curl -X POST http://localhost:4000/model/new \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{
    "model_name": "copilot-sonnet",
    "spanway_params": {"model": "github_copilot/claude-sonnet-5.5", "spanway_credential_name": "copilot-engineering"}
    }'
  3. Connect your account (each user). Open Models + Endpoints, pick the LLM Credentials tab and find the credential under Your connections. Its Status reads Not connected. Click Connect. The Connect GitHub Copilot dialog shows a verification link and a code, with a Copy code button. Open the link, enter the code, approve the request, and the dialog changes to Connected as @your-login. Click Done. From the command line, start the flow with the key of the user who is connecting:

    curl -X POST http://localhost:4000/credentials/copilot-engineering/user_connection/start \
    -H "Authorization: Bearer $SPANWAY_USER_KEY"

    Show the user_code to the user and send them to verification_uri. Then poll with the returned flow_handle every interval seconds until the status is no longer pending:

    curl -X POST http://localhost:4000/credentials/copilot-engineering/user_connection/poll \
    -H "Authorization: Bearer $SPANWAY_USER_KEY" -H "Content-Type: application/json" \
    -d '{"flow_handle": "gAAAAABpH3...encrypted-flow-handle"}'
  4. Use the model (each user). Send requests with your own virtual key. The key must belong to your user, because the gateway looks up the connection by user.

    curl -X POST http://localhost:4000/v1/chat/completions \
    -H "Authorization: Bearer $SPANWAY_USER_KEY" -H "Content-Type: application/json" \
    -d '{"model": "copilot-sonnet", "messages": [{"role": "user", "content": "Explain this stack trace"}]}'
  5. Check or remove a connection. Your connections lists every per-user credential with Connected as @login or Not connected, and Disconnect removes yours right away. From the command line:

    curl http://localhost:4000/credentials/user_connections -H "Authorization: Bearer $SPANWAY_USER_KEY"
    curl -X DELETE http://localhost:4000/credentials/copilot-engineering/user_connection \
    -H "Authorization: Bearer $SPANWAY_USER_KEY"

Expected result​

The start call answers with the code, the provider's device page, how long the code is valid and how often to poll:

{
"user_code": "WDJB-MJHT",
"verification_uri": "<the provider's device login page>",
"expires_in": 899,
"interval": 5,
"flow_handle": "gAAAAABpH3...encrypted-flow-handle"
}

Each poll answers {"status": "pending", "interval": 5} until the user approves, then {"status": "connected", "github_login": "octocat"}. The connection list then shows the connection.

{
"connections": [
{
"credential_name": "copilot-engineering",
"provider": "github_copilot",
"connected": true,
"github_login": "octocat",
"connected_at": "2026-11-20T09:12:00+00:00"
}
]
}

The user's requests to copilot-sonnet succeed with their own access. Disconnecting answers {"status": "disconnected"}, and the next request from that user on the credential is refused until they connect again.

How it works​

The flow_handle is the pending device code, encrypted and bound to the user and the credential, so the poll can land on any gateway instance. The gateway stores the user's token encrypted in the database and keeps a short lived copy in its cache. Disconnecting writes a tombstone to the cache before deleting the row, so a cached token cannot keep working after the user disconnects. Deleting the credential, or changing it so it is no longer per-user, removes every user's connection under it. A master key rotation and the encryption migration re-encrypt the stored tokens too.

Audit​

Connecting writes a created audit row on Spanway_UserProviderCredentials, disconnecting a deleted row, and the purge after a credential delete one deleted row per removed connection. The object id is <credential name>:<user id>, and the row holds the provider and the account login (github_login), never the token. See audit logs.

Errors​

What you seeWhyFix
404 Credential not found on start, poll or deleteThe name is wrong, or the credential is not marked per-user with github_copilot_auth_type: per_user_oauth.Check the name under Your connections, or edit the credential's auth type.
401 An authenticated user is requiredThe key is not tied to a user, such as the master key.Use a virtual key that belongs to a user.
400 invalid or expired flow_handleThe handle was issued to another user or credential, was altered, or its code expired.Start again to get a new code.
status: expired or status: deniedThe code ran out before approval, or the user declined the request. The dialog says "The device code expired before it was approved. Start again to get a new code."Click Start again.
status: no_copilot_seatThe account was approved but has no GitHub Copilot access, so nothing was saved.Get a seat on that account, or connect a different account.
429The provider rate limited the device flow.Wait and poll again at the returned interval.
502 saying the device flow completed without a tokenThe provider approved the code but returned no token.Start again. If it repeats, contact support@spanway.ai.
503 could not revoke cached connection, retry or ...the cache could not be refreshedThe gateway's cache was unavailable while writing the connection state.Retry the call once the cache is back.
500 DB not connected. This endpoint needs a databaseThe gateway has no database, so it cannot store a connection.Set DATABASE_URL.
A model call fails with Connect GitHub Copilot for credential '<name>' in the Spanway UI (LLM Credentials)The user never connected an account for that credential.Open Your connections and click Connect.
A model call fails with an authentication error that says the provider rejected the GitHub Copilot connection for credential '<name>' and asks you to reconnectThe stored token was revoked, or the account lost access, so the token exchange answered 401, 403 or 404.Open Your connections, click Disconnect and then Connect again.

Logs​

LevelMessageMeaningAction
WARNINGinvalidate_user_provider_credential_cache: Redis tombstone failedA disconnect could not mark the cached token as gone, so the row was kept and the caller got 503.Check Redis, then disconnect again.
WARNINGset_user_provider_credential_cache: Redis set failed; falling back to deleteA new connection could not be written to the cache, so the old entry was deleted instead.Normal during a short Redis outage.
WARNINGaget_user_provider_tokens: Redis get failed; falling back to the databaseThe cache was unreachable, so the token was read from the database.Normal during a short Redis outage, check Redis if it repeats.
ERROR_purge_user_connections_for_credential: failed to drop user connections for <name>The connections under a deleted credential could not be removed.Delete them again by deleting and re-creating the credential, or check the database.