The LLM Key Management endpoints let you securely store encrypted LLM provider API keys in your Stratus account. These are optional — Formation provides a shared OpenRouter pool that handles all requests automatically when no native key is configured.Storing your own key bypasses the Formation pool entirely: you pay your provider directly and the 25% pool markup is not applied.
Key Resolution Priority: Stratus checks for keys in this order: (1) inline request headers, (2) vault-stored keys, (3) Formation’s pool. See Authentication - Key Resolution Priority for a full breakdown.
1. User provides LLM keys → 2. Stratus validates → 3. Encrypt with AES-256-GCM → 4. Store in Vault ↓5. User makes request → 6. Retrieve from cache/vault → 7. Decrypt → 8. Use to call LLM provider
Vault Connection Required: These endpoints require active Vault connection. Check /health endpoint to verify vault: "connected" before use.
Store encrypted LLM provider API keys. All fields are optional — provide any combination of the providers you want to use. Omitted keys remain unchanged.
OpenRouter API key (format: sk-or-*) — used as a native BYOK OpenRouter key. Bypasses Formation’s pool key entirely.
All fields are optional. You can supply any combination. Omitted keys remain unchanged (or unset if this is your first call). If no keys are stored, Formation’s shared pool handles requests automatically.
async function onboardUserLLMKeys(stratusKey: string) { // LLM keys are optional — Formation pool works out of the box. // Offer this as an upgrade path to remove the 25% markup. const openaiKey = await promptUser('Enter your OpenAI API key (optional — removes pool markup):'); const anthropicKey = await promptUser('Enter your Anthropic API key (optional):'); if (!openaiKey && !anthropicKey) { // Totally fine — Formation pool will be used automatically console.log('No keys provided. Formation pool will handle requests (25% markup applies).'); return; } // Store provided keys const response = await fetch('https://api.stratus.run/v1/account/llm-keys', { method: 'POST', headers: { 'Authorization': `Bearer ${stratusKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ ...(openaiKey && { openai_key: openaiKey }), ...(anthropicKey && { anthropic_key: anthropicKey }) }) }); const result = await response.json(); if (result.success) { console.log('Keys stored securely. Pool markup removed for stored providers.'); } else { console.error('Failed to store keys'); }}