Skip to main content

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.

MethodPathSummary
GET/credentialsList stored credentials with masked values
POST/credentialsCreate a reusable provider credential
GET/credentials/by_name/{credential_name}Get one credential by name
GET/credentials/{credential_name}/jwksExport 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_connectionsList your personal provider connections
POST/credentials/{credential_name}/user_connection/startStart connecting your own provider account
POST/credentials/{credential_name}/user_connection/pollPoll a personal connection once
DELETE/credentials/{credential_name}/user_connectionDisconnect your own provider account
PATCH/credentials/{credential_name}Update a stored credential
DELETE/credentials/{credential_name}Delete a stored credential
POST/credentials/migrate-encryptionRe-encrypt stored secrets as AES-256-GCM
GET/credentials/migrate-encryption/checkCount 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:

StatusDescriptionBody
200Every credential the gateway knows, from the database and from config.yaml, with secrets masked.application/json CredentialListResponse
401Authentication Error, Invalid proxy server token passed. Create key via /key/generate call.application/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
successbooleanYesSuccess
credentialsarray of CredentialViewYesCredentials

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):

FieldTypeRequiredDescription
credential_namestringYesCredential Name
display_namestring or nullNoDisplay Name
credential_infoobjectYesCredential Info
credential_valuesobject or nullNoCredential Values
model_idstring or nullNoModel 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:

StatusDescriptionBody
200The credential is stored encrypted and loaded on every gateway instance.application/json CredentialWriteResponse
400Credential 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
403Only proxy admins can change 'anthropic_federation_rule_id', a server-owned workload identity federation or OAuth token exchange parameter.application/json ProxyError
409Credential '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
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
successbooleanYesSuccess
messagestringYesMessage

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:

NameInTypeRequiredDescription
credential_namepathstringYesThe 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:

StatusDescriptionBody
200The credential with its secret values masked.application/json CredentialView
404Credential not found. Got credential name: anthropic-prodapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
credential_namestringYesCredential Name
display_namestring or nullNoDisplay Name
credential_infoobjectYesCredential Info
credential_valuesobjectYesCredential Values
sourceenum: "db", "config"YesSource

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:

NameInTypeRequiredDescription
credential_namepathstringYesThe 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:

StatusDescriptionBody
200The public key set to register on the provider's federation rule.application/json JwksDocument
400The identity token signing key reference could not be resolved.application/json ProxyError
403Only proxy admins can export a credential's JWKS.application/json ProxyError
404No anthropic credential named 'anthropic-prod'.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
keysarray of objectYesKeys

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:

NameInTypeRequiredDescription
model_idpathstringYesThe 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:

StatusDescriptionBody
200The deployment's provider values, masked, under a generated credential name.application/json CredentialItem
404Model not foundapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500LLM router not foundapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
credential_namestringYesCredential Name
display_namestring or nullNoDisplay Name
credential_infoobjectYesCredential Info
credential_valuesobjectYesCredential 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:

StatusDescriptionBody
200One row per credential that needs a personal connection, with your connection state on each.application/json UserProviderConnectionsResponse
401An authenticated user is requiredapplication/json ProxyError
500DB 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_keysapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
connectionsarray of UserProviderConnectionYesConnections

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:

NameInTypeRequiredDescription
credential_namepathstringYesThe 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:

StatusDescriptionBody
200The code to enter on the provider's device page and the handle to poll with.application/json UserConnectionStartResponse
401An authenticated user is requiredapplication/json ProxyError
404Credential not foundapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
user_codestringYesUser Code
verification_uristringYesVerification Uri
expires_inintegerYesExpires In
intervalintegerYesInterval
flow_handlestringYesFlow 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:

NameInTypeRequiredDescription
credential_namepathstringYesThe credential name, percent-decoded

Request body (application/json, schema UserConnectionPollRequest):

FieldTypeRequiredDescription
flow_handlestringYesFlow 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:

StatusDescriptionBody
200The flow state. pending and slow_down mean keep polling, every other status ends the flow.application/json UserConnectionPollResponse
400invalid or expired flow_handleapplication/json ProxyError
401An authenticated user is requiredapplication/json ProxyError
404Credential not foundapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
429The provider rate limited the device flow. Wait before polling again.application/json ProxyError
500DB 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_keysapplication/json ProxyError
502OAuth device flow completed without a tokenapplication/json ProxyError
503The upstream service connection saved, but the cache could not be refreshed; requests may be rejected for up to 60 secondsapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
statusenum: "pending", "slow_down", "expired", "denied", "connected", "no_copilot_seat"YesStatus
intervalinteger or nullNoInterval
github_loginstring or nullNothe 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:

NameInTypeRequiredDescription
credential_namepathstringYesThe 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:

StatusDescriptionBody
200Your stored connection is gone.application/json UserConnectionDeleteResponse
401An authenticated user is requiredapplication/json ProxyError
404Credential not foundapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ProxyError
503could not revoke cached connection, retryapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
statusstringYesStatus

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:

NameInTypeRequiredDescription
credential_namepathstringYesThe credential name, percent-decoded; may contain slashes

Request body (application/json, schema UpdateCredentialItem):

FieldTypeRequiredDescription
credential_namestring or nullNoCredential Name
display_namestring or nullNoDisplay Name
credential_infoobjectYesCredential Info
credential_valuesobject or nullNoCredential Values
model_idstring or nullNoModel Id
credential_values_to_deletearray of string or nullNoCredential 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:

StatusDescriptionBody
200The stored values are merged with the ones you sent and reloaded in memory.application/json CredentialWriteResponse
400credential_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
403Only proxy admins can change 'anthropic_federation_rule_id', a server-owned workload identity federation or OAuth token exchange parameter.application/json ProxyError
404Credential not found in DB.application/json ProxyError
405Credential 'anthropic-prod' is defined in config and cannot be edited from the API or UI.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
successbooleanYesSuccess
messagestringYesMessage

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:

NameInTypeRequiredDescription
credential_namepathstringYesThe 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:

StatusDescriptionBody
200The credential and every personal connection under it are removed.application/json CredentialWriteResponse
403Only proxy admins can change 'anthropic_federation_rule_id', a server-owned workload identity federation or OAuth token exchange parameter.application/json ProxyError
404Credential not found. Got credential name: anthropic-prodapplication/json ProxyError
405Credential 'anthropic-prod' is defined in config and cannot be edited from the API or UI.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
successbooleanYesSuccess
messagestringYesMessage

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:

NameInTypeRequiredDescription
dry_runquerybooleanNoIf 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:

StatusDescriptionBody
200What was scanned and rewritten per storage location. residual_legacy is 0 when nothing is left.application/json EncryptionMigrationResponse
400Encryption 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
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Admin-only endpoint. Not allowed to access this.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500DB 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_keysapplication/json ErrorDetail
503Could 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):

FieldTypeRequiredDescription
status"success"YesStatus
dry_runbooleanYesDry Run
reportEncryptionReportYes

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:

StatusDescriptionBody
200The same report as the migration, from a read-only scan.application/json EncryptionCheckResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Admin-only endpoint. Not allowed to access this.application/json ErrorDetail
500DB 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_keysapplication/json ErrorDetail
503Could 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):

FieldTypeRequiredDescription
status"success"YesStatus
reportEncryptionReportYes