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
-
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-engineeringand 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"}}' -
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"}}' -
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_codeto the user and send them toverification_uri. Then poll with the returnedflow_handleeveryintervalseconds until the status is no longerpending: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"}' -
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"}]}' -
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 see | Why | Fix |
|---|---|---|
404 Credential not found on start, poll or delete | The 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 required | The 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_handle | The 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: denied | The 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_seat | The account was approved but has no GitHub Copilot access, so nothing was saved. | Get a seat on that account, or connect a different account. |
429 | The provider rate limited the device flow. | Wait and poll again at the returned interval. |
502 saying the device flow completed without a token | The 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 refreshed | The 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 database | The 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 reconnect | The 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
| Level | Message | Meaning | Action |
|---|---|---|---|
| WARNING | invalidate_user_provider_credential_cache: Redis tombstone failed | A disconnect could not mark the cached token as gone, so the row was kept and the caller got 503. | Check Redis, then disconnect again. |
| WARNING | set_user_provider_credential_cache: Redis set failed; falling back to delete | A new connection could not be written to the cache, so the old entry was deleted instead. | Normal during a short Redis outage. |
| WARNING | aget_user_provider_tokens: Redis get failed; falling back to the database | The 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. |
Related
- Setting provider credentials, shared credentials and the resolution order.
- Models + Endpoints page, the LLM Credentials tab and the connect dialog.
- GitHub Copilot provider, model names and the shared sign in option.
- Per-user MCP credentials, the same idea for MCP servers.
- Virtual keys, keys tied to a user.
- Credential management API reference.