Skip to content

Save (or replace) the BYOK key for a provider.

PUT
/api/advisor/provider-keys/{providerId}
curl --request PUT \
--url https://api.tradr.cloud/api/advisor/provider-keys/claude \
--header 'Content-Type: application/json' \
--data '{ "apiKey": "example", "defaultModel": "example" }'

Encrypts the supplied key at rest (AES-256-GCM, REQ-5.1) and stores only the ciphertext plus a last-4-char masking hint — the plaintext is never persisted or returned (REQ-5.7). Runs a lightweight validation roundtrip against the provider’s listModels endpoint (REQ-5.8, 5s timeout): a 401/403 rejects the save with PROVIDER_KEY_INVALID; a successful probe returns verified: true; a timeout or transient failure stores the key anyway and returns verified: false. Rate limited to 10 saves per user per hour (REQ-5.9). defaultModel is optional — when omitted (a first-time save has no model list to pick from), the server selects the provider’s deterministic default from the probe’s listModels response (REQ-6.4); the user can change it later.

providerId
required
string
Allowed values: claude openai
Media typeapplication/json
object
apiKey
required
string
>= 8 characters
defaultModel
string
>= 1 characters <= 64 characters
Examplegenerated
{
"apiKey": "example",
"defaultModel": "example"
}

The stored key (ProviderKeyListItem) plus verified: boolean.

Validation error or PROVIDER_KEY_INVALID (key rejected by provider).

Save rate limit reached (10 / hour).