Subscribe to stream
curl --request GET \
--url https://macaly.com/api/chat/{chatId}/subscribe \
--header 'Authorization: Bearer <token>'import requests
url = "https://macaly.com/api/chat/{chatId}/subscribe"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://macaly.com/api/chat/{chatId}/subscribe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://macaly.com/api/chat/{chatId}/subscribe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://macaly.com/api/chat/{chatId}/subscribe"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://macaly.com/api/chat/{chatId}/subscribe")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://macaly.com/api/chat/{chatId}/subscribe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyEndpoints
Subscribe to stream
Suscríbete al stream de un chat activo para recibir las respuestas de la IA en tiempo real
GET
/
api
/
chat
/
{chatId}
/
subscribe
Subscribe to stream
curl --request GET \
--url https://macaly.com/api/chat/{chatId}/subscribe \
--header 'Authorization: Bearer <token>'import requests
url = "https://macaly.com/api/chat/{chatId}/subscribe"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://macaly.com/api/chat/{chatId}/subscribe', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://macaly.com/api/chat/{chatId}/subscribe",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://macaly.com/api/chat/{chatId}/subscribe"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://macaly.com/api/chat/{chatId}/subscribe")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://macaly.com/api/chat/{chatId}/subscribe")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodySuscríbete al stream de un chat activo para recibir las respuestas de la IA en tiempo real. Es una alternativa a consultar el endpoint Get Status.
Solicitud
GET /api/chat/{chatId}/subscribe
Encabezados
| Encabezado | Obligatorio | Descripción |
|---|---|---|
Authorization | Sí | Bearer macaly_... |
Parámetros de ruta
| Parámetro | Tipo | Descripción |
|---|---|---|
chatId | string | El ID del chat devuelto por POST /api/chat |
Solicitud de ejemplo
curl -N https://www.macaly.com/api/chat/abc123/subscribe \
-H "Authorization: Bearer macaly_abc123..."
const response = await fetch(
`https://www.macaly.com/api/chat/${chatId}/subscribe`,
{
headers: {
'Authorization': 'Bearer macaly_abc123...',
},
}
);
if (response.status === 204) {
console.log('No active stream');
return;
}
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
for (const line of chunk.split('\n')) {
if (line.startsWith('0:')) {
// Text content
const text = JSON.parse(line.slice(2));
process.stdout.write(text);
}
}
}
import requests
response = requests.get(
f'https://www.macaly.com/api/chat/{chat_id}/subscribe',
headers={
'Authorization': 'Bearer macaly_abc123...',
},
stream=True,
)
if response.status_code == 204:
print('No active stream')
else:
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('0:'):
import json
text = json.loads(line[2:])
print(text, end='')
Respuesta
Devuelve un stream de eventos enviados por el servidor (SSE) con el progreso del proceso y las respuestas de la IA.Formato del stream
El stream usa el protocolo de stream de datos del Vercel AI SDK v4. Cada fragmento lleva un prefijo que indica el tipo:| Prefijo | Descripción |
|---|---|
0: | Contenido de texto |
2: | Objetos de datos (como { chatId }) |
8: | Anotaciones y metadatos |
Ejemplo de stream
2:[{"chatId":"abc123"}]
0:"I'll create a landing page for you."
0:" Let me start by setting up the project structure."
8:{"type":"tool-call","toolName":"WriteFile",...}
0:" Done! Your landing page is ready."
Códigos de estado
| Código | Descripción |
|---|---|
| 200 | Correcto (respuesta en streaming) |
| 204 | Sin stream activo (el proceso ha finalizado o no se ha iniciado) |
| 401 | Clave API no válida o ausente |
| 403 | El chat no pertenece a tu equipo |
| 404 | Chat no encontrado |
| 429 | Límite de solicitudes alcanzado |
Notas
- El stream terminará cuando el proceso finalice
- Si llamas a este endpoint después de que el proceso haya finalizado, obtendrás una respuesta
204 No Content - Para implementaciones más sencillas, considera consultar en su lugar el endpoint Get Status
¿Esta página le ayudó?