How to call your AI Agent Graph via a Vercel AI SDK format API
Copy page
Use a raw HTTP request to stream responses from your agent graph over the Vercel AI SDK data stream protocol.
Overview
This guide shows how to call your agent graph directly over HTTP and stream responses using the Vercel AI SDK data stream format. It covers the exact endpoint, headers, request body, and the event stream response you should expect.
If you are building a React UI, consider our prebuilt components under React UI Components. This page is for low-level HTTP usage.
Endpoint
- Path (mounted by the Run API):
/api/chat
- Method:
POST
- Protocol: Server-Sent Events (SSE) encoded JSON, using Vercel AI SDK data-stream v2
- Content-Type (response):
text/event-stream
- Response Header:
x-vercel-ai-data-stream: v2
Authentication
Choose the authentication method:
See Authentication → Run API for more details.
Request Body Schema
Field Notes:
messages
— Must include at least oneuser
messagecontent
— Can be a string or an object withparts
for multi-part contentconversationId
— Optional; server generates one if omitted
Provide request context via HTTP headers only (validated against your Context Config). Do not include it in the JSON body. See Request context.
Example cURL
When using an API key for auth:
Response: Vercel AI SDK Data Stream (v2)
The response is an SSE stream of JSON events compatible with the Vercel AI SDK UI message stream. The server sets x-vercel-ai-data-stream: v2
.
Event Types
text-start
— Indicates a new text segment is startingtext-delta
— Carries the text content delta for the current segmenttext-end
— Marks the end of the current text segmentdata-component
— Structured UI data emitted by the agent (for rich UIs)data-artifact
— Artifact data emitted by tools/agentsdata-operation
— Operational events (status updates, completion, errors)error
— Error message emitted by the server/agent
Example Stream (abbreviated)
Operation Events
data-operation
events conform to an internal schema. Common types include:
agent_initializing
— The agent runtime is startingagent_ready
— Agent is readyagent_thinking
— Agent is processingstatus_update
— Progress update; may includelabel
and structuredctx
datacompletion
— The agent completed the taskerror
— Error information (also emitted as a top-levelerror
event)
Text Streaming Behavior
- For each text segment, the server emits
text-start
→text-delta
→text-end
- The server avoids splitting content word-by-word; a segment is usually a coherent chunk
- Operational events are queued during active text emission and flushed shortly after to preserve ordering and readability
Error Responses
Streamed Errors
Non-Streaming Errors
Validation failures and other errors return JSON with an appropriate HTTP status code.
HTTP Status Codes
200
— Stream opened successfully401
— Missing/invalid authentication404
— Graph or agent not found400
— Invalid request body/context500
— Internal server error
Development Notes
- Default local base URL:
http://localhost:3003
- Endpoint mounting in the server:
/api/chat
→ Vercel data stream (this page)/v1/mcp
→ MCP JSON-RPC endpoint
To test quickly without a UI, use curl -N
or a tool that supports Server-Sent Events.