Credential management API
This page documents the 13 gateway endpoints tagged credential management in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| GET | /credentials | List stored credentials with masked values |
| POST | /credentials | Create a reusable provider credential |
| GET | /credentials/by_name/{credential_name} | Get one credential by name |
| GET | /credentials/{credential_name}/jwks | Export the public JWKS of an internal issuer credential |
| GET | /credentials/by_model/{model_id} | Get the masked credential values a deployment uses |
| GET | /credentials/user_connections | List your personal provider connections |
| POST | /credentials/{credential_name}/user_connection/start | Start connecting your own provider account |
| POST | /credentials/{credential_name}/user_connection/poll | Poll a personal connection once |
| DELETE | /credentials/{credential_name}/user_connection | Disconnect your own provider account |
| PATCH | /credentials/{credential_name} | Update a stored credential |
| DELETE | /credentials/{credential_name} | Delete a stored credential |
| POST | /credentials/migrate-encryption | Re-encrypt stored secrets as AES-256-GCM |
| GET | /credentials/migrate-encryption/check | Count stored secrets still in the legacy encryption format |
Endpoints
GET /credentials
List stored credentials with masked values
List every credential loaded on this gateway. Secret values are masked, and source says whether a
credential was saved from the API or Admin UI (db) or defined in config.yaml (config).
Example request:
curl -X GET "http://localhost:4000/credentials" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Every credential the gateway knows, from the database and from config.yaml, with secrets masked. | application/json CredentialListResponse |
| 401 | Authentication Error, Invalid proxy server token passed. Create key via /key/generate call. | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Success |
credentials | array of CredentialView | Yes | Credentials |
POST /credentials
Create a reusable provider credential
Store a named set of provider values, such as an API key, API base or region, once, so many model
deployments can reference it with spanway_credential_name instead of carrying their own copy.
Send credential_values directly, or send model_id to copy the values an existing deployment uses.
Secrets are encrypted before they reach the database and come back masked on every read.
Request body (application/json, schema CreateCredentialItem):
| Field | Type | Required | Description |
|---|---|---|---|
credential_name | string | Yes | Credential Name |
display_name | string or null | No | Display Name |
credential_info | object | Yes | Credential Info |
credential_values | object or null | No | Credential Values |
model_id | string or null | No | Model Id |
Example request:
curl -X POST "http://localhost:4000/credentials" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"credential_name": "anthropic-prod",
"display_name": "Anthropic production",
"credential_values": {
"api_key": "sk-ant-api03-your-anthropic-key"
},
"credential_info": {
"custom_llm_provider": "anthropic"
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The credential is stored encrypted and loaded on every gateway instance. | application/json CredentialWriteResponse |
| 400 | Credential values are required. Unable to infer credential values from model ID. or display_name cannot be blank. Send null to clear it or omit the field to leave it unchanged. or display_name cannot be longer than 255 characters. or display_name cannot contain control, formatting, or line separator characters. | application/json ProxyError |
| 403 | Only proxy admins can change 'anthropic_federation_rule_id', a server-owned workload identity federation or OAuth token exchange parameter. | application/json ProxyError |
| 409 | Credential 'anthropic-prod' already exists. Update it with PATCH /credentials/anthropic-prod, or delete it first. or Credential 'anthropic-prod' is defined in config. Edit config.yaml to change it. | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Success |
message | string | Yes | Message |
GET /credentials/by_name/{credential_name}
Get one credential by name
Read one credential by its name. Secret values keep their first four characters and are otherwise masked, which is enough to tell two keys apart without revealing either.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded; may contain slashes |
Example request:
curl -X GET "http://localhost:4000/credentials/by_name/credential_name-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The credential with its secret values masked. | application/json CredentialView |
| 404 | Credential not found. Got credential name: anthropic-prod | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
credential_name | string | Yes | Credential Name |
display_name | string or null | No | Display Name |
credential_info | object | Yes | Credential Info |
credential_values | object | Yes | Credential Values |
source | enum: "db", "config" | Yes | Source |
GET /credentials/{credential_name}/jwks
Export the public JWKS of an internal issuer credential
Export the public JWKS for an anthropic internal_issuer credential, so the operator can
register it on the Anthropic federation issuer from the UI. Never touches the private signing
key: only its derived public JWKS leaves this process. 404s for any other credential shape.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded; may contain slashes |
Example request:
curl -X GET "http://localhost:4000/credentials/credential_name-123/jwks" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The public key set to register on the provider's federation rule. | application/json JwksDocument |
| 400 | The identity token signing key reference could not be resolved. | application/json ProxyError |
| 403 | Only proxy admins can export a credential's JWKS. | application/json ProxyError |
| 404 | No anthropic credential named 'anthropic-prod'. | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
keys | array of object | Yes | Keys |
GET /credentials/by_model/{model_id}
Get the masked credential values a deployment uses
Show, masked, the provider values one deployment calls its provider with, whether they were typed into
the deployment or inherited from a named credential. Useful before turning them into a reusable credential
with POST /credentials and model_id.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
model_id | path | string | Yes | The model ID to look up credentials for |
Example request:
curl -X GET "http://localhost:4000/credentials/by_model/model_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The deployment's provider values, masked, under a generated credential name. | application/json CredentialItem |
| 404 | Model not found | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | LLM router not found | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
credential_name | string | Yes | Credential Name |
display_name | string or null | No | Display Name |
credential_info | object | Yes | Credential Info |
credential_values | object | Yes | Credential Values |
GET /credentials/user_connections
List your personal provider connections
List every credential on this gateway that uses each caller's own provider account, and whether you have
connected yours. connected is false until you complete the device flow for that credential.
Example request:
curl -X GET "http://localhost:4000/credentials/user_connections" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | One row per credential that needs a personal connection, with your connection state on each. | application/json UserProviderConnectionsResponse |
| 401 | An authenticated user is required | application/json ProxyError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
connections | array of UserProviderConnection | Yes | Connections |
POST /credentials/{credential_name}/user_connection/start
Start connecting your own provider account
Begin a device flow that links your own provider account to a per-user credential. Show the returned
user_code to the user, send them to verification_uri, then call the poll route every interval
seconds with flow_handle until it answers connected. The handle is encrypted and bound to you.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded |
Request body (application/json, object):
Example request:
curl -X POST "http://localhost:4000/credentials/credential_name-123/user_connection/start" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The code to enter on the provider's device page and the handle to poll with. | application/json UserConnectionStartResponse |
| 401 | An authenticated user is required | application/json ProxyError |
| 404 | Credential not found | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
user_code | string | Yes | User Code |
verification_uri | string | Yes | Verification Uri |
expires_in | integer | Yes | Expires In |
interval | integer | Yes | Interval |
flow_handle | string | Yes | Flow Handle |
POST /credentials/{credential_name}/user_connection/poll
Poll a personal connection once
Ask the provider once whether the user approved the device code. On approval the gateway checks the account
has a seat, stores the connection for you and answers connected. no_copilot_seat means the account was
approved but has no access, so nothing was saved. expired and denied end the flow, start again for a
new code.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded |
Request body (application/json, schema UserConnectionPollRequest):
| Field | Type | Required | Description |
|---|---|---|---|
flow_handle | string | Yes | Flow Handle |
Example request:
curl -X POST "http://localhost:4000/credentials/credential_name-123/user_connection/poll" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"flow_handle": "gAAAAABpH3...encrypted-flow-handle"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The flow state. pending and slow_down mean keep polling, every other status ends the flow. | application/json UserConnectionPollResponse |
| 400 | invalid or expired flow_handle | application/json ProxyError |
| 401 | An authenticated user is required | application/json ProxyError |
| 404 | Credential not found | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 429 | The provider rate limited the device flow. Wait before polling again. | application/json ProxyError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
| 502 | OAuth device flow completed without a token | application/json ProxyError |
| 503 | The upstream service connection saved, but the cache could not be refreshed; requests may be rejected for up to 60 seconds | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | enum: "pending", "slow_down", "expired", "denied", "connected", "no_copilot_seat" | Yes | Status |
interval | integer or null | No | Interval |
github_login | string or null | No | the upstream service Login |
DELETE /credentials/{credential_name}/user_connection
Disconnect your own provider account
Remove your stored connection for a per-user credential and stop any cached token from being used. Safe to call when nothing is connected. Your next request to a model on that credential is refused until you connect again.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded |
Example request:
curl -X DELETE "http://localhost:4000/credentials/credential_name-123/user_connection" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Your stored connection is gone. | application/json UserConnectionDeleteResponse |
| 401 | An authenticated user is required | application/json ProxyError |
| 404 | Credential not found | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
| 503 | could not revoke cached connection, retry | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | string | Yes | Status |
PATCH /credentials/{credential_name}
Update a stored credential
Change the values, display name or info of a stored credential. Only the fields you send change, and
credential_values_to_delete removes stored keys. The name itself is fixed. Changing where a secret is sent,
such as api_base, requires sending the secret again in the same request, otherwise the update is refused.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded; may contain slashes |
Request body (application/json, schema UpdateCredentialItem):
| Field | Type | Required | Description |
|---|---|---|---|
credential_name | string or null | No | Credential Name |
display_name | string or null | No | Display Name |
credential_info | object | Yes | Credential Info |
credential_values | object or null | No | Credential Values |
model_id | string or null | No | Model Id |
credential_values_to_delete | array of string or null | No | Credential Values To Delete |
Example request:
curl -X PATCH "http://localhost:4000/credentials/credential_name-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"display_name": "Anthropic production",
"credential_values": {
"api_key": "sk-ant-api03-your-rotated-key"
},
"credential_info": {
"custom_llm_provider": "anthropic"
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The stored values are merged with the ones you sent and reloaded in memory. | application/json CredentialWriteResponse |
| 400 | credential_name is immutable. Set display_name to change how the credential is labeled. or credential_values_to_delete overlaps credential_values for key(s): ['api_key'] or display_name cannot be blank. Send null to clear it or omit the field to leave it unchanged. or display_name cannot be longer than 255 characters. or display_name cannot contain control, formatting, or line separator characters. | application/json ProxyError |
| 403 | Only proxy admins can change 'anthropic_federation_rule_id', a server-owned workload identity federation or OAuth token exchange parameter. | application/json ProxyError |
| 404 | Credential not found in DB. | application/json ProxyError |
| 405 | Credential 'anthropic-prod' is defined in config and cannot be edited from the API or UI. | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Success |
message | string | Yes | Message |
DELETE /credentials/{credential_name}
Delete a stored credential
Delete a credential saved through the API or Admin UI. Deployments that reference it by
spanway_credential_name stop resolving it, and every user's personal connection under it is dropped.
A credential defined in config.yaml cannot be deleted here, edit the file instead.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
credential_name | path | string | Yes | The credential name, percent-decoded; may contain slashes |
Example request:
curl -X DELETE "http://localhost:4000/credentials/credential_name-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The credential and every personal connection under it are removed. | application/json CredentialWriteResponse |
| 403 | Only proxy admins can change 'anthropic_federation_rule_id', a server-owned workload identity federation or OAuth token exchange parameter. | application/json ProxyError |
| 404 | Credential not found. Got credential name: anthropic-prod | application/json ProxyError |
| 405 | Credential 'anthropic-prod' is defined in config and cannot be edited from the API or UI. | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
success | boolean | Yes | Success |
message | string | Yes | Message |
POST /credentials/migrate-encryption
Re-encrypt stored secrets as AES-256-GCM
Upgrade every secret the gateway stores in its database, such as provider keys, SSO settings, team callback settings and config environment variables, from the legacy encryption format to AES-256-GCM. Only proxy admins may call it, and general_settings.encryption_algorithm must be set to aes-256-gcm first.
Safe to run again: values already migrated are skipped, and values that cannot be decrypted, because they
were written with a different master or salt key, are counted as undecryptable and left untouched.
dry_run=true reports what would change without writing anything. A real run writes an audit row with the
counts, and a storage location the gateway cannot read stops the run with a 503 instead of counting as clean.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
dry_run | query | boolean | No | If true, scan and report without writing any changes. |
Request body (application/json, object):
Example request:
curl -X POST "http://localhost:4000/credentials/migrate-encryption" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | What was scanned and rewritten per storage location. residual_legacy is 0 when nothing is left. | application/json EncryptionMigrationResponse |
| 400 | Encryption migration requires general_settings.encryption_algorithm: 'aes-256-gcm'. Current value: None. Set it before migrating so re-encrypted values are written in the AES-256-GCM format. or Cannot migrate covered tables: no salt key / master key is set. Set SPANWAY_SALT_KEY before migrating. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Admin-only endpoint. Not allowed to access this. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ErrorDetail |
| 503 | Could not read credentials: connection refused. The scan stopped, so this run attests nothing. Fix the database connection and run it again. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | "success" | Yes | Status |
dry_run | boolean | Yes | Dry Run |
report | EncryptionReport | Yes |
GET /credentials/migrate-encryption/check
Count stored secrets still in the legacy encryption format
Count the stored secrets still in the legacy encryption format, for example as evidence for a compliance
review after a migration. Only proxy admins may call it, and nothing changes. residual_legacy is the number
of values still in the legacy format, so 0 shows that no legacy ciphertext remains. A storage location the
gateway cannot read answers 503, so a database problem never reads as a clean result.
Example request:
curl -X GET "http://localhost:4000/credentials/migrate-encryption/check" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The same report as the migration, from a read-only scan. | application/json EncryptionCheckResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | Admin-only endpoint. Not allowed to access this. | application/json ErrorDetail |
| 500 | DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keys | application/json ErrorDetail |
| 503 | Could not read credentials: connection refused. The scan stopped, so this run attests nothing. Fix the database connection and run it again. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | "success" | Yes | Status |
report | EncryptionReport | Yes |