Search documentation
karat

+

K

User Documentation ↗
Version 2.0

Streaming Execute Query

POST/api/v2/functions/queries/{queryApiName}/streamingExecute
Warning

This endpoint is in preview and may be modified or removed at any time. To use this endpoint, add preview=true to the request query parameters.

Executes a Query and returns results as a Server-Sent Events (text/event-stream) stream. By default, this executes the latest version of the query. The latest version is the one that was most recently published, which may be a pre-release version.

This endpoint supports all Query functions. Each SSE event's data field is a JSON-encoded StreamingExecuteQueryResponse – either a data batch (type: data) carrying one or more result values, or an error (type: error) emitted before stream termination if execution fails. Non-streaming functions emit a single data event containing the entire result; streaming functions emit a data event per batch as results become available.

Per the Server-Sent Events specification, each event is terminated by a blank line:

data: {"type":"data","value":[{"productId":"SKU-001","price":29.99}]}

data: {"type":"error","errorCode":"INVALID_ARGUMENT","errorName":"QueryRuntimeError","errorInstanceId":"3f8a9c7b-2e4d-4a1f-9b8c-7d6e5f4a3b2c","errorDescription":"Division by zero","parameters":{}}

Third-party applications using this endpoint via OAuth2 must request the following operation scope: api:functions-execute.

Path parameters

queryApiName
string

The name of the Query in the API.

Query parameters

transactionId
stringoptional

The ID of a transaction to read from. Transactions are an experimental feature and not all workflows may be supported.

preview
booleanoptional

Enables the use of preview functionality.

Request body

StreamingExecuteQueryRequest
object
Hide child attributes

Hide child attributes

ontology
stringoptional

Optional ontology identifier (RID or API name). When provided, executes an ontology-scoped function. When omitted, executes a global function.

parameters
map<ParameterId, DataValue>optional
Show child attributes

Show child attributes

version
stringoptional

The version of the query to execute. When used with branch, the specified version must exist on the branch.

branch
stringoptional

The Foundry branch to execute the query from. If not specified, the default branch is used. When provided without version, the latest version on this branch is used. When provided with version, the specified version must exist on the branch.

Response body

StreamingExecuteQueryResponse
union

Returns a stream of Server-Sent Events (text/event-stream). Each event's data field is a JSON-encoded payload of the type described below.

A single message in a streaming Query execution response. Each message contains either a data batch or an error.

Hide child attributes

Hide child attributes

data
objectoptional

A batch of query results.

Show child attributes

Show child attributes

error
objectoptional

An error that occurred during query execution.

Show child attributes

Show child attributes

Examples

Request

Copied!
1 2 3 4 5 curl -X POST \ \t-H "Content-type: application/json" \ \t-H "Authorization: Bearer $TOKEN" \ "https://$HOSTNAME/api/v2/functions/queries/myQueryFunction/streamingExecute?transactionId=transaction-1&preview=true" \ -d '{"parameters":{"price":29.99},"version":"1.2.3","branch":"ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252","ontology":"example-ontology"}'

Error responses

Error Name
StreamingExecuteQueryPermissionDeniedError CodePERMISSION_DENIED
Status Code403
DescriptionCould not streamingExecute the Query.
ParametersqueryApiName