Skip to main content

Overview

This endpoint executes a workflow and streams the response in real-time as the model generates tokens. It works seamlessly with the Vercel AI SDK and is ideal for building interactive chat interfaces and real-time tutoring experiences.

Endpoint

  • HTTP Method: POST
  • URL: /api/v1/run/{workflow_id}/stream?token=STREAM_TOKEN
Replace {workflow_id} with your workflow ID and STREAM_TOKEN with a token from the Stream Token endpoint.

Features

Real-time Streaming

Receive and display progressive responses as the AI generates content — no waiting for the full result.

Single-Use Token Auth

Secure your requests with single-use tokens — no API key exposed on the client side.

Vercel AI SDK Compatible

Integrates directly with ai/react hooks like useChat for reactive chat interfaces.

Flexible Input Processing

Support for various input formats including text variables and image URLs.

Authentication

Uses a stream token passed as a query parameter (not a Bearer key). Get a token from GET /api/v1/token first.

Request

Path Parameters Query Parameters Request Body Content-Type: application/json Pass your workflow’s input variables as key/value pairs.

Implementation Guide

First, obtain a single-use token from the token endpoint using your API key.
Response:
Use the token to make a streaming request to the workflow endpoint:
Use --no-buffer so curl prints tokens as they arrive.
Use this React component to handle streaming responses in your UI:
For chat-style interfaces, integrate with the Vercel AI SDK’s useChat hook:

Response

The response is a real-time text/plain stream. Text chunks arrive as they are generated:

Error Responses

Missing, invalid, or already-used token.
No credits remaining on the account.
Workflow not found or not published.
Something went wrong during execution.

Code Examples

Best Practices

Implement robust error handling for network issues, expired tokens, and invalid responses. Always check response.ok before reading the stream.
Tokens are single-use — generate a fresh token before each stream request. Never cache or reuse tokens.
Display appropriate loading indicators while waiting for the initial response chunk to arrive.
Optimize your application to handle continuous data streams efficiently. Use ReadableStream readers and avoid buffering the entire response in memory.

Additional Notes

  • Single-Use Token: The stream token is consumed on the first request — if it’s expired or already used, you’ll get a 401.
  • Max Duration: Streaming requests can run for up to 300 seconds before timing out.
  • Credits: The workflow owner’s credits are charged based on total tokens generated.
  • Non-Streaming Alternative: Use the POST /api/v1/run/{workflow_id} endpoint if you don’t need real-time output.