---
title: "Record a query history entry"
method: POST
path: "/api/{org_id}/query_history"
tags: ["Query History"]
---

# Record a query history entry

`POST /api/{org_id}/query_history`

## Request

- Base URL: `https://api.openobserve.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://api.openobserve.ai/api/{org_id}/query_history`
- Auth: API key in header `Authorization`
- TypeScript: <https://skmtc.dev/openobserve/apis/openobserve-api-http/docs/api/:org_id/query_history/post.ts> (a function with typed inputs; its response is checked against the schema)

Records a query the caller ran. A run with the same source and query_key as an existing entry of the caller merges into it: the run count goes up and the latest run time, context and status replace the old ones. Stores nothing and answers 204 when ZO_QUERY_HISTORY_ENABLED is false.

## Path parameters

- `org_id` string, required

## Request body

- QueryHistoryRequest
  - `context` unknown, required
  - `query` string, required: The query text, at most 16 KB and not blank.
  - `query_key` string, nullable: Runs with the same source and key merge into one entry; defaults to the query text.
  - `source` string, nullable: `logs`, `traces`, `metrics`, `dbm` or `profiles`; defaults to `metrics`.
  - `status` string, nullable: `ok` or `error`; defaults to `ok`.
  - `streams` string[]: Streams the query ran on, at most 50; each name non-empty and without a comma.

## Response `200`

Success

- QueryHistoryEntry
  - `context` unknown, required
  - `created_at` integer, required: First run, in microseconds since the epoch; the last run on entries recorded by v1.1.x.
  - `id` string, required: Entry id.
  - `query` string, required: The query text.
  - `query_key` string, nullable: Hex sha256 of the merge key; null on entries recorded before keys existed.
  - `run_count` integer, required: How many runs merged into this entry; 1 on entries recorded by v1.1.x.
  - `source` string, required: Page the query ran on.
  - `starred` boolean, required: Starred entries are kept until deleted.
  - `status` string, required: `ok` or `error`, from the latest run; `ok` on entries recorded by v1.1.x.
  - `streams` string[], required: Streams the query ran on.
  - `updated_at` integer, required: Latest run, in microseconds since the epoch.

## Other responses

- `204`: Query history is disabled; nothing was stored
- `400`: Unknown source or status, query empty, query or context too large, too many streams, or an empty stream name or one with a comma (the message lists them)
- `413`: Request body larger than 128 KB
- `500`: Failure

---

[API](https://skmtc.dev/openobserve/apis/openobserve-api-http.md) - [All operations](https://skmtc.dev/openobserve/apis/openobserve-api-http/llms.txt) - [OpenAPI document](https://skmtc.dev/openobserve/apis/openobserve-api-http/revisions/0529b8a10252?raw)
