POST Save Provider API Key

abstract

Save or update an LLM provider's API key — validates the key is non-empty, encrypts it, stores it in llm_provider_configs, and caches the masked hint for display.

🔒 Authentication

PropertyValue
MechanismNone
RequiredNo

🛠️ Technical Specification

Request

ParameterLocationTypeRequiredDescription
providerPathstringYesOne of: openai, gemini, anthropic, openrouter, ollama
api_keyBodystringYesFull API key to store

Pydantic Schema: backend/api/routes/settings.py :: SaveProviderRequest

Logic Flow

📦 Request Body

{
  "api_key": "sk-ant-api03-..."
}

📤 Responses

StatusWhenBody
200 OKKey savedProviderStatus
400 Bad RequestInvalid provider name{ "detail": "Invalid provider: xyz" }
422 Unprocessable EntityEmpty api_key{ "detail": [...] }

200 OK example:

{
  "provider": "anthropic",
  "is_configured": true,
  "is_active": true,
  "key_hint": "sk-...cdef"
}

Pydantic Schema: backend/api/routes/settings.py :: ProviderStatus

RolePath
Routerbackend/api/routes/settings.py
Securitybackend/core/security.py :: encrypt(), _mask_key()
DB TableDB - llm_provider_configs
MethodPathPurpose
GET/api/v1/settings/providersList all provider statuses (with hints, no keys)
POST/api/v1/settings/providers/{provider}/testTest provider connection
POST/api/v1/settings/task-assignmentsSave task→model mappings
GET/api/v1/settings/task-assignmentsGet current task assignments
PUT/api/v1/settings/globalUpdate global settings (maintenance, pipeline toggles)
GET/api/v1/settings/globalGet global settings
PUT/api/v1/settings/riskUpdate risk management rules
PUT/api/v1/settings/telegramUpdate Telegram bot config