curl --request POST \
--url https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"content": "<string>",
"conversation_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
]
}
'import requests
url = "https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages"
payload = {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"content": "<string>",
"conversation_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
content: '<string>',
conversation_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
image_ids: ['3c90c3cc-0d44-4b50-8888-8dd25736052a']
})
};
fetch('https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages', 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://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'content' => '<string>',
'conversation_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'image_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages"
payload := strings.NewReader("{\n \"id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"content\": \"<string>\",\n \"conversation_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"image_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"content\": \"<string>\",\n \"conversation_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"image_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"content\": \"<string>\",\n \"conversation_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"image_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"conversation": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"title": "<string>",
"last_message_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z"
},
"question": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"role": "user",
"content": "<string>",
"status": "generating",
"images": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "video",
"title": "<string>",
"provider": "bunny_stream",
"status": "uploading",
"visibility": "private",
"archived": true,
"created_at": "2023-11-07T05:31:56Z",
"file_name": "<string>",
"mime": "<string>",
"size_bytes": 123,
"external_id": "<string>",
"error": "<string>",
"duration_seconds": 123,
"width": 123,
"height": 123,
"preview_url": "<string>",
"thumbnail_url": "<string>",
"folder_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"citations": [
{
"media_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"media_title": "<string>",
"cited_text": "<string>",
"page_from": 123,
"page_to": 123
}
],
"created_at": "2023-11-07T05:31:56Z",
"error_code": "<string>",
"reply_to": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"completed_at": "2023-11-07T05:31:56Z"
},
"answer": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"role": "user",
"content": "<string>",
"status": "generating",
"images": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "video",
"title": "<string>",
"provider": "bunny_stream",
"status": "uploading",
"visibility": "private",
"archived": true,
"created_at": "2023-11-07T05:31:56Z",
"file_name": "<string>",
"mime": "<string>",
"size_bytes": 123,
"external_id": "<string>",
"error": "<string>",
"duration_seconds": 123,
"width": 123,
"height": 123,
"preview_url": "<string>",
"thumbnail_url": "<string>",
"folder_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"citations": [
{
"media_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"media_title": "<string>",
"cited_text": "<string>",
"page_from": 123,
"page_to": 123
}
],
"created_at": "2023-11-07T05:31:56Z",
"error_code": "<string>",
"reply_to": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"completed_at": "2023-11-07T05:31:56Z"
},
"limits": {
"daily_limit": 123,
"used": 123,
"remaining": 123,
"club_budget_exhausted": true,
"resets_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Perguntar ao agente
A resposta chega em streaming, e não depende da conexão.
curl --request POST \
--url https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"content": "<string>",
"conversation_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_ids": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
]
}
'import requests
url = "https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages"
payload = {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"content": "<string>",
"conversation_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"image_ids": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
content: '<string>',
conversation_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
image_ids: ['3c90c3cc-0d44-4b50-8888-8dd25736052a']
})
};
fetch('https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages', 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://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'content' => '<string>',
'conversation_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'image_ids' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages"
payload := strings.NewReader("{\n \"id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"content\": \"<string>\",\n \"conversation_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"image_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"content\": \"<string>\",\n \"conversation_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"image_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.weve.cx/v1/clubs/{clubId}/classroom/agents/{publicId}/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"content\": \"<string>\",\n \"conversation_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"image_ids\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"conversation": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"title": "<string>",
"last_message_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z"
},
"question": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"role": "user",
"content": "<string>",
"status": "generating",
"images": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "video",
"title": "<string>",
"provider": "bunny_stream",
"status": "uploading",
"visibility": "private",
"archived": true,
"created_at": "2023-11-07T05:31:56Z",
"file_name": "<string>",
"mime": "<string>",
"size_bytes": 123,
"external_id": "<string>",
"error": "<string>",
"duration_seconds": 123,
"width": 123,
"height": 123,
"preview_url": "<string>",
"thumbnail_url": "<string>",
"folder_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"citations": [
{
"media_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"media_title": "<string>",
"cited_text": "<string>",
"page_from": 123,
"page_to": 123
}
],
"created_at": "2023-11-07T05:31:56Z",
"error_code": "<string>",
"reply_to": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"completed_at": "2023-11-07T05:31:56Z"
},
"answer": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"role": "user",
"content": "<string>",
"status": "generating",
"images": [
{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"kind": "video",
"title": "<string>",
"provider": "bunny_stream",
"status": "uploading",
"visibility": "private",
"archived": true,
"created_at": "2023-11-07T05:31:56Z",
"file_name": "<string>",
"mime": "<string>",
"size_bytes": 123,
"external_id": "<string>",
"error": "<string>",
"duration_seconds": 123,
"width": 123,
"height": 123,
"preview_url": "<string>",
"thumbnail_url": "<string>",
"folder_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
],
"citations": [
{
"media_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"media_title": "<string>",
"cited_text": "<string>",
"page_from": 123,
"page_to": 123
}
],
"created_at": "2023-11-07T05:31:56Z",
"error_code": "<string>",
"reply_to": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"completed_at": "2023-11-07T05:31:56Z"
},
"limits": {
"daily_limit": 123,
"used": 123,
"remaining": 123,
"club_budget_exhausted": true,
"resets_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}text/event-stream: quatro eventos, cada data: um JSON (ver os esquemas
AgentStreamAccepted, AgentStreamDelta, AgentStreamDone e AgentStreamError). O
EventSource do browser só faz GET; leia o corpo do fetch:
const res = await fetch(`/api/v1/clubs/${clubId}/classroom/agents/${publicId}/messages`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: crypto.randomUUID(), content, conversation_id }),
});
if (!res.headers.get("content-type")?.startsWith("text/event-stream")) {
const { error } = await res.json(); // 403, 409, 429… — ver a tabela abaixo
throw new Error(error.code);
}
const reader = res.body!.pipeThrough(new TextDecoderStream()).getReader();
let buffer = "";
for (;;) {
const { value, done } = await reader.read();
if (done) break;
buffer += value;
const events = buffer.split("\n\n");
buffer = events.pop()!;
for (const raw of events) {
const event = raw.match(/^event: (.+)$/m)?.[1];
const data = raw.match(/^data: (.+)$/m)?.[1];
if (event && data) handle(event, JSON.parse(data));
}
}
id antes de mostrar a pergunta na tela e reuse-o se precisar reenviar: é ele que
impede a pergunta de ser feita — e cobrada — duas vezes. Se a conexão cair no meio, a resposta
continua sendo gerada; leia-a em
GET .../conversations/{conversationId}.Authorizations
Token OPACO de sessão de aluno, emitido por /v1/auth/sign-in e
verificado contra a nossa tabela — não é JWT e não se lê nada dele.
A ida ao banco não é custo novo: toda requisição autenticada já resolve o dono da sessão. Em troca, encerrar uma sessão vale no mesmo instante, sem lista de bloqueio nem janela de tolerância.
O classroom o guarda em cookie host-only: um cookie de domínio o mandaria para os subdomínios dos outros clubs.
Path Parameters
Id público da organização — o mesmo que GET /v1/me devolve em
organization_id.
Na URL o recurso se chama club; no contrato e no domínio, organization.
A divergência é deliberada: clubs é a palavra do produto, e a URL é o que
as pessoas leem.
É o identificador do provedor de autenticação, e é assim de propósito: o cliente precisa nomear a organização ao pedir o token, e o token é o que prova o escopo. Um id só nosso obrigaria a traduzir um no outro antes de ter um token — e a tradução exigiria uma chamada escopada, que é justamente a que ainda não dá para fazer.
O uuid interno da organização não aparece no contrato: ele é o que as chaves estrangeiras do domínio referenciam, e continua sendo nosso.
A chave curta da URL do classroom.
1 - 32Body
Response
A resposta, em eventos. Cada data: é um JSON de um dos quatro
formatos, conforme o event: — accepted, delta, done ou error.