S'abonner au 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
S'abonner au stream
Abonnez-vous à un stream de chat actif pour recevoir les réponses IA en temps réel
GET
/
api
/
chat
/
{chatId}
/
subscribe
S'abonner au 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_bodyAbonnez-vous à un stream de chat actif pour recevoir les réponses IA en temps réel. C’est une alternative à l’interrogation de l’endpoint Obtenir le statut.
Requête
GET /api/chat/{chatId}/subscribe
En-têtes
| En-tête | Requis | Description |
|---|---|---|
Authorization | Oui | Bearer macaly_... |
Paramètres de chemin
| Paramètre | Type | Description |
|---|---|---|
chatId | string | L’ID du chat retourné par POST /api/chat |
Exemple de requête
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='')
Réponse
Retourne un flux Server-Sent Events (SSE) avec la progression du workflow et les réponses IA.Format du stream
Le stream utilise le protocole data stream du Vercel AI SDK v4. Chaque chunk est préfixé par un indicateur de type :| Préfixe | Description |
|---|---|
0: | Contenu texte |
2: | Objets de données (comme { chatId }) |
8: | Annotations et métadonnées |
Exemple 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."
Codes de statut
| Statut | Description |
|---|---|
| 200 | Succès (réponse streaming) |
| 204 | Pas de stream actif (workflow terminé ou pas encore démarré) |
| 401 | Clé API invalide ou manquante |
| 403 | Le chat n’appartient pas à votre équipe |
| 404 | Chat introuvable |
| 429 | Limite de requêtes atteinte |
Remarques
- Le stream se termine lorsque le workflow est terminé
- Si vous appelez cet endpoint après la fin du workflow, vous obtiendrez une réponse
204 No Content - Pour des implémentations plus simples, envisagez d’interroger l’endpoint Obtenir le statut à la place
Cette page vous a-t-elle été utile ?