{"record":{"id":"19b2d5e10a26941c","repo":"lfnovo/open-notebook","slug":"failed-to-register-models","errorCode":null,"errorMessage":"Failed to register models","messagePattern":"Failed to register models","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/credentials.py","lineNumber":463,"sourceCode":"        logger.error(f\"Error discovering models for credential {credential_id}: {e}\")\n        raise HTTPException(status_code=500, detail=\"Failed to discover models\")\n\n\n@router.post(\"/{credential_id}/register-models\", response_model=RegisterModelsResponse)\nasync def register_models_for_credential(\n    credential_id: str, request: RegisterModelsRequest\n):\n    \"\"\"Register discovered models and link them to this credential.\"\"\"\n    try:\n        result = await register_models(credential_id, request.models)\n        return RegisterModelsResponse(**result)\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error registering models for credential {credential_id}: {e}\")\n        raise HTTPException(status_code=500, detail=\"Failed to register models\")\n\n\n# =============================================================================\n# Migration endpoints\n# =============================================================================\n\n\n@router.post(\"/migrate-from-provider-config\")\nasync def migrate_from_provider_config():\n    \"\"\"Migrate existing ProviderConfig data to individual credential records.\"\"\"\n    try:\n        return await svc_migrate_from_provider_config()\n    except ValueError as e:\n        raise _handle_value_error(e)\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/credentials.py#L445-L481","documentation":"Catch-all 500 from POST /api/credentials/{credential_id}/register-models. Registration persists discovered model IDs as model records linked to the credential; unexpected DB write failures or model-construction errors land here.","triggerScenarios":"Submitting selected model IDs to register while the DB write fails, registering a model whose slug collides with an existing model record, or referencing stale discovered-model data.","commonSituations":"Registering models discovered in a previous session after the credential was updated, duplicate registration attempts, or DB briefly unavailable.","solutions":["Check logs for 'Error registering models for credential <id>: ...'","List existing models to detect slug/ID collisions; remove duplicates before retrying","Re-run discovery to get fresh model metadata, then register again","Confirm DB health and retry — registration is idempotent-ish once collisions are cleared"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const existing = await api.listModels();\nconst dups = requestedModelIds.filter(id => existing.some(m => m.matches(id)));\nif (dups.length) skipOrConfirm(dups); // avoid collisions before registering","typeGuard":null,"tryCatchPattern":"try {\n  await api.registerModels(credentialId, { models: selected });\n} catch (e) {\n  if (e.status === 500) { await api.listModels(); showError('Registration failed — check for duplicate models'); }\n  throw e;\n}","preventionTips":["Dedupe against existing model records before registering","Re-run discovery to get fresh metadata rather than reusing stale selections"],"tags":["credentials","model-registration","http-500"],"backgroundTag":"http-500-fallback","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}