Streaming
BindAI v0.1 provides a streaming endpoint for agent execution through the REST API. Streaming allows a client to receive agent output progressively instead of waiting for the complete response. The endpoint is:Streaming Architecture
A streaming request follows this general flow:StreamingResponse to return the streamed output.
The endpoint provides a lightweight HTTP streaming boundary around BindAI agent execution.
Endpoint
The streaming endpoint is:{agent_name} parameter identifies the configured agent that should execute the request.
For example:
Authentication
The streaming endpoint is protected by the BindAI API authentication layer. Clients must provide:Request Body
The streaming endpoint accepts an agent run request. The request body contains:message field is required and must contain a non-empty string.
The request model is the same request model used by the normal agent execution endpoint.
Streaming Response
The endpoint returns a streaming HTTP response. The response allows clients to consume agent output incrementally. Conceptually:Streaming with cURL
A simple command-line example is:-N option tells cURL not to buffer the streamed response unnecessarily.
Streaming with Python
A Python HTTP client can consume the response incrementally. For example, usingrequests:
Streaming with JavaScript
A browser or server-side JavaScript application can consume the HTTP response using the Fetch API. For example:Streaming vs Normal Execution
BindAI provides both normal and streaming agent execution. Normal execution:When to Use Streaming
Streaming is particularly useful for interactive applications. Examples include:- Chat interfaces
- Agent consoles
- Interactive assistants
- Long model responses
- Generated explanations
- Content generation
- Developer tools
Streaming and Model Providers
The REST API provides the HTTP streaming boundary around agent execution. The agent and its configured model provider determine how the underlying execution produces output. Conceptually:Chunk Handling
Clients should treat received data as part of a larger response. A chunk may not represent:- A complete sentence
- A complete word
- A complete semantic unit
- A complete application-level event
Buffering
Streaming can be affected by buffering at different layers. Potential buffering points include:Reverse Proxies
If a reverse proxy is placed in front of BindAI:Connection Lifetime
A streaming request remains active while the HTTP response is being produced. Conceptually:Client Disconnects
A client may disconnect before the response has completed. For example:Streaming vs Background Runs
Streaming and background execution solve different problems. Streaming:Streaming and Authentication Errors
Authentication is checked before the protected streaming endpoint can be used. A missing or invalid API key results in an authentication error rather than a stream. For example:Streaming and Agent Errors
A validly authenticated request can still fail during execution. Potential failure sources include:- Agent configuration
- Model providers
- Tools
- Connections
- External services
- Application code
Streaming and Tools
An agent may use tools during execution. Conceptually:EventRecorder.
Streaming and Observability
BindAI’s runtime event system can record structured execution events independently of the HTTP streaming response. Relevant event categories include:- Agent started
- Agent finished
- Model requested
- Model responded
- Tool executed
- Workflow events
- Node events
- Memory events
- MCP connection events
Content Type
The current v0.1 streaming route returns a text-basedStreamingResponse.
Clients should consume it as streamed text.
The current implementation is not documented as a Server-Sent Events (text/event-stream) protocol.
Applications should therefore avoid assuming SSE-specific framing or event fields.
If a future BindAI release introduces a structured streaming protocol, that protocol will be documented separately.
Streaming Protocol Scope
The current v0.1 streaming implementation intentionally provides a simple HTTP streaming interface. It does not define a complete structured event protocol for:- Token metadata
- Tool-call events
- Tool results
- Structured model events
- Usage events
- Reasoning events
- Workflow events
- Connection events
API Documentation
FastAPI automatically exposes API documentation for the BindAI API application. When running locally, the documentation is available through the standard FastAPI documentation routes. For example:Testing Streaming
The API package includes tests for the implemented agent API, including streaming behavior. Run the API test suite with:- Endpoint availability
- Authentication
- Agent lookup
- Request validation
- Streaming response behavior
- Returned agent output
Local Development
Start the API locally with:Production Considerations
When deploying streaming endpoints publicly, consider:- HTTPS
- Reverse-proxy buffering
- Request timeouts
- Connection timeouts
- Client disconnects
- API authentication
- Rate limiting
- Provider latency
- Concurrent streams
- Resource usage
- Monitoring
Current v0.1 Scope
BindAI v0.1 provides:- Agent streaming through the REST API
- Bearer API-key authentication
- HTTP streaming responses
- Python HTTP client compatibility
- JavaScript Fetch compatibility
- cURL compatibility
- FastAPI/OpenAPI documentation
Future Streaming Capabilities
Future BindAI releases may expand streaming with capabilities such as:- Structured streaming events
- Token metadata
- Tool-call events
- Tool-result events
- Usage information
- Execution identifiers
- Stream cancellation
- Richer error events
- Server-Sent Events support
- WebSocket support
- Structured workflow streaming
