---
title: "Get a generic execution plan for a query"
method: GET
path: "/instances/{id}/query-plan"
tags: ["Query Insights"]
---

# Get a generic execution plan for a query

`GET /instances/{id}/query-plan`

## Request

- Base URL: `https://api.cloudpepper.io`
- URL: `https://api.cloudpepper.io/instances/{id}/query-plan`
- Auth: HTTP bearer

Returns EXPLAIN (GENERIC_PLAN, FORMAT JSON) for the normalized query text of the given pg_stat_statements queryid. The query is never executed (no ANALYZE) and is only planned if its stored text is fully normalized (contains no literals) and is a single SELECT/WITH statement. PostgreSQL 16+ only. A reachable instance whose queryid has no matching row returns HTTP 404 with `status: not_found`; unplannable/unsupported/version-too-old cases return HTTP 409 with a `reason`.

**Key Parameters:**
- `id`: The instance whose database to inspect
- `queryid`: The queryid obtained from the slow-queries endpoint

## Response `200`

Generic plan produced successfully

- object

## Other responses

- `400`: Missing or invalid queryid
- `404`: Instance not found, or no pg_stat_statements row exists for the queryid (body `status`: not_found)
- `409`: Query insights unavailable, query unplannable, or PostgreSQL < 16 (see body `reason`)

---

[API](https://skmtc.dev/cloudpepper/apis/cloudpepper-api-docs.md) · [All operations](https://skmtc.dev/cloudpepper/apis/cloudpepper-api-docs/llms.txt) · [OpenAPI document](https://skmtc.dev/cloudpepper/apis/cloudpepper-api-docs/revisions/b6a59274cedc?raw)
