AG-UI is an open protocol between agent backends and chat frontends. POST /v1/agents/{id}/ag-ui speaks it, so any HTTP client that can read server-sent events, or any AG-UI client library, can talk to your agent directly. Scope agents. Each run is one turn of a conversation: the same key auth, spend cap, one-turn-at-a-time rule, hosted runtime and token billing apply, and the reply is stored on the conversation like any other message.

Request

The body is AG-UI’s RunAgentInput:

Response

Server-sent events, one data: line of JSON per AG-UI event:
  • Text before a tool call is closed with TEXT_MESSAGE_END; text after it is a new message.
  • Tool arguments arrive in one TOOL_CALL_ARGS event, once the runtime knows them. Arguments and results are cut at 8,000 characters. A tool that failed reports its error as the TOOL_CALL_RESULT content.
  • A failed turn ends with RUN_ERROR ({ "message", "code": "turn_failed" }) instead of RUN_FINISHED.
Refusals before the stream starts are plain JSON errors, not events: 401/403 for the key, 402 spend_cap_reached or 402 payment_method_required, 409 conversation_busy (a run on this thread is still going), 503 runtime_starting (retry in a few seconds, as with messages).

Read the stream with fetch

Keep your Allternit key on your server. The endpoint takes a POST, so the browser EventSource API (GET only) can’t call it; read the stream with fetch instead. This works in Node 18+, Deno, Bun and edge runtimes:
To serve a browser chat, put this behind your own route and forward the events to the page; the key never leaves your server.

Compatible AG-UI clients

Any client that sends RunAgentInput and reads AG-UI events over SSE works. Point it at the endpoint above with the Authorization header:
  • The AG-UI client libraries (HttpAgent from @ag-ui/client in TypeScript, and the Python SDK). See docs.ag-ui.com.
  • CopilotKit, through an AG-UI HttpAgent registered in its runtime.
  • Any framework or chat UI that lists AG-UI support.
The SDKs also expose the raw stream: client.conversations.runAgentAgUiStream(agentId, body) in TypeScript and client.conversations.run_agent_ag_ui_stream(agent_id, messages=[…]) in Python. Errors: invalid_messages, invalid_content, invalid_thread_id, plus those of sending a message.