langflow-ai/langflow · warning · HTTPException
Cannot request logs before and after the timestamp
Error message
Cannot request logs before and after the timestamp
What it means
HTTP 400 from GET /api/v1/logs when both lines_before and lines_after query parameters are > 0. The API only supports paging in one direction from a timestamp at a time; asking for both sides of the timestamp in one request is rejected.
Source
Thrown at src/backend/base/langflow/api/log_router.py:92
@log_router.get("/logs", dependencies=[Depends(get_current_active_superuser)])
async def logs(
lines_before: Annotated[int, Query(description="The number of logs before the timestamp or the last log")] = 0,
lines_after: Annotated[int, Query(description="The number of logs after the timestamp")] = 0,
timestamp: Annotated[int, Query(description="The timestamp to start getting logs from")] = 0,
):
"""Retrieve application logs with superuser authentication required.
SECURITY: Logs may contain sensitive information and require superuser authentication.
"""
global log_buffer # noqa: PLW0602
if log_buffer.enabled() is False:
raise HTTPException(
status_code=HTTPStatus.NOT_IMPLEMENTED,
detail="Log retrieval is disabled",
)
if lines_after > 0 and lines_before > 0:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail="Cannot request logs before and after the timestamp",
)
if timestamp <= 0:
if lines_after > 0:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail="Timestamp is required when requesting logs after the timestamp",
)
content = log_buffer.get_last_n(10) if lines_before <= 0 else log_buffer.get_last_n(lines_before)
elif lines_before > 0:
content = log_buffer.get_before_timestamp(timestamp=timestamp, lines=lines_before)
elif lines_after > 0:
content = log_buffer.get_after_timestamp(timestamp=timestamp, lines=lines_after)
else:
content = log_buffer.get_before_timestamp(timestamp=timestamp, lines=10)
return JSONResponse(content=content)
View on GitHub (pinned to 976ec789d2)
Solutions
- Split into two requests: one with lines_before, one with lines_after
- Fetch before and after pages separately and merge client-side
- If you need a continuous window, request get_last_n semantics by omitting timestamp with lines_before only
Example fix
# before GET /api/v1/logs?timestamp=1700000000&lines_before=10&lines_after=10 # 400 # after GET /api/v1/logs?timestamp=1700000000&lines_before=10 GET /api/v1/logs?timestamp=1700000000&lines_after=10
Defensive patterns
Strategy: validation
Validate before calling
const url = new URL('/api/v1/logs', base);
if (linesBefore > 0) url.searchParams.set('lines_before', linesBefore);
if (linesAfter > 0 && !linesBefore) { url.searchParams.set('lines_after', linesAfter); url.searchParams.set('timestamp', ts); } Try / catch
try { ... } catch (e) { if (e.response?.status === 400 && /before and after/.test(e.detail)) { return merge(await getBefore(ts), await getAfter(ts)); } throw e; } Prevention
- Never send lines_before and lines_after together
- Build query params conditionally, defaulting omitted params to 0
- Unit-test log-viewer queries against the param matrix
When it happens
Trigger: Calling /api/v1/logs?lines_before=10&lines_after=10 (optionally with timestamp) as superuser with the log buffer enabled.
Common situations: UI log viewers trying to fetch a context window around a timestamp in a single request; ported client code assuming a 'range' query API.
Related errors
- Timestamp is required when requesting logs after the timesta
- Failed to install MCP
- No supported files found in folder. Allowed types: ${types?.
- File type ${fileExtension} not allowed. Allowed types: ${typ
- Invalid path
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/246b675b2f7ea6ef.
Report an issue: GitHub.