Stream chat response
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{role: 'user', content: 'Hello'},
{role: 'assistant', content: 'Hi there!'},
{
role: 'user',
content: [
{type: 'text', text: 'What is in this image?'},
{type: 'image', image_url: {url: 'https://example.com/image.jpg'}}
]
}
],
message: {
text: '<string>',
images: [
{url: '<string>', base64: '<string>', mimeType: '<string>', caption: '<string>'}
]
},
componentId: '<string>',
userId: '<string>',
groupIds: ['<string>'],
sessionId: '<string>',
id: '<string>',
context: {}
})
};
fetch('https://studyfetchapi.com/api/v1/chat/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://studyfetchapi.com/api/v1/chat/stream \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"messages": [
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hi there!"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
],
"message": {
"text": "<string>",
"images": [
{
"url": "<string>",
"base64": "<string>",
"mimeType": "<string>",
"caption": "<string>"
}
]
},
"componentId": "<string>",
"userId": "<string>",
"groupIds": [
"<string>"
],
"sessionId": "<string>",
"id": "<string>",
"context": {}
}
'import requests
url = "https://studyfetchapi.com/api/v1/chat/stream"
payload = {
"messages": [
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hi there!"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image",
"image_url": { "url": "https://example.com/image.jpg" }
}
]
}
],
"message": {
"text": "<string>",
"images": [
{
"url": "<string>",
"base64": "<string>",
"mimeType": "<string>",
"caption": "<string>"
}
]
},
"componentId": "<string>",
"userId": "<string>",
"groupIds": ["<string>"],
"sessionId": "<string>",
"id": "<string>",
"context": {}
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)Chat
Stream chat response
Streams a chat response in real-time using server-sent events (SSE). Supports both AI SDK format (with messages array) and custom format (with message object).
POST
/
api
/
v1
/
chat
/
stream
Stream chat response
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
messages: [
{role: 'user', content: 'Hello'},
{role: 'assistant', content: 'Hi there!'},
{
role: 'user',
content: [
{type: 'text', text: 'What is in this image?'},
{type: 'image', image_url: {url: 'https://example.com/image.jpg'}}
]
}
],
message: {
text: '<string>',
images: [
{url: '<string>', base64: '<string>', mimeType: '<string>', caption: '<string>'}
]
},
componentId: '<string>',
userId: '<string>',
groupIds: ['<string>'],
sessionId: '<string>',
id: '<string>',
context: {}
})
};
fetch('https://studyfetchapi.com/api/v1/chat/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://studyfetchapi.com/api/v1/chat/stream \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"messages": [
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hi there!"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
],
"message": {
"text": "<string>",
"images": [
{
"url": "<string>",
"base64": "<string>",
"mimeType": "<string>",
"caption": "<string>"
}
]
},
"componentId": "<string>",
"userId": "<string>",
"groupIds": [
"<string>"
],
"sessionId": "<string>",
"id": "<string>",
"context": {}
}
'import requests
url = "https://studyfetchapi.com/api/v1/chat/stream"
payload = {
"messages": [
{
"role": "user",
"content": "Hello"
},
{
"role": "assistant",
"content": "Hi there!"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image",
"image_url": { "url": "https://example.com/image.jpg" }
}
]
}
],
"message": {
"text": "<string>",
"images": [
{
"url": "<string>",
"base64": "<string>",
"mimeType": "<string>",
"caption": "<string>"
}
]
},
"componentId": "<string>",
"userId": "<string>",
"groupIds": ["<string>"],
"sessionId": "<string>",
"id": "<string>",
"context": {}
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)Authorizations
API Key for server-to-server authentication. Resolves to the owning organization.
Headers
Optional component ID for component-specific chat context
Body
application/json
Messages array for AI SDK format - list of conversation messages with roles
Example:
[
{ "role": "user", "content": "Hello" },
{
"role": "assistant",
"content": "Hi there!"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is in this image?"
},
{
"type": "image",
"image_url": { "url": "https://example.com/image.jpg" }
}
]
}
]
Single message for custom format - contains text and optional images
Show child attributes
Show child attributes
Component ID
User ID
Group IDs for access control
Session ID
Session ID (AI SDK uses "id")
Additional context
Response
Successful streaming response (SSE format)
Was this page helpful?
⌘I