# Serve your agent over AG-UI

> Enable the AG-UI endpoint at /v1/ag-ui with the ag-ui extra and the ag_ui key in 10xgraph.json, then test it with curl and connect frontends like CopilotKit.

Source: https://10xgraph.com/docs/server/ag-ui
Last updated: 2026-11-25

AG-UI is an open event protocol that connects agent backends to chat frontends. The API server can expose AG-UI at `/v1/ag-ui` (off by default), so chat frontends such as CopilotKit connect under the same authentication and permission checks as the other routes. If you are building a custom frontend, the [TypeScript client](/docs/client) over `/v1/graph/stream` is the direct path. This guide covers the server side of AG-UI. For frontend integration with CopilotKit, see [10xGraph with CopilotKit](/docs/integrations/copilotkit). For complete endpoint and event documentation, see the [AG-UI endpoint reference](/docs/reference/rest-api/ag-ui).

## Install the AG-UI extra

The endpoint is not built by default. Install it with the `ag-ui` extra:

```bash
pip install "10xgraph-api[ag-ui]"
```

## Enable the endpoint in 10xgraph.json

Add the `ag_ui` key to your `10xgraph.json` configuration:

```json
{
  "agent": "graph.agent:app",
  "ag_ui": { "enabled": true }
}
```

Then start the server:

```bash
10xgraph dev --no-open
```

The endpoint `POST /v1/ag-ui` is now ready and appears in Swagger at `/docs` under the **AG-UI** tag. If you enable AG-UI without installing the extra, the server exits at startup and prints the install command.

## Test the endpoint

Use curl to verify the endpoint is working. The request must include `threadId`, `runId`, and `messages`:

```bash
curl -N http://127.0.0.1:8000/v1/ag-ui \
  -H 'content-type: application/json' \
  -d '{
    "threadId": "t1",
    "runId": "r1",
    "messages": [{"id": "u1", "role": "user", "content": "hello"}]
  }'
```

You should see server-sent event (SSE) lines starting with `data: `, beginning with `RUN_STARTED` and ending with `RUN_FINISHED`. The output is in AG-UI event format.

If you have authentication enabled, add the authorization header:

```bash
curl -N http://127.0.0.1:8000/v1/ag-ui \
  -H 'content-type: application/json' \
  -H "authorization: Bearer $TOKEN" \
  -d '{"threadId": "t1", "runId": "r1", "messages": [{"id": "u1", "role": "user", "content": "hello"}]}'
```

| Response | Meaning |
|---|---|
| `data: {"type": "RUN_STARTED"...` followed by events and `data: {"type": "RUN_FINISHED"...` | Endpoint is working |
| `404` | AG-UI is not enabled in 10xgraph.json, or the server was not restarted |
| `401` | Authentication is required and the token is missing or invalid |
| `403` | The token lacks the permission for the route (`graph:stream`) |
| `404` | The thread does not exist for this caller (unknown, or owned by someone else) |
| `422` | The request body is invalid. Check that `threadId`, `runId`, and `messages` are present and properly formatted |
| `data: {"type": "RUN_ERROR"...` in the stream | The run started but encountered an error. Check the server logs for details |

## Connect your frontend

Point your AG-UI client to the endpoint. With CopilotKit, you create an `HttpAgent` in a Next.js route handler on the server side, so the browser never sees the API token:

```ts
import { HttpAgent } from "@ag-ui/client";

const agent = new HttpAgent({
  url: process.env.TENXGRAPH_API_URL + "/v1/ag-ui",
  headers: { Authorization: `Bearer ${process.env.TENXGRAPH_API_TOKEN}` },
});
```

By handling the connection on your server, the token stays server-side and you do not need to configure CORS for the frontend's origin. The full Next.js route handler and page component are documented in [10xGraph with CopilotKit](/docs/integrations/copilotkit).

## Configure for production

The endpoint is mounted whenever enabled, in every `MODE`.

### Persistent checkpointing

AG-UI clients identify the conversation by `threadId`, which the server maps to a 10xGraph thread. AG-UI follows `runs.thread_ids` like REST. With the default `"server"`, a `threadId` the server never issued gets `404`; send a blank or `"new"` `threadId` to have the server create the thread, and read the id from `RUN_STARTED`. CopilotKit makes its own ids by default, so a CopilotKit frontend needs `"runs": {"thread_ids": "client"}` in `10xgraph.json`. An existing thread is scoped to the caller as usual, so another user's thread answers `404`. The server reads the checkpoint to determine which messages are new and only sends those to the graph. With an in-memory checkpointer:

- Threads are lost when the server restarts
- State is not shared across replicas

Use a persistent checkpointer (Postgres or SQLite). See [Set up checkpointing](/docs/guides/set-up-checkpointing) for configuration.

### Message ids

The server gives every user and tool message its own id from the id generator, as REST does. It does not keep the client's message id. The client's id is stored in the message's `metadata["client_message_id"]`, and a retry that resends the same id is not stored twice. This keeps a client such as CopilotKit, which sends uuids, working under an integer id generator like Snowflake.

### Authentication and authorization

Without authentication, anyone can access anyone's thread. Enable auth with `"auth": "jwt"` or a custom `BaseAuth` subclass. With auth on, each user reaches only their own threads by default (reach `own`).

```json
{
  "auth": "jwt"
}
```

Environment: set `JWT_SECRET_KEY` to a strong random string (32+ characters).

See [Auth](/docs/server/auth) for full configuration.

### Client tools policy

By default, AG-UI clients can send tools with each request. The model is offered those tools for that run only. Client tools run in the browser, cannot overwrite server-side tools, and are size-limited. You can disable them if you only use server-side tools:

```json
{
  "ag_ui": {
    "enabled": true,
    "allow_client_tools": false
  }
}
```

With `allow_client_tools: false`, only tools declared in `remote_tools` are offered, and tools the client sends are ignored.

With `allow_client_tools` true, a client tool whose name equals a server tool (a local tool or an MCP tool of the graph) is refused with 422 before the run starts, for example `tools[1]: 'get_weather' is the name of a server tool`. A client tool that repeats a name declared under `remote_tools` is accepted.

### Rate limiting

The endpoint counts against `cache_store.rate_limit` like any route; see [Rate limiting](/docs/server/rate-limiting).

### One run per thread and request limits

The server runs one graph run at a time on a thread. A second AG-UI run on a busy thread waits up to 30 seconds, then gets `409` with `thread is busy`. AG-UI always waits; it cannot ask the running run to stop. With a Redis cache store, the lock is shared across replicas.

Because AG-UI clients resend the whole conversation, the size limits (500 messages, 100 content blocks per message, 1,000,000 characters of text) apply to the trailing turn only. The full history is capped at 10,000 messages. Requests over a limit get `422`. See the [AG-UI endpoint reference](/docs/reference/rest-api/ag-ui#request-size-limits).

In production (`MODE=production`), error events carry a generic message. Details stay in the server log.

### Stream buffering

The endpoint streams responses as server-sent events. Disable buffering on any reverse proxy or load balancer in front of the server:

- **nginx**: The response headers already include `X-Accel-Buffering: no` to disable nginx buffering.
- **Other proxies and load balancers**: Explicitly disable response buffering for `/v1/ag-ui`.
- **Connection timeout**: Set the idle timeout longer than your slowest graph run.

## Related

- [AG-UI endpoint reference](/docs/reference/rest-api/ag-ui): complete request schema, event types, interrupts, and error codes
- [10xGraph with CopilotKit](/docs/integrations/copilotkit): frontend integration example with tools and human approval
- [AG-UI configuration](/docs/reference/api-cli/configuration#websocket-ag_ui-and-observability): full `ag_ui` key documentation

## Frequently asked questions

### Do I need AG-UI to build a frontend for 10xGraph?

No. The TypeScript client over /v1/graph/stream is the standard path. Use AG-UI when your frontend already speaks it, such as CopilotKit.

### Why does POST /v1/ag-ui return 404?

The endpoint is off by default. Enable it by setting ag_ui in 10xgraph.json with enabled true, install the ag-ui extra, and restart.
