How to call your AI Agent using the Chat API
Copy page
Learn about details of the Vercel AI SDK data stream protocol that powers the `/run/api/chat` API endpoint.
Overview
This guide shows how to call your agent 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 or Vercel AI Elements headless primitives. This page is for the low-level streaming API.
Endpoint
- Path (mounted by the Run API):
/run/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 oneusermessagecontent— Optional string message text (legacy-compatible)parts— Optional multi-part content array (text + images)content+partstogether — Both are accepted.contentis prepended as a text part unless an identical text part already exists.conversationId— Optional; server generates one if omitted
Sending Images
Images can be included as part of multi-part message content. Supported formats are PNG, JPEG, and WebP.
There are two ways to include images:
- Inline data URIs — Base64-encoded images with the format
data:image/{png|jpeg|jpg|webp};base64,{data} - External URLs — HTTP/HTTPS URLs pointing to hosted images
When both content and parts are provided, the server keeps all valid parts and also includes content as text input. If text in content and parts does not match, the server logs a warning to help identify payload-construction bugs.
Images are validated server-side: MIME types are verified against actual content via byte-sniffing, a 10 MB size limit is enforced, and external URLs must use HTTP/HTTPS with no embedded credentials. DNS checks block requests to private/internal IP addresses.
Optional Headers
x-emit-operations— Set totrueto include detailed data operations in the response stream. Useful for debugging and monitoring agent behavior. See Data Operations for details.
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 Streaming Events
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 segment
Data Events
data-component— Structured UI data emitted by the agent (for rich UIs)data-artifact— Artifact data emitted by tools/agents (documents, files, saved results)data-operation— Low-level operational events (agent lifecycle, completion, errors)data-summary— AI-generated status updates with user-friendly labels and contextual details
Tool Events
tool-input-start,tool-input-delta,tool-input-available— Tool input streamingtool-approval-request— Emitted when a tool requires user approval before executiontool-output-available,tool-output-denied— Tool output (including approval denial)
Tool approval
If a tool is configured with needsApproval: true, the run pauses and the stream includes a tool-approval-request event:
To continue the run, your client must approve/deny the pending tool call. See Tool approvals.
Tool input & output events
Depending on UI needs, the stream may include tool input and tool output events.
Example Stream (abbreviated)
Data Event Details
data-operation Events
Low-level operational events with technical context. Common types include:
agent_initializing— The agent runtime is startingagent_ready— Agent is ready and processingcompletion— The agent completed the task (includes agent ID and iteration count)error— Error information (also emitted as a top-levelerrorevent)
data-summary Events
AI-generated status updates designed for end-user consumption. Structure:
label— User-friendly description (required)details— Optional structured/unstructured context data
data-artifact Events
Emitted when an agent saves an artifact from a tool result. The event carries the artifact's preview fields in summary — these are the fields marked inPreview: true in the artifact schema and are available immediately in the agent's context.
The complete artifact data (including non-preview fields) is persisted and can be fetched on demand. See Artifact Components for details on preview vs. non-preview fields.
data-component Events
Structured UI data for rich interface components:
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
Errors are now delivered as data-operation events with unified structure:
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— Agent not found400— Invalid request body/context500— Internal server error
Development Notes
- Default local base URL:
http://localhost:3002 - Endpoint mounting in the server:
/run/api/chat→ Vercel data stream (this page)/run/v1/mcp→ MCP JSON-RPC endpoint
To test quickly without a UI, use curl -N or a tool that supports
Server-Sent Events.