unclecode/crawl4ai · error · HTTPException

Invalid limit: {limit}. Must be between 1 and 1000

Error message

Invalid limit: {limit}. Must be between 1 and 1000

What it means

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.

Source

Thrown at deploy/docker/monitor_routes.py:38

        return await monitor.get_health_summary()
    except Exception as e:
        logger.error(f"Error getting health: {e}")
        raise HTTPException(500, str(e))


@router.get("/requests")
async def get_requests(status: str = "all", limit: int = 50):
    """Get active and completed requests.

    Args:
        status: Filter by 'active', 'completed', 'success', 'error', or 'all'
        limit: Max number of completed requests to return (default 50)
    """
    # Input validation
    if status not in ["all", "active", "completed", "success", "error"]:
        raise HTTPException(400, f"Invalid status: {status}. Must be one of: all, active, completed, success, error")
    if limit < 1 or limit > 1000:
        raise HTTPException(400, f"Invalid limit: {limit}. Must be between 1 and 1000")

    try:
        monitor = get_monitor()

        if status == "active":
            return {"active": monitor.get_active_requests(), "completed": []}
        elif status == "completed":
            return {"active": [], "completed": monitor.get_completed_requests(limit)}
        elif status in ["success", "error"]:
            return {"active": [], "completed": monitor.get_completed_requests(limit, status)}
        else:  # "all"
            return {
                "active": monitor.get_active_requests(),
                "completed": monitor.get_completed_requests(limit)
            }
    except Exception as e:
        logger.error(f"Error getting requests: {e}")
        raise HTTPException(500, str(e))

View on GitHub (pinned to 7e80152142)

Solutions

  1. Clamp client-side: limit = max(1, min(limit, 1000)).
  2. Paginate with multiple calls if you need more than 1000 records.
  3. Remember the default is 50 — omit the param when that suffices.

Example fix

# before
GET /monitor/requests?limit=5000

# after
GET /monitor/requests?limit=1000  (page through for more)
Defensive patterns

Strategy: validation

Validate before calling

def safe_limit(n: int) -> int:
    return max(1, min(int(n), 1000))

Type guard

def is_valid_limit(n) -> bool:
    return isinstance(n, int) and 1 <= n <= 1000

Prevention

When it happens

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

Common situations: 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.

Related errors


AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14). Data as JSON: /api/errors/8d24e9537e5c2a01. Report an issue: GitHub.