Skip to content

Reference

Explore

The explore endpoints of the HTTP API.

POST /datasources/{uid}/query

Run one query against a datasource and return its frames.

The query runs as given against the datasource in the path, with the time and user macros expanded for the range and no variables. kind instant returns rows (log lines, table rows, spans) over exactly the given range, and range returns series over the range aligned to its step. The query runs with the agent tools’ limits (15 seconds, 200 series for metric queries, 100,000 points, 1,000 rows; log lines count against the row limit only), and limit lowers the row limit. Nothing is cached, and the call counts against the caller’s 8 in-flight query requests. Every call is recorded in the audit trail as query.run with the query text (cut at 4 KiB), the range and the row count, once per caller, datasource, query text and period in 10 minutes when it succeeds; a failed or refused call is recorded every time. Viewers and above may call it, service-account keys included. from and to take relative expressions such as now-1h, epoch milliseconds or RFC 3339 times, fractional seconds included. The response has the shape of panel data, with meta.cached always false. meta.truncated says the query stopped at the row limit, meta.partial that the datasource did not cover the whole range, and meta.oldest and meta.newest are the time edges of the rows returned. To load older rows, repeat the request with to set to meta.oldest; to load newer rows, with from set to meta.newest. On Loki end is exclusive and start inclusive, so the oldest line is not repeated and the newest one is; on ClickHouse $__timeFilter includes both ends. Clients de-duplicate by time plus body. page_size turns paging on for an instant query on a logs or trace datasource, and the response then carries meta.page: ClickHouse pages by offset with an exact total, so any page can be asked for directly; Loki and Tempo page by a time cursor, so a page past the first needs the next cursor of the page before it, and total is the rows walked so far (gte) until the last page makes it exact. prev is the cursor that produced the page. sort orders the whole result of a ClickHouse query before it is paged, not just the page; send it with every page of a walk. The SQL views of the ClickHouse logs and trace searches both run here, with the same checks for either table: one read-only SELECT, the time range read through a macro such as $__timeFilter(Timestamp) when the query selects no Timestamp, and the limits above. Without page_size a ClickHouse query must read the time range through a macro even when it selects Timestamp, because only a paged query is cut to the range by the server; a macro inside a comment does not count. With a cursor the time range is pinned from it and from and to are ignored; without one, send absolute times for a stable total.

Parameters

Name In Type Description
uid (required) path string

Request body

application/json, required.

Field Type Description
query (required) string
kind (required) "range", "instant"
from (required) string
to (required) string
timezone string The browser’s IANA time zone, used to resolve relative times such as now/d.
max_data_points integer Range queries only: the most points per series, 200 by default as for the query_range MCP tool. The step never falls below a Prometheus datasource’s scrapeInterval. Between 10 and 11000. Default 200.
limit integer The most rows the query may return; lowers the 1,000 row limit. Cannot be sent with page_size. Between 1 and 1000.
page_size integer Rows per page; turns paging on. Instant queries on logs and trace datasources only, and not with limit. Between 50 and 500.
page integer The page to read. Needs page_size. On ClickHouse any page can be asked for; on Loki and Tempo a page above 1 needs cursor, and the page is then the cursor’s. Default 1.
cursor string The next or prev value of an earlier page of the same query. Needs page_size. A cursor from another datasource, query or range is refused, and so is one whose sort differs from the one sent with it.
sort string A result column to sort the whole result by before it is paged, with a leading minus for descending, such as -Duration. Needs page_size, applies to ClickHouse only and answers 422 query_invalid when the column is not in the result. Without it rows come newest first.
as_written boolean ClickHouse only: returns the rows as the query wrote them, with its own ORDER BY, LIMIT and columns and no TimeNs field, even when it selects Timestamp; a LIMIT above page_size is paged and never raised, and the query must read the time range through a macro such as $__timeFilter(Timestamp). Without it a query that selects Timestamp comes back as log lines, newest first. Needs page_size. Default false.

Responses

Status Description Body
200 The frames the query returned. PanelData
400 The request is malformed or fails validation (invalid_request), or the query is longer than 64 KiB (query_too_long). PanelDataError
401 Authentication is missing or invalid. Error
404 The datasource does not exist (not_found). PanelDataError
413 The request body exceeds the size limit. Error
422 The query cannot run: query_invalid, query_forbidden, limit_exceeded (also for a response over 32 MiB) or unknown_macro; on Tempo also time_range_in_future for a range that starts after now and time_range_too_long for a range over Tempo’s search limit, 7 days by default, with the limit in the text; the body carries no ref. PanelDataError
429 The caller already has the maximum number of query requests in flight, or the server’s shared upstream call slots stayed busy for 5 seconds. Error
500 The server failed to handle the request, including a datasource call that failed without a classified cause. PanelDataError
502 The datasource is unavailable. PanelDataError
504 The datasource did not answer within the 15 second query timeout, or the request did not finish within 20 seconds. PanelDataError

POST /datasources/{uid}/log-volume

Count the log lines a logs query matches over a range, by level.

The counts cover every line the query matches over the whole range, not only the lines the logs page shows. The server picks a whole-second step of at least one second so the range fits in at most buckets buckets, aligns the range to it, adds one more bucket when the end of the range falls inside a step so the newest lines are counted, and returns every bucket, oldest first. Loki, ClickHouse, Elasticsearch and OpenSearch datasources answer it. Each line is filed as error, warning, info or other by its level word: err, eror, error, emerg, fatal, alert, crit, critical and panic are errors; warn and warning are warnings; info, information, informational and notice are info; anything else, or no level, is other. For Loki the query must be a log query that starts with a stream selector; the server counts it with count_over_time by the first of the level, lvl, severity_text, severity and detected_level labels, so a pipeline that extracts level with | json or | logfmt is honored. Loki counts a range longer than a day one day at a time, newest first, and counts a bucket wider than 30 minutes as the sum of equal windows of at most 30 minutes, because Loki reads a much wider window far more slowly; when the next day would not finish within the query time limit, the server stops, returns the days it counted with partial true and counted_from set to where the count starts, and leaves the older buckets at zero. For ClickHouse the query must be one SELECT; the server drops its top-level ORDER BY and LIMIT and groups the rows it matches by the result columns Timestamp and SeverityText, the columns the logs page selects. The query runs with the agent tools’ limits, nothing is cached, and the call counts against the caller’s 8 in-flight query requests. Viewers and above may call it, service-account keys included. from and to take relative expressions such as now-1h, epoch milliseconds or RFC 3339 times.

Parameters

Name In Type Description
uid (required) path string

Request body

application/json, required.

Field Type Description
query (required) string The query the logs page runs.
from (required) string
to (required) string
buckets integer The most buckets wanted. Between 1 and 200. Default 60.

Responses

Status Description Body
200 The line counts by level per bucket. LogVolume
400 The request is malformed or fails validation, buckets is out of range, or the datasource is not Loki or ClickHouse (invalid_request), or the query is longer than 64 KiB (query_too_long). PanelDataError
401 Authentication is missing or invalid. Error
404 The datasource does not exist (not_found). PanelDataError
413 The request body exceeds the size limit. Error
422 The query cannot run: query_invalid for a Loki metric query, a ClickHouse query with a top-level UNION, INTERSECT, EXCEPT or LIMIT BY, or an upstream rejection such as an unknown column; query_forbidden, limit_exceeded or unknown_macro as for the explore query; the body carries no ref. PanelDataError
429 The caller already has the maximum number of query requests in flight, or the server’s shared upstream call slots stayed busy for 5 seconds. Error
500 The server failed to handle the request, including a datasource call that failed without a classified cause. PanelDataError
502 The datasource is unavailable. PanelDataError
504 The datasource did not answer within the 15 second query timeout, or the request did not finish within 20 seconds. PanelDataError

Generated from api/openapi.yaml at c770e5e0. Report a problem.

Reading this as an agent? Every page is in /llms.txt and /llms-full.txt as plain text.

/observeOpen source under Apache-2.0.Grafana is a trademark of Grafana Labs. Elasticsearch and Kibana are trademarks of Elasticsearch B.V. OpenSearch is a trademark of LF Projects, LLC. SlashObserve is not affiliated with or endorsed by any of them.

Search pages and headings.