---
title: "Draft query"
description: "The draft query 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.

# Draft query

## POST /datasources/{uid}/draft-query

Turn a question into a checked log query, PromQL query, TraceQL query or trace filters for one datasource.

The server reads the datasource's metric names, labels, attributes or columns first, then asks the model once with the question and those facts, capped at 12 KiB. The answer is checked with the lint and one sample run over the last 15 minutes of the range under the agent tools' limits; the full query is never run. Only when that check fails does the server make a second model call in the same session to correct it, so a draft spends at most two model calls, and a second failure answers `cannot_translate`. The whole draft has a 60 second deadline. Each caller may have 3 drafts in flight and each server process 10, and each caller may start 60 drafts per clock hour across all servers; the count is kept in the database. Loki answers LogQL, Prometheus answers PromQL, ClickHouse logs answer ClickHouse SQL, ClickHouse traces answer trace filters, and Tempo answers trace filters or, when the question needs more, TraceQL. `signal` defaults to `logs` on Loki, `metrics` on Prometheus and `traces` on Tempo, and ClickHouse requires it. `from` and `to` default to `now-1h` and `now` and take relative expressions such as `now-1h`, epoch milliseconds or RFC 3339 times. Viewers and above may call it, service-account keys included. Without a configured model it answers 503 `agent_unavailable`.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `uid` (required) | path | `string` |   |

### Request body

`application/json`, required.

A [`DraftQueryRequest`](/docs/reference/api/schemas/#draftqueryrequest) object.

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | The checked draft; `trace_filters` is null unless `language` is `filters`, and `query` is empty when it is. | [`DraftQuery`](/docs/reference/api/schemas/#draftquery) |
| `400` | The body is malformed or fails validation, the signal does not fit the datasource type, or the datasource type has no drafts (`invalid_request`). | [`Error`](/docs/reference/api/schemas/#error) |
| `401` | Authentication is missing or invalid. | [`Error`](/docs/reference/api/schemas/#error) |
| `403` | The caller is not allowed to perform the request; a role that is too low is code `forbidden_role`. | [`Error`](/docs/reference/api/schemas/#error) |
| `404` | The datasource does not exist (`not_found`). | [`Error`](/docs/reference/api/schemas/#error) |
| `413` | The request body exceeds the size limit. | [`Error`](/docs/reference/api/schemas/#error) |
| `422` | The question could not be turned into a query (`cannot_translate`); `reason` says why in one sentence. | [`CannotTranslate`](/docs/reference/api/schemas/#cannottranslate) |
| `429` | The caller has 3 drafts in flight or has used the 60 drafts of this clock hour (`too_many_requests`, and the message says which and how long to wait), or the server process has 10 in flight (`agent_busy`). | [`Error`](/docs/reference/api/schemas/#error) |
| `500` | The server failed to handle the request. | [`Error`](/docs/reference/api/schemas/#error) |
| `502` | The model provider failed (`provider_error`), or every read of the datasource failed, with the datasource's own code such as `datasource_unavailable`. | [`Error`](/docs/reference/api/schemas/#error) |
| `503` | No model is configured on this server (`agent_unavailable`). | [`Error`](/docs/reference/api/schemas/#error) |
| `504` | The draft did not finish within its 60 second deadline (`draft_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).
