The /api/chat endpoint accepts a POST request containing a list of ClientMessage objects and returns a streaming response using the Data Stream Protocol.
Request Format
- Method:
POST - Path:
/api/chat - Query Parameter:
protocol (defaults to 'data'). This determines the streaming protocol used. - Body: A JSON object matching the
Request schema:{
"messages": [
{ "role": "user", "content": "Hello!" }
]
}
Response Format
- Media Type:
text/event-stream - Behavior: The response is a streamed sequence of events (text, tool calls, etc.) patched with necessary headers for the specified protocol via
patch_response_with_headers.
# Example request structure
import requests
url = "http://localhost:8000/api/chat?protocol=data"
payload = {
"messages": [
{"role": "user", "content": "What is the capital of France?"}
]
}
response = requests.post(url, json=payload, stream=True)
for line in response.iter_lines():
if line:
print(line.decode('utf-8'))