query_range
Run a LogQL range query across a time window to search logs, tail a service, or graph metric expressions. Returns raw Loki JSON results without modifying data.
Instructions
Run a LogQL range query against Loki, returning results across a time window.
This is the tool to reach for when reading logs: searching for errors, tailing a service over the last hour, or graphing a metric expression over time. Use query instead when a single point-in-time value is enough. If the selector is unknown, call labels and label_values first.
Returns the raw Loki JSON response: {"status","data":{"resultType","result"}}, where resultType is "streams" for log selectors and "matrix" for metric expressions. Loki truncates at limit entries, so a full result set may mean logs were cut off; narrow start/end or tighten the selector rather than raising limit. Read-only: it never writes to or mutates Loki.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | No | End of the time range, RFC3339 or Unix nanoseconds. Defaults to now. | |
| limit | No | Maximum log entries to return. Applies to log selectors only; metric expressions ignore it. Defaults to 100, must not exceed 5000. | |
| query | Yes | LogQL expression. Log example: {app="nginx"} |= "error" | json. Metric example: sum by (app) (rate({app="nginx"}[5m])). | |
| start | No | Start of the time range, RFC3339 (2026-03-25T10:00:00Z) or Unix nanoseconds. Defaults to 1 hour ago. | |
| direction | No | Order of returned log entries: backward (newest first, the default) or forward (oldest first). With backward and a hit limit, you keep the newest entries. |