lfnovo/open-notebook · error · HTTPException

Failed to create credential

Error message

Failed to create credential

What it means

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.

Source

Thrown at api/routers/credentials.py:207

            endpoint_llm=request.endpoint_llm,
            endpoint_embedding=request.endpoint_embedding,
            endpoint_stt=request.endpoint_stt,
            endpoint_tts=request.endpoint_tts,
            project=request.project,
            location=request.location,
            credentials_path=request.credentials_path,
            num_ctx=request.num_ctx,
        )
        await cred.save()
        return credential_to_response(cred, 0)

    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error creating credential: {e}")
        raise HTTPException(status_code=500, detail="Failed to create credential")


@router.get("/{credential_id}", response_model=CredentialResponse)
async def get_credential(credential_id: str):
    """Get a specific credential by ID. Never returns api_key."""
    try:
        cred = await Credential.get(credential_id)
        models = await cred.get_linked_models()
        return credential_to_response(cred, len(models))
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error fetching credential {credential_id}: {e}")
        raise HTTPException(status_code=404, detail="Credential not found")

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Confirm OPEN_NOTEBOOK_ENCRYPTION_KEY is set in the API process environment
  2. Check logs for 'Error creating credential: ...' to see the real exception
  3. Verify the DB is up and migrations ran (API startup logs)
  4. Retry the POST with the same payload once infrastructure is confirmed healthy
Defensive patterns

Strategy: validation

Validate before calling

// before creating, confirm required fields and a unique provider+slug
if (!payload.api_key || !payload.provider) throw new Error('api_key and provider are required');
const existing = await api.listCredentials();
if (existing.some(c => c.provider === payload.provider && c.slug === payload.slug)) {
  // update instead of create
}

Try / catch

try {
  const cred = await api.createCredential(payload);
} catch (e) {
  if (e.status === 500) showError('Could not save credential — check API logs and encryption key');
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: OPEN_NOTEBOOK_ENCRYPTION_KEY missing in the API environment (credentials are encrypted at rest), DB unreachable, or API restart needed after adding the key.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/1df4d05b279cf298. Report an issue: GitHub.