REST API Reference¶
The REST API exposes tasks and document pipelines via HTTP.
Starting the Server¶
# app.py
from redis_agent_kit.api import create_app
app = create_app(redis_url="redis://localhost:6379")
Customization¶
Endpoints¶
Health¶
GET / → {"name": "Redis Agent Kit API", "version": "...", "docs": "/docs"}
GET /health → {"status": "healthy"}
Tasks¶
List tasks:
Response:
{
"tasks": [
{
"task_id": "01HXYZ...",
"session_id": "01HABC...",
"status": "in_progress",
"metadata": {"message": "..."}
}
],
"total": 1
}
Get task:
Response:
{
"task_id": "01HXYZ...",
"session_id": "01HABC...",
"status": "done",
"metadata": {"message": "What is Redis?"},
"result": {"answer": "..."},
"updates": [{"message": "Searching...", "update_type": "info"}]
}
Delete task:
Cancel task (optionally cascade to descendants):
When cascade is omitted, the kit's SubTaskConfig.cascade_cancel is used. The response includes cancelled_count — the number of tasks transitioned to CANCELLED.
List children (sub-tasking):
Returns the direct children of a task in spawn order, with each child's status, result, and spawn_key.
Get task tree (sub-tasking):
Returns the recursive descendant tree:
{
"task": {"task_id": "...", "status": "done", ...},
"children": [
{"task": {...}, "children": [...]}
]
}
See the Sub-Tasks guide for the data model and lifecycle.
Streaming¶
Server-Sent Events (SSE) endpoints push task progress and LLM tokens to clients in real time. Enable streaming by passing stream_config=StreamConfig(enabled=True) to both AgentKit and create_app.
from redis_agent_kit import AgentKit, ChannelScope, StreamConfig
from redis_agent_kit.api import create_app
stream_config = StreamConfig(
enabled=True,
channels={ChannelScope.TASK, ChannelScope.SESSION},
)
kit = AgentKit(agent_callable=my_handler, stream_config=stream_config)
app = create_app(kit=kit, stream_config=stream_config)
Stream a task:
GET /tasks/{task_id}/stream
GET /tasks/{task_id}/stream?replay=false
GET /tasks/{task_id}/stream?events=token,done,failed
?replay=true, default) and then new events as they happen. Returns 404 if streaming is not enabled.
Stream all tasks in a session (requires ChannelScope.SESSION):
Stream all events globally (requires ChannelScope.GLOBAL, useful for dashboards):
Event types: update, token, done, failed, cancelled, input_required. When sub-tasking is enabled, the parent's channel also receives subtask_spawned, subtask_done, subtask_failed, and subtask_input_required events (see the Sub-Tasks guide).
JavaScript client:
const es = new EventSource(`/tasks/${taskId}/stream`);
es.addEventListener('update', (e) => console.log(JSON.parse(e.data).message));
es.addEventListener('token', (e) => process.stdout.write(JSON.parse(e.data).message));
es.addEventListener('done', (e) => { console.log(JSON.parse(e.data).result); es.close(); });
es.addEventListener('failed', (e) => { console.error(JSON.parse(e.data).error); es.close(); });
See the Streaming guide for the full configuration reference.
Pipelines¶
prepare, ingest, full, and documents submit background tasks and return task IDs.
Prepare (Stage 1):
Response:
Ingest (Stage 2):
Response:
Full pipeline:
Add document:
Run on inline documents:
POST /pipelines/run
{
"documents": [{"title": "Doc 1", "content": "...", "source": "api"}],
"chunk_size": 500
}
Status:
Response:
Clear:
Example Client¶
import httpx
async with httpx.AsyncClient(base_url="http://localhost:8000") as client:
# List tasks
response = await client.get("/tasks", params={"status": "done"})
tasks = response.json()["tasks"]
# Get pipeline status
response = await client.get("/pipelines/status")
print(f"Chunks: {response.json()['chunks']}")
Error Responses¶
Status codes:
- 200 – Success
- 201 – Created
- 404 – Not found
- 422 – Validation error
- 500 – Server error