--- title: Loki HTTP API menuTitle: HTTP API description: Loki exposes HTTP endpoints for data ingestion, data retrieval, as well for cluster management. aliases: - ../api/ weight: 100 --- # Loki HTTP API Loki exposes an HTTP API for pushing, querying, and tailing log data, as well as for viewing and managing cluster information. {{% admonition type="note" %}} Note that authorization is not part of the Loki API. Authorization needs to be done separately, for example, using an open-source load-balancer such as NGINX. {{% /admonition %}} ## Endpoints ### Ingest endpoints These endpoints are exposed by the `distributor`, `write`, and `all` components: - [`POST /loki/api/v1/push`](#ingest-logs) A [list of clients]({{< relref "../send-data" >}}) can be found in the clients documentation. ### Query endpoints {{% admonition type="note" %}} Requests sent to the query endpoints must use valid LogQL syntax. For more information, see the [LogQL]({{< relref "../query" >}}) section of the documentation. {{% /admonition %}} These HTTP endpoints are exposed by the `querier`, `query-frontend`, `read`, and `all` components: - [`GET /loki/api/v1/query`](#query-logs-at-a-single-point-in-time) - [`GET /loki/api/v1/query_range`](#query-logs-within-a-range-of-time) - [`GET /loki/api/v1/labels`](#query-labels) - [`GET /loki/api/v1/label//values`](#query-label-values) - [`GET /loki/api/v1/series`](#query-streams) - [`GET /loki/api/v1/index/stats`](#query-log-statistics) - [`GET /loki/api/v1/index/volume`](#query-log-volume) - [`GET /loki/api/v1/index/volume_range`](#query-log-volume) - [`GET /loki/api/v1/tail`](#stream-logs) ### Status endpoints These HTTP endpoints are exposed by all components and return the status of the component: - [`GET /ready`](#readiness-probe) - [`GET /log_level`](#change-log-level) - [`GET /metrics`](#prometheus-metrics) - [`GET /config`](#show-current-configuration) - [`GET /services`](#list-running-services) - [`GET /loki/api/v1/status/buildinfo`](#show-build-information) ### Ring endpoints These HTTP endpoints are exposed by their respective component that is part of the ring URL prefix: - [`GET /distributor/ring`](#distributor-ring-status) - [`GET /indexgateway/ring`](#index-gateway-ring-status) - [`GET /ruler/ring`](#ruler-ring-status) - [`GET /compactor/ring`](#compactor-ring-status) ### Flush/shutdown endpoints These HTTP endpoints are exposed by the `ingester`, `write`, and `all` components for flushing chunks and/or shutting down. - [`POST /flush`](#flush-in-memory-chunks-to-backing-store) - [`POST /ingester/prepare_shutdown`](#prepare-ingester-shutdown) - [`POST /ingester/shutdown`](#flush-in-memory-chunks-and-shut-down) ### Rule endpoints These HTTP endpoints are exposed by the `ruler` component: - [`GET /loki/api/v1/rules`](#list-rule-groups) - [`GET /loki/api/v1/rules/({namespace}`](#get-rule-groups-by-namespace) - [`GET /loki/api/v1/rules/{namespace}/{groupName}`](#get-rule-group) - [`POST /loki/api/v1/rules/{namespace}`](#set-rule-group) - [`DELETE /loki/api/v1/rules/{namespace}/{groupName}`](#delete-rule-group) - [`DELETE /loki/api/v1/rules/{namespace}`](#delete-namespace) - [`GET /api/prom/rules`](#list-rule-groups) - [`GET /api/prom/rules/{namespace}`](#get-rule-groups-by-namespace) - [`GET /api/prom/rules/{namespace}/{groupName}`](#get-rule-group) - [`POST /api/prom/rules/{namespace}`](#set-rule-group) - [`DELETE /api/prom/rules/{namespace}/{groupName}`](#delete-rule-group) - [`DELETE /api/prom/rules/{namespace}`](#delete-namespace) - [`GET /prometheus/api/v1/rules`](#list-rules) - [`GET /prometheus/api/v1/alerts`](#list-alerts) API endpoints starting with `/api/prom` are [Prometheus API-compatible](https://prometheus.io/docs/prometheus/latest/querying/api/) and the result formats can be used interchangeably. ### Log deletion endpoints These endpoints are exposed by the `compactor`, `backend`, and `all` components: - [`POST /loki/api/v1/delete`](#request-log-deletion) - [`GET /loki/api/v1/delete`](#list-log-deletion-requests) - [`DELETE /loki/api/v1/delete`](#request-cancellation-of-a-delete-request) ### Other endpoints These HTTP endpoints are exposed by all individual components: - [`GET /loki/api/v1/format_query`](#format-a-logql-query) ### Deprecated endpoints {{% admonition type="note" %}} The following endpoints are deprecated. While they still exist and work, they should not be used for new deployments. Existing deployments should upgrade to use the supported endpoints. {{% /admonition %}} | Deprecated | Replacement | | ---------- | ----------- | | `POST /api/prom/push` | [`POST /loki/api/v1/push`](#ingest-logs) | | `GET /api/prom/tail` | [`GET /loki/api/v1/tail`](#stream-logs) | | `GET /api/prom/query` | [`GET /loki/api/v1/query`](#query-logs-at-a-single-point-in-time) | | `GET /api/prom/label` | [`GET /loki/api/v1/labels`](#query-labels) | | `GET /api/prom/label//values` | [`GET /loki/api/v1/label//values`](#query-label-values) | | `GET /api/prom/series` | [`GET /loki/api/v1/series`](#query-streams) | ## Format ### Matrix, vector, and stream Some Loki API endpoints return a result of a matrix, a vector, or a stream: - **Matrix**: a table of values where each row represents a different label set and the columns are each sample values for that row over the queried time. Matrix types are only returned when running a query that computes some value. - **Instant Vector**: denoted in the type as just `vector`, an Instant Vector represents the latest value of a calculation for a given labelset. Instant Vectors are only returned when doing a query against a single point in time. - **Stream**: a Stream is a set of all values (logs) for a given label set over the queried time range. Streams are the only type that will result in log lines being returned. ### Timestamps The API accepts several formats for timestamps: * An integer with ten or fewer digits is interpreted as a Unix timestamp in seconds. * More than ten digits are interpreted as a Unix timestamp in nanoseconds. * A floating point number is a Unix timestamp with fractions of a second. * A string in `RFC3339` and `RFC3339Nano` format, as supported by Go's [time](https://pkg.go.dev/time) package. ### Statistics Query endpoints such as `/loki/api/v1/query` and `/loki/api/v1/query_range` return a set of statistics about the query execution. Those statistics allow users to understand the amount of data processed and at which speed. The example below show all possible statistics returned with their respective description. ```json { "status": "success", "data": { "resultType": "streams", "result": [], "stats": { "ingester": { "compressedBytes": 0, // Total bytes of compressed chunks (blocks) processed by ingesters "decompressedBytes": 0, // Total bytes decompressed and processed by ingesters "decompressedLines": 0, // Total lines decompressed and processed by ingesters "headChunkBytes": 0, // Total bytes read from ingesters head chunks "headChunkLines": 0, // Total lines read from ingesters head chunks "totalBatches": 0, // Total batches sent by ingesters "totalChunksMatched": 0, // Total chunks matched by ingesters "totalDuplicates": 0, // Total of duplicates found by ingesters "totalLinesSent": 0, // Total lines sent by ingesters "totalReached": 0 // Amount of ingesters reached. }, "store": { "compressedBytes": 0, // Total bytes of compressed chunks (blocks) processed by the store "decompressedBytes": 0, // Total bytes decompressed and processed by the store "decompressedLines": 0, // Total lines decompressed and processed by the store "chunksDownloadTime": 0, // Total time spent downloading chunks in seconds (float) "totalChunksRef": 0, // Total chunks found in the index for the current query "totalChunksDownloaded": 0, // Total of chunks downloaded "totalDuplicates": 0 // Total of duplicates removed from replication }, "summary": { "bytesProcessedPerSecond": 0, // Total of bytes processed per second "execTime": 0, // Total execution time in seconds (float) "linesProcessedPerSecond": 0, // Total lines processed per second "queueTime": 0, // Total queue time in seconds (float) "totalBytesProcessed": 0, // Total amount of bytes processed overall for this request "totalLinesProcessed": 0 // Total amount of lines processed overall for this request } } } } ``` ## Ingest logs ``` POST /loki/api/v1/push ``` `/loki/api/v1/push` is the endpoint used to send log entries to Loki. The default behavior is for the POST body to be a [Snappy](https://github.com/google/snappy)-compressed [Protocol Buffer](https://github.com/protocolbuffers/protobuf) message: - [Protocol Buffer definition](https://github.com/grafana/loki/blob/main/pkg/logproto/logproto.proto) - [Go client library](https://github.com/grafana/loki/blob/main/clients/pkg/promtail/client/client.go) These POST requests require the `Content-Type` HTTP header to be `application/x-protobuf`. Alternatively, if the `Content-Type` header is set to `application/json`, a JSON post body can be sent in the following format: ``` { "streams": [ { "stream": { "label": "value" }, "values": [ [ "", "" ], [ "", "" ] ] } ] } ``` You can set `Content-Encoding: gzip` request header and post gzipped JSON. You can optionally attach [structured metadata]({{< relref "../get-started/labels/structured-metadata" >}}) to each log line by adding a JSON object to the end of the log line array. The JSON object must be a valid JSON object with string keys and string values. The JSON object should not contain any nested object. The JSON object must be set immediately after the log line. Here is an example of a log entry with some structured metadata attached: ``` "values": [ [ "", "", {"trace_id": "0242ac120002", "user_id": "superUser123"}] ] ``` In microservices mode, `/loki/api/v1/push` is exposed by the distributor. ### Examples The following cURL command pushes a stream with the label "foo=bar2" and a single log line "fizzbuzz" using JSON encoding: ```bash curl -H "Content-Type: application/json" \ -s -X POST "http://localhost:3100/loki/api/v1/push" \ --data-raw '{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}' ``` ## Query logs at a single point in time ``` GET /loki/api/v1/query ``` `/loki/api/v1/query` allows for doing queries against a single point in time. This type of query is often referred to as an instant query. Instant queries are mostly used for metric type LogQL queries. It accepts the following query parameters in the URL: - `query`: The [LogQL]({{< relref "../query" >}}) query to perform. Requests that do not use valid LogQL syntax will return errors. - `limit`: The max number of entries to return. It defaults to `100`. Only applies to query types which produce a stream (log lines) response. - `time`: The evaluation time for the query as a nanosecond Unix epoch or another [supported format](#timestamps). Defaults to now. - `direction`: Determines the sort order of logs. Supported values are `forward` or `backward`. Defaults to `backward`. In microservices mode, `/loki/api/v1/query` is exposed by the querier and the query frontend. Response format: ``` { "status": "success", "data": { "resultType": "vector" | "streams", "result": [] | [], "stats" : [] } } ``` where `` is: ``` { "metric": {