---
title: "Tail"
description: "The tail endpoints of the HTTP API."
---

> Documentation Index
> Fetch the complete documentation index at: https://slashobserve.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tail

## GET /datasources/{uid}/tail

Stream new log lines of a logs query as Server-Sent Events.

The server polls the datasource every second for lines newer than the last line it sent and streams them as they arrive, so the browser holds no credential and runs no query of its own. The stream starts with `retry: 3000` and an `event: ready` whose data is `{"datasource_uid","from"}`. Each poll that found lines sends an `event: lines` whose data is `{"frames","newest","truncated"}`: `frames` holds the lines in the `Frame` shape of a panel data response, every frame with `ref` `A`, oldest first, with a `TimeNs` string field beside `Time`; `newest` is the RFC 3339 time of the newest line; `truncated` is true when the poll hit `limit`, and the next poll then runs at once instead of a second later. `partial` and `warning` are present only when the datasource said the poll did not cover everything, such as a failed shard; the lines found are still sent. The next poll starts one nanosecond after `newest`, so a line is sent once, except that a partial poll leaves the start where it was for up to three polls, so the lines it missed are fetched and the ones already sent are not sent again. A datasource failure sends an `event: error` whose data is `{"error","code"}` with the code the explore query would answer, and the stream ends; a datasource that is unavailable or slow is retried and reported only after five failed polls in a row. The first poll runs before any stream byte, so a query that cannot run answers JSON with the explore query's status instead of a stream. For Loki the query must be a log query that starts with a stream selector; for ClickHouse one SELECT that selects `Timestamp`, whose top-level `ORDER BY` and `LIMIT` the server replaces. A `: ping` comment arrives every 15 seconds and re-checks the caller's credential, and the server ends the stream after 30 minutes. Polls run with the agent tools' limits and share the server's upstream call slots, but a tail holds no in-flight query slot. A caller may hold 5 tails and the process 200. Each tail is recorded once, when it ends, as `query.run` with `stream` true, the query text, the start of the stream and the rows of its first poll; tails are never folded. Viewers and above may call it, service-account keys included.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `uid` (required) | path | `string` |   |
| `query` (required) | query | `string` | The query the logs page runs. |
| `from` | query | `string` | Where the first poll starts: a relative expression such as `now-30s`, epoch milliseconds or an RFC 3339 time, in the past. Defaults to 10 seconds ago. |
| `limit` | query | `integer` | The most lines one poll returns. Between 1 and 1000. Default `500`. |
| `timezone` | query | `string` | The IANA zone a relative `from` resolves in; defaults to UTC. |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | An open `text/event-stream`. | `text/event-stream` |
| `400` | A parameter is missing, repeated, unknown or out of range, `from` is not a time or lies in the future, or the datasource is not Loki or ClickHouse (`invalid_request`), or the query is longer than 64 KiB (`query_too_long`). | [`Error`](/docs/reference/api/schemas/#error) |
| `401` | Authentication is missing or invalid. | [`Error`](/docs/reference/api/schemas/#error) |
| `404` | The datasource does not exist (`not_found`). | [`Error`](/docs/reference/api/schemas/#error) |
| `422` | The first poll cannot run: `query_invalid` for a Loki metric query, a ClickHouse query without `Timestamp` or with a top-level set operator, or an upstream rejection; `query_forbidden`, `limit_exceeded` or `unknown_macro` as for the explore query. | [`Error`](/docs/reference/api/schemas/#error) |
| `429` | The caller already holds 5 tails (`too_many_streams`), or the server's shared upstream call slots stayed busy for the first poll (`too_many_requests`). | [`Error`](/docs/reference/api/schemas/#error) |
| `500` | The server failed to handle the request, including a first poll that failed without a classified cause. | [`Error`](/docs/reference/api/schemas/#error) |
| `502` | The datasource is unavailable for the first poll. | [`Error`](/docs/reference/api/schemas/#error) |
| `503` | The process holds 200 tails (`too_many_streams`). | [`Error`](/docs/reference/api/schemas/#error) |
| `504` | The datasource did not answer the first poll within the 15 second query timeout. | [`Error`](/docs/reference/api/schemas/#error) |

Generated from [`api/openapi.yaml`](https://github.com/slashobserve/slashobserve/blob/c770e5e0/api/openapi.yaml) at `c770e5e0`. [Report a problem](https://github.com/slashobserve/slashobserve/issues/new).
