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

# Get Query Pipeline

> Builds a query pipeline from the specified query and returns the pipeline definition containing all the nested materialized views that the query depends on. A pipeline allows you to chain multiple queries together and execute them as a single unit.

<Info>
  Minimum required API key scope: `Read`
</Info>

Retrieve the pipeline definition for a specific query, including all nested materialized views that the query depends on.

## Overview

This endpoint returns the pipeline structure that would be executed for a given query, allowing you to inspect the lineage and execution order before running the pipeline. This is useful for understanding dependencies and planning pipeline executions.

The pipeline definition contains all the nodes (queries and materialized view refreshes) in the correct dependency order.

<Note>
  The `query_parameters` should be passed as a URL-encoded JSON string in the query parameter, where keys are parameter names and values are parameter values.
</Note>

## Use Cases

### Inspect Pipeline Before Execution

Check what queries and materialized views will be executed:

```bash theme={null}
curl "https://api.dune.com/api/v1/query/3493826/pipeline?performance=medium" \
  -H "X-Dune-Api-Key: $DUNE_API_KEY"
```

### Validate Dependencies with Parameters

Understand query dependencies before running a pipeline with specific parameters:

```bash theme={null}
# Query parameters as JSON string
curl "https://api.dune.com/api/v1/query/3493826/pipeline?performance=large&query_parameters=%7B%22blockchain%22%3A%22ethereum%22%7D" \
  -H "X-Dune-Api-Key: $DUNE_API_KEY"
```

## Response Structure

The response contains a `pipeline` object with a `nodes` array. Each node represents either a query execution or materialized view refresh, along with its dependencies.

Example response:

```json theme={null}
{
  "pipeline": {
    "nodes": [
      {
        "id": 1,
        "dependencies": [],
        "materialized_view_refresh": {
          "name": "dune.analyst.mv_base_data",
          "performance": "medium"
        }
      },
      {
        "id": 2,
        "dependencies": [1],
        "query_execution": {
          "query_id": 3493826,
          "performance": "medium"
        }
      }
    ]
  }
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Use Before Pipeline Execution">
    Call this endpoint before executing a pipeline to understand what will be executed and in what order. This helps with planning and cost estimation.
  </Accordion>

  <Accordion title="Validate Complex Dependencies">
    For queries with many dependencies, use this endpoint to visualize the execution graph and identify potential bottlenecks.
  </Accordion>

  <Accordion title="Test with Parameters">
    When using query parameters, test the pipeline structure with different parameter values to ensure the lineage is resolved correctly.
  </Accordion>
</AccordionGroup>

## Related Endpoints

* [Execute Query Pipeline](/api-reference/executions/endpoint/execute-query-pipeline) - Execute a query's pipeline
* [Execute Pipeline](/api-reference/pipelines/endpoint/execute-pipeline) - Execute a pipeline based on lineage
* [Get Pipeline Status](/api-reference/pipelines/endpoint/get-pipeline-status) - Check pipeline execution status


## OpenAPI

````yaml GET /v1/query/{query_id}/pipeline
openapi: 3.0.1
info:
  contact: {}
  description: Dune API
  title: DuneAPI
  version: '1.0'
servers:
  - url: https://api.dune.com/api
security: []
paths:
  /v1/query/{query_id}/pipeline:
    get:
      summary: Get query pipeline
      description: >-
        Builds a query pipeline from the specified query and returns the
        pipeline definition containing all the nested materialized views that
        the query depends on. A pipeline allows you to chain multiple queries
        together and execute them as a single unit.
      parameters:
        - description: API Key for the service
          in: header
          name: X-Dune-Api-Key
          required: true
          schema:
            type: string
        - description: Alternative to using the X-Dune-Api-Key header
          in: query
          name: api_key
          schema:
            type: string
        - description: Unique identifier of the query
          in: path
          name: query_id
          required: true
          schema:
            type: integer
        - description: The performance engine tier. Can be `small`, `medium`, or `large`.
          in: query
          name: performance
          schema:
            type: string
        - description: SQL Query parameters in json key-value pairs
          in: query
          name: query_parameters
          schema:
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.GetQueryPipelineResponse'
          description: OK
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error400'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error401'
          description: Unauthorized
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error404'
          description: Not Found
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/models.Error500'
          description: Internal Server Error
components:
  schemas:
    models.GetQueryPipelineResponse:
      properties:
        pipeline:
          allOf:
            - $ref: '#/components/schemas/models.Pipeline'
          description: The pipeline definition containing nodes to execute
      type: object
    models.Error400:
      properties:
        error:
          example: Bad Request
          type: string
      type: object
    models.Error401:
      properties:
        error:
          example: Invalid API Key
          type: string
      type: object
    models.Error404:
      properties:
        error:
          example: Object not found
          type: string
      type: object
    models.Error500:
      properties:
        error:
          example: Internal error
          type: string
      type: object
    models.Pipeline:
      properties:
        nodes:
          description: >-
            List of nodes in the pipeline. Nodes are executed in dependency
            order.
          items:
            $ref: '#/components/schemas/models.PipelineNode'
          type: array
      type: object
    models.PipelineNode:
      properties:
        dependencies:
          description: >-
            List of node IDs that this node depends on. Nodes are executed in
            dependency order.
          items:
            type: integer
          type: array
        id:
          description: Unique identifier of the node in the pipeline
          example: 1
          type: integer
        materialized_view_refresh:
          allOf:
            - $ref: '#/components/schemas/models.PipelineMaterializedViewRefreshNode'
          description: >-
            Materialized view refresh node configuration. Required if this node
            refreshes a materialized view.
        query_execution:
          allOf:
            - $ref: '#/components/schemas/models.PipelineQueryExecutionNode'
          description: >-
            Query execution node configuration. Required if this node executes a
            query.
      type: object
    models.PipelineMaterializedViewRefreshNode:
      properties:
        name:
          description: Name of the materialized view to refresh
          example: mv_1
          type: string
        performance:
          description: >-
            The performance engine tier the refresh will be run on. Can be
            `small`, `medium`, or `large`.
          enum:
            - small
            - medium
            - large
          example: medium
          type: string
      type: object
    models.PipelineQueryExecutionNode:
      properties:
        performance:
          description: >-
            The performance engine tier the execution will be run on. Can be
            `small`, `medium`, or `large`.
          enum:
            - small
            - medium
            - large
          example: medium
          type: string
        query_id:
          description: Unique identifier of the query to execute
          example: 1234
          type: integer
        query_parameters:
          description: >-
            SQL Query parameters in json key-value pairs. Each parameter is to
            be provided in key-value pairs. This enables you to execute a
            parameterized query with the provided values for your parameter
            keys.
          type: object
      type: object

````