{"record":{"id":"1df4d05b279cf298","repo":"lfnovo/open-notebook","slug":"failed-to-create-credential","errorCode":null,"errorMessage":"Failed to create credential","messagePattern":"Failed to create credential","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/credentials.py","lineNumber":207,"sourceCode":"            endpoint_llm=request.endpoint_llm,\n            endpoint_embedding=request.endpoint_embedding,\n            endpoint_stt=request.endpoint_stt,\n            endpoint_tts=request.endpoint_tts,\n            project=request.project,\n            location=request.location,\n            credentials_path=request.credentials_path,\n            num_ctx=request.num_ctx,\n        )\n        await cred.save()\n        return credential_to_response(cred, 0)\n\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error creating credential: {e}\")\n        raise HTTPException(status_code=500, detail=\"Failed to create credential\")\n\n\n@router.get(\"/{credential_id}\", response_model=CredentialResponse)\nasync def get_credential(credential_id: str):\n    \"\"\"Get a specific credential by ID. Never returns api_key.\"\"\"\n    try:\n        cred = await Credential.get(credential_id)\n        models = await cred.get_linked_models()\n        return credential_to_response(cred, len(models))\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error fetching credential {credential_id}: {e}\")\n        raise HTTPException(status_code=404, detail=\"Credential not found\")\n\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/credentials.py#L189-L225","documentation":"Catch-all 500 from POST /api/credentials when creating a credential fails with an unexpected exception — e.g. DB write failure, encryption error, or an unvalidated field combination reaching domain code.","triggerScenarios":"POST /api/credentials with a valid-looking payload while SurrealDB is down, when the encryption key env var is unset so the secret cannot be encrypted, or when a duplicate/invalid provider+slug combination trips lower-level code.","commonSituations":"OPEN_NOTEBOOK_ENCRYPTION_KEY missing in the API environment (credentials are encrypted at rest), DB unreachable, or API restart needed after adding the key.","solutions":["Confirm OPEN_NOTEBOOK_ENCRYPTION_KEY is set in the API process environment","Check logs for 'Error creating credential: ...' to see the real exception","Verify the DB is up and migrations ran (API startup logs)","Retry the POST with the same payload once infrastructure is confirmed healthy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before creating, confirm required fields and a unique provider+slug\nif (!payload.api_key || !payload.provider) throw new Error('api_key and provider are required');\nconst existing = await api.listCredentials();\nif (existing.some(c => c.provider === payload.provider && c.slug === payload.slug)) {\n  // update instead of create\n}","typeGuard":null,"tryCatchPattern":"try {\n  const cred = await api.createCredential(payload);\n} catch (e) {\n  if (e.status === 500) showError('Could not save credential — check API logs and encryption key');\n  throw e;\n}","preventionTips":["Ensure OPEN_NOTEBOOK_ENCRYPTION_KEY is set before the first credential is created","Check for an existing credential with the same provider/slug before POSTing"],"tags":["credentials","create","encryption","http-500"],"backgroundTag":"http-500-fallback","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}