{"record":{"id":"f25bea9a27dbd9e2","repo":"langflow-ai/langflow","slug":"str-exc-f25bea","errorCode":null,"errorMessage":"str(exc)","messagePattern":"str\\(exc\\)","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/backend/base/langflow/api/v1/api_key.py","lineNumber":27,"sourceCode":"# Assuming you have these methods in your service layer\nfrom langflow.services.database.models.api_key.crud import create_api_key, delete_api_key, get_api_keys\nfrom langflow.services.database.models.api_key.model import ApiKeyCreate, UnmaskedApiKeyRead\nfrom langflow.services.deps import get_settings_service\n\nrouter = APIRouter(tags=[\"APIKey\"], prefix=\"/api_key\")\n\n\n@router.get(\"/\", include_in_schema=False)\nasync def get_api_keys_route(\n    db: DbSession,\n    current_user: CurrentActiveUser,\n) -> ApiKeysResponse:\n    try:\n        user_id = current_user.id\n        api_keys = await get_api_keys(db, user_id)\n        return ApiKeysResponse(total_count=len(api_keys), user_id=user_id, api_keys=api_keys)\n    except Exception as exc:\n        raise HTTPException(status_code=400, detail=str(exc)) from exc\n\n\n@router.post(\"/\", include_in_schema=False)\nasync def create_api_key_route(\n    req: ApiKeyCreate,\n    current_user: CurrentActiveUser,\n    db: DbSession,\n) -> UnmaskedApiKeyRead:\n    try:\n        user_id = current_user.id\n        return await create_api_key(db, req, user_id=user_id)\n    except PermissionError as e:\n        raise HTTPException(status_code=403, detail=str(e)) from e\n    except Exception as e:\n        raise HTTPException(status_code=400, detail=str(e)) from e\n\n\n@router.delete(\"/{api_key_id}\", include_in_schema=False)","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/api_key.py#L9-L45","documentation":"Raised by GET /api/v1/api_keys/ as a catch-all: any unexpected exception while listing the current user's API keys (database errors, ORM issues, deserialization problems) is converted to HTTP 400 with the raw exception text as detail. It requires an authenticated user (CurrentActiveUser), so 401 happens earlier at the dependency. The 400 status is misleading for server-side faults but the detail string usually names the real cause.","triggerScenarios":"GET /api/v1/api_keys/ when the underlying get_api_keys call throws — DB connectivity loss, schema mismatch after a partial migration, or an unexpected value in the api_key table.","commonSituations":"DB migration drift where the api_key table shape doesn't match the ORM model; transient database outage surfacing as 400; running a frontend built against a newer API than the backend.","solutions":["Read the detail string — it contains the underlying exception message; fix that root cause","Run migrations (make alembic-upgrade) if the error mentions missing columns/tables","Verify DB connectivity and that the api_key table matches the current model; restart after fixing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    keys = client.get(\"/api/v1/api_keys/\").json()\nexcept HTTPStatusError as e:\n    if e.response.status_code == 400:\n        log.error(\"api_keys listing failed: %s\", e.response.json().get(\"detail\"))\n        alert_ops(\"api_keys route degraded\")   # usually a backend/DB fault, not client error\n        raise\n    raise","preventionTips":["Treat 400 from this read-only listing as a server-side signal — inspect detail, don't mutate the request","Run alembic upgrades before pointing clients at a new backend","Monitor this route; it should never fail on a healthy deployment"],"tags":["api-key","http-400","database","catch-all"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}