curl -X POST https://api.thinnest.ai/chat/stream \
-H "Authorization: Bearer $THINNESTAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}'
import requests
url = "https://api.thinnest.ai/chat/stream"
headers = {
"Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
"Content-Type": "application/json",
}
payload = {
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
const response = await fetch("https://api.thinnest.ai/chat/stream", {
method: "POST",
headers: {
"Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}),
});
const data = await response.json();
console.log(data);
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}`)
req, _ := http.NewRequest("POST", "https://api.thinnest.ai/chat/stream", bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer YOUR_THINNESTAI_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Chat
Stream Message
Send a message and receive a streaming response via Server-Sent Events (SSE).
POST
/
chat
/
stream
curl -X POST https://api.thinnest.ai/chat/stream \
-H "Authorization: Bearer $THINNESTAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}'
import requests
url = "https://api.thinnest.ai/chat/stream"
headers = {
"Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
"Content-Type": "application/json",
}
payload = {
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
const response = await fetch("https://api.thinnest.ai/chat/stream", {
method: "POST",
headers: {
"Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}),
});
const data = await response.json();
console.log(data);
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}`)
req, _ := http.NewRequest("POST", "https://api.thinnest.ai/chat/stream", bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer YOUR_THINNESTAI_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}curl -X POST https://api.thinnest.ai/chat/stream \
-H "Authorization: Bearer $THINNESTAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}'
import requests
url = "https://api.thinnest.ai/chat/stream"
headers = {
"Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
"Content-Type": "application/json",
}
payload = {
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
const response = await fetch("https://api.thinnest.ai/chat/stream", {
method: "POST",
headers: {
"Authorization": "Bearer " + "YOUR_THINNESTAI_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}),
});
const data = await response.json();
console.log(data);
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
payload := []byte(`{
"agent_id": "ag_c47e7c97_b2f2",
"message": "Explain how machine learning works",
"session_id": "sess_customer_001"
}`)
req, _ := http.NewRequest("POST", "https://api.thinnest.ai/chat/stream", bytes.NewBuffer(payload))
req.Header.Set("Authorization", "Bearer YOUR_THINNESTAI_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
Request Body
Same as Send Message — all fields are identical.Target agent ID (ag_*)
User message text
Session ID for conversation memory
Response — Server-Sent Events (SSE)
The response is a stream oftext/event-stream events. Each event is a JSON object on a data: line:
data: {"type": "text", "content": "Machine learning is"}
data: {"type": "text", "content": " a subset of artificial intelligence"}
data: {"type": "text", "content": " that enables systems to learn"}
data: {"type": "tool_call", "name": "web_search", "args": {"query": "ML applications 2026"}}
data: {"type": "tool_result", "name": "web_search", "result": "..."}
data: {"type": "text", "content": " from data without being explicitly programmed."}
data: {"type": "done", "usage": {"input_tokens": 50, "output_tokens": 120, "total_tokens": 170}}
Event Types
| Type | Fields | Description |
|---|---|---|
text | content | Partial text chunk — concatenate all chunks for the full response |
tool_call | name, args | Agent is invoking a tool |
tool_result | name, result | Tool execution result |
done | usage | Stream complete — includes final token usage |
error | message | Error during generation |
Client Example — JavaScript
const response = await fetch('https://api.thinnest.ai/chat/stream', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify({
agent_id: 'ag_c47e7c97_b2f2',
message: 'Hello',
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const text = decoder.decode(value);
for (const line of text.split('\n')) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6));
if (event.type === 'text') {
process.stdout.write(event.content);
}
}
}
}
Client Example — Python
import httpx
import json
with httpx.stream("POST", "https://api.thinnest.ai/chat/stream",
headers={"Authorization": "Bearer YOUR_TOKEN"},
json={"agent_id": "ag_c47e7c97_b2f2", "message": "Hello"}
) as response:
for line in response.iter_lines():
if line.startswith("data: "):
event = json.loads(line[6:])
if event["type"] == "text":
print(event["content"], end="", flush=True)
Errors
| Code | Description |
|---|---|
401 | Missing or invalid authentication |
402 | Insufficient balance |
404 | Agent not found |
429 | Rate limit exceeded |
⌘I

