---
title: "Execute SQL query against Kafka topics"
method: POST
path: "/topics/query"
tags: ["Topics"]
---

# Execute SQL query against Kafka topics

`POST /topics/query`

Parse and execute a SQL query against a Kafka topic.

## Request body

- KafkaSqlQueryReq — Request body for executing a SQL query against Kafka topics.
  - `sql` string, required — SQL query string (e.g., SELECT * FROM topic_name WHERE ... LIMIT 10)
  - `max_time_seconds` integer — Maximum execution time in seconds before the query is terminated

## Response `200`

Successful Response

- KafkaSqlQueryRes — Response from executing a SQL query against a Kafka topic.
  - `columns` string[] — Column names in the result set
  - `rows` object[] — Result rows as dicts
  - `metadata` KafkaSqlQueryResultMetadata — Metadata about query execution for the results panel.
    - `records_scanned` integer
    - `records_matched` integer
    - `partitions_scanned` integer[]
    - `execution_time_ms` number
    - `terminated_by` string — limit, max_time, max_bytes, or end_of_topic
    - `bytes_scanned` integer
    - `topic` string — The topic that was queried
  - `error` string, nullable — Error message if the query failed

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/streamkap/apis/streamkap-rest-api.md) · [All operations](https://skmtc.net/streamkap/apis/streamkap-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/streamkap/streamkap-rest-api/revisions/8aea6143d003/schema)
