curl --request POST \
--url https://api.allternit.com/v1/agents/{id}/ag-ui \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"id": "<string>",
"content": "<unknown>"
}
],
"threadId": "<string>",
"runId": "<string>",
"parentRunId": "<string>",
"tools": [
{}
],
"context": [
{}
],
"state": "<unknown>",
"forwardedProps": "<unknown>"
}
'import requests
url = "https://api.allternit.com/v1/agents/{id}/ag-ui"
payload = {
"messages": [
{
"id": "<string>",
"content": "<unknown>"
}
],
"threadId": "<string>",
"runId": "<string>",
"parentRunId": "<string>",
"tools": [{}],
"context": [{}],
"state": "<unknown>",
"forwardedProps": "<unknown>"
}
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({
messages: [{id: '<string>', content: '<unknown>'}],
threadId: '<string>',
runId: '<string>',
parentRunId: '<string>',
tools: [{}],
context: [{}],
state: '<unknown>',
forwardedProps: '<unknown>'
})
};
fetch('https://api.allternit.com/v1/agents/{id}/ag-ui', 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.allternit.com/v1/agents/{id}/ag-ui",
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([
'messages' => [
[
'id' => '<string>',
'content' => '<unknown>'
]
],
'threadId' => '<string>',
'runId' => '<string>',
'parentRunId' => '<string>',
'tools' => [
[
]
],
'context' => [
[
]
],
'state' => '<unknown>',
'forwardedProps' => '<unknown>'
]),
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.allternit.com/v1/agents/{id}/ag-ui"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"id\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"threadId\": \"<string>\",\n \"runId\": \"<string>\",\n \"parentRunId\": \"<string>\",\n \"tools\": [\n {}\n ],\n \"context\": [\n {}\n ],\n \"state\": \"<unknown>\",\n \"forwardedProps\": \"<unknown>\"\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.allternit.com/v1/agents/{id}/ag-ui")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"id\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"threadId\": \"<string>\",\n \"runId\": \"<string>\",\n \"parentRunId\": \"<string>\",\n \"tools\": [\n {}\n ],\n \"context\": [\n {}\n ],\n \"state\": \"<unknown>\",\n \"forwardedProps\": \"<unknown>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.allternit.com/v1/agents/{id}/ag-ui")
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 \"messages\": [\n {\n \"id\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"threadId\": \"<string>\",\n \"runId\": \"<string>\",\n \"parentRunId\": \"<string>\",\n \"tools\": [\n {}\n ],\n \"context\": [\n {}\n ],\n \"state\": \"<unknown>\",\n \"forwardedProps\": \"<unknown>\"\n}"
response = http.request(request)
puts response.read_body<string>{
"error": {
"type": "invalid_request_error",
"code": "<string>",
"message": "<string>",
"param": "<string>",
"url": "<string>"
}
}Run the agent for an AG-UI frontend
Runs one conversation turn over the AG-UI protocol (https://docs.ag-ui.com), so AG-UI
clients such as CopilotKit’s HttpAgent can drive the agent. The body is AG-UI’s
RunAgentInput. threadId is one of the agent’s conversation ids, or any other string,
which is kept on the conversation the first run opens so later runs continue it; no
threadId opens a new conversation. The server keeps the history: the turn’s input is
the last user message’s text. Client-side tools, context and state are not used.
The answer is server-sent events, one data: JSON AG-UI event each: RUN_STARTED,
TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END, TOOL_CALL_START /
TOOL_CALL_ARGS / TOOL_CALL_END / TOOL_CALL_RESULT for each tool the agent uses,
then RUN_FINISHED or RUN_ERROR ({message, code}). runId is echoed (generated when
missing). Refusals before the stream starts are plain errors, as for messages:
402 spend_cap_reached / payment_method_required, 409 conversation_busy,
503 runtime_starting or 503 computer_capacity (the host has no memory for another awake
runtime). Both carry Retry-After: 30. The reply is stored and metered like any conversation message.
curl --request POST \
--url https://api.allternit.com/v1/agents/{id}/ag-ui \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{
"id": "<string>",
"content": "<unknown>"
}
],
"threadId": "<string>",
"runId": "<string>",
"parentRunId": "<string>",
"tools": [
{}
],
"context": [
{}
],
"state": "<unknown>",
"forwardedProps": "<unknown>"
}
'import requests
url = "https://api.allternit.com/v1/agents/{id}/ag-ui"
payload = {
"messages": [
{
"id": "<string>",
"content": "<unknown>"
}
],
"threadId": "<string>",
"runId": "<string>",
"parentRunId": "<string>",
"tools": [{}],
"context": [{}],
"state": "<unknown>",
"forwardedProps": "<unknown>"
}
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({
messages: [{id: '<string>', content: '<unknown>'}],
threadId: '<string>',
runId: '<string>',
parentRunId: '<string>',
tools: [{}],
context: [{}],
state: '<unknown>',
forwardedProps: '<unknown>'
})
};
fetch('https://api.allternit.com/v1/agents/{id}/ag-ui', 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.allternit.com/v1/agents/{id}/ag-ui",
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([
'messages' => [
[
'id' => '<string>',
'content' => '<unknown>'
]
],
'threadId' => '<string>',
'runId' => '<string>',
'parentRunId' => '<string>',
'tools' => [
[
]
],
'context' => [
[
]
],
'state' => '<unknown>',
'forwardedProps' => '<unknown>'
]),
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.allternit.com/v1/agents/{id}/ag-ui"
payload := strings.NewReader("{\n \"messages\": [\n {\n \"id\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"threadId\": \"<string>\",\n \"runId\": \"<string>\",\n \"parentRunId\": \"<string>\",\n \"tools\": [\n {}\n ],\n \"context\": [\n {}\n ],\n \"state\": \"<unknown>\",\n \"forwardedProps\": \"<unknown>\"\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.allternit.com/v1/agents/{id}/ag-ui")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {\n \"id\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"threadId\": \"<string>\",\n \"runId\": \"<string>\",\n \"parentRunId\": \"<string>\",\n \"tools\": [\n {}\n ],\n \"context\": [\n {}\n ],\n \"state\": \"<unknown>\",\n \"forwardedProps\": \"<unknown>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.allternit.com/v1/agents/{id}/ag-ui")
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 \"messages\": [\n {\n \"id\": \"<string>\",\n \"content\": \"<unknown>\"\n }\n ],\n \"threadId\": \"<string>\",\n \"runId\": \"<string>\",\n \"parentRunId\": \"<string>\",\n \"tools\": [\n {}\n ],\n \"context\": [\n {}\n ],\n \"state\": \"<unknown>\",\n \"forwardedProps\": \"<unknown>\"\n}"
response = http.request(request)
puts response.read_body<string>{
"error": {
"type": "invalid_request_error",
"code": "<string>",
"message": "<string>",
"param": "<string>",
"url": "<string>"
}
}Body
Response
AG-UI events.
The response is of type string.