{"record":{"id":"8d24e9537e5c2a01","repo":"unclecode/crawl4ai","slug":"invalid-limit-limit-must-be-between-1-and-1000","errorCode":null,"errorMessage":"Invalid limit: {limit}. Must be between 1 and 1000","messagePattern":"Invalid limit: (.+?)\\. Must be between 1 and 1000","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"deploy/docker/monitor_routes.py","lineNumber":38,"sourceCode":"        return await monitor.get_health_summary()\n    except Exception as e:\n        logger.error(f\"Error getting health: {e}\")\n        raise HTTPException(500, str(e))\n\n\n@router.get(\"/requests\")\nasync def get_requests(status: str = \"all\", limit: int = 50):\n    \"\"\"Get active and completed requests.\n\n    Args:\n        status: Filter by 'active', 'completed', 'success', 'error', or 'all'\n        limit: Max number of completed requests to return (default 50)\n    \"\"\"\n    # Input validation\n    if status not in [\"all\", \"active\", \"completed\", \"success\", \"error\"]:\n        raise HTTPException(400, f\"Invalid status: {status}. Must be one of: all, active, completed, success, error\")\n    if limit < 1 or limit > 1000:\n        raise HTTPException(400, f\"Invalid limit: {limit}. Must be between 1 and 1000\")\n\n    try:\n        monitor = get_monitor()\n\n        if status == \"active\":\n            return {\"active\": monitor.get_active_requests(), \"completed\": []}\n        elif status == \"completed\":\n            return {\"active\": [], \"completed\": monitor.get_completed_requests(limit)}\n        elif status in [\"success\", \"error\"]:\n            return {\"active\": [], \"completed\": monitor.get_completed_requests(limit, status)}\n        else:  # \"all\"\n            return {\n                \"active\": monitor.get_active_requests(),\n                \"completed\": monitor.get_completed_requests(limit)\n            }\n    except Exception as e:\n        logger.error(f\"Error getting requests: {e}\")\n        raise HTTPException(500, str(e))","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/deploy/docker/monitor_routes.py#L20-L56","documentation":"GET /monitor/requests enforces 1 <= limit <= 1000, raising HTTPException(400, 'Invalid limit: ...') otherwise. The cap bounds how many completed-request records the monitor copies out of its ring buffer per call.","triggerScenarios":"?limit=0, ?limit=-5, ?limit=1001, or a non-integer value that FastAPI itself rejects; string limits like ?limit=50.0 also fail FastAPI's int parsing.","commonSituations":"Dashboards requesting 'all' history with limit=100000; pagination math producing 0 on the last page; reusing a page-size constant from another API with a different cap.","solutions":["Clamp client-side: limit = max(1, min(limit, 1000)).","Paginate with multiple calls if you need more than 1000 records.","Remember the default is 50 — omit the param when that suffices."],"exampleFix":"# before\nGET /monitor/requests?limit=5000\n\n# after\nGET /monitor/requests?limit=1000  (page through for more)","handlingStrategy":"validation","validationCode":"def safe_limit(n: int) -> int:\n    return max(1, min(int(n), 1000))","typeGuard":"def is_valid_limit(n) -> bool:\n    return isinstance(n, int) and 1 <= n <= 1000","tryCatchPattern":null,"preventionTips":["Clamp page-size constants to the 1000 cap at the client.","Handle 'first page empty' correctly so pagination math never yields 0.","Paginate with repeated calls instead of oversized single limits."],"tags":["http-400","validation","pagination","monitoring"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}