The Agent API
The agents LearnHouse runs in its own interface, available to your app: Atlas for staff and automation, Copilot and custom agents for learners. You send messages, LearnHouse streams back text, tool calls, approvals, structured views and citations, and you draw them however you like.
Every path starts with /api/v1/agent. Every response carries an X-LearnHouse-Agent-API header with the contract
version (currently 2026-11-16).
| Where LearnHouse runs | Base URL |
|---|---|
| LearnHouse Cloud | https://api.learnhouse.io/api/v1/agent |
| Self-hosted | https://your-domain.com/api/v1/agent |
| Local development | http://localhost:1338/api/v1/agent |
What you get
- Conversations that keep their history on the server, so a reload or a second device picks up where you left off.
- Streaming over Server-Sent Events with typed events: text deltas, tool calls and progress, plans, views, citations, approvals, usage. See Streaming events.
- Approvals for risky actions. Atlas never publishes, deletes or emails on its own: it asks, and someone approves or denies. See Approvals & tools.
- Views: the 42 structured components Atlas draws in LearnHouse (tables, charts, quizzes, flashcards, timelines…), as validated JSON with a Markdown fallback. See Views.
- Citations for learner agents, pointing at the lesson an answer came from.
- Output modes: Markdown, views, or JSON that matches a schema you provide, plus safe server-side templates. See Output modes & templates.
- Client-side tools: let the agent call functions that run in your app.
- Support in
@learnhouse/sdk,@learnhouse/reactand@learnhouse/vue. See the Quickstart.
Agents
GET /agents lists the agents the caller can use, with what each one supports.
| Agent id | Kind | For | What it does |
|---|---|---|---|
atlas | atlas | Staff, automation | The admin agent. Reads and changes the organization through the same tools as Atlas in the dashboard: courses, members, analytics, assignments, payments and the rest. Changes that need a person's OK go through |
copilot | copilot | Learners | Answers questions about the courses, grounded in course content the learner can open, with citations. |
agent_<uuid> | custom | Learners | An agent built in |
{ "id": "atlas", "kind": "atlas", "name": "Atlas", "description": "…", "emoji": "🧭", "color": "#4f46e5", "audience": "staff", "greeting": null, "starters": ["…"], "capabilities": { "streaming": true, "tools": true, "approvals": true, "views": true, "citations": false, "json_output": true, "templates": true, "client_tools": true }, "output_modes": ["views", "markdown", "json"], "required_scopes": ["agent.create"], "available": true, "unavailable_reason": null }
An agent the caller can see but not use has available: false and a short unavailable_reason (AI turned off, plan,
missing scope). Check capabilities instead of assuming: learner agents have citations: true and approvals: false.
GET /agents/{agent_id}/tools lists the tools that agent may call for this caller, with each tool's tier (read,
write, destructive) and whether it needs_approval. Use the names in a conversation's
tool allowlist.
Authentication
Send Authorization: Bearer <token>. Three kinds of token work:
| Credential | Acts as | Agents | Use it from |
|---|---|---|---|
lh_… | The organization, capped by the token creator's role | All | Your server only |
| That member, with their role | All the member can use | The member's own app or browser | |
| One learner | copilotagent_<uuid> | A browser, minted by your server |
API token permissions
Create the token under Developers → API Access and turn on the AI agents (Agent API) row (how tokens work):
| Permission | Allows |
|---|---|
| List agents and tools, list and read conversations and messages, reattach to a stream | |
| Create conversations, send messages, cancel runs, send client tool results | |
| Approve or deny risky actions with the token itself (self-approval) | |
| Delete conversations |
Without Update, a token can still run Atlas: when Atlas asks for approval, a person approves it in your app with their own member session, or in LearnHouse. Full Access tokens do not include self-approval; turn it on under Custom when an automation really must approve its own actions.
API tokens act for the whole organization. Never send one to a browser. For learners chatting in your frontend, mint an embed session on your server and use that.
Member sessions and the org
API tokens and embed sessions belong to one organization. A member session can belong to several, so pass org_id as
a query parameter (or org_id in the body of POST /conversations) on GET /agents, POST /conversations and
GET /conversations.
Embed sessions
A learner copilot in your frontend uses an embed session minted with
POST /api/v1/admin/{org_slug}/auth/embed-session, the same session the React and Vue
components use. An embed session can only talk to learner agents, sees only what that learner can open, and can never
approve anything. See Security & limits.
Endpoints
| Method | Path | What it does |
|---|---|---|
GET | /agents | Agents this caller can use |
GET | /agents/{agent_id} | One agent |
GET | /agents/{agent_id}/tools | Tools that agent may call for this caller |
GET | /views/schema | JSON Schema of views and every component |
POST | /templates/render | Render a template with sample data, for previews |
POST | /conversations | Start a conversation |
GET | /conversations | List conversations (agentexternal_user_idlimit |
GET | /conversations/{id} | One conversation, with its pending approvals and tool calls |
DELETE | /conversations/{id} | Delete a conversation |
GET | /conversations/{id}/messages | Its messages |
POST | /conversations/{id}/messages | Send a message; streams the reply |
GET | /conversations/{id}/stream | Reattach to the current run (Last-Event-ID |
POST | /conversations/{id}/cancel | Stop the current run |
POST | /conversations/{id}/tool-results | Return the results of client-side tool calls |
POST | /approvals/{approval_id}/approve | Approve a risky action |
POST | /approvals/{approval_id}/deny | Deny it |
Conversations
curl -X POST https://learn.example.com/api/v1/agent/conversations \ -H "Authorization: Bearer lh_…" -H "Content-Type: application/json" \ -d '{ "agent": "atlas", "title": "Weekly report", "instructions": "Answer in French. Keep answers short.", "output": { "mode": "views" }, "metadata": { "workspace": "north" }, "external_user_id": "u_1842" }'
| Field | ||
|---|---|---|
agent | required | atlascopilotagent_<uuid> |
title | optional | Shown in conversation lists |
context | optional | course_uuidactivity_uuidlocale |
instructions | optional | Up to 2000 characters added to the agent's instructions. They can shape tone and focus, never override LearnHouse's own rules. |
output | optional | modeviewsmarkdownjsonjson_schematemplate |
tools | optional | allowclient |
metadata | optional | Up to 20 keys of strings, numbers or booleans, returned as is |
external_user_id | optional | Your own id for the person behind the conversation (up to 128 characters). Filter lists with it. |
The answer is a conversation object (201):
{ "id": "agconv_…", "object": "conversation", "agent_id": "atlas", "title": "Weekly report", "created_at": "2026-11-16T09:12:03Z", "updated_at": "2026-11-16T09:12:03Z", "status": "idle", "context": { "course_uuid": null, "activity_uuid": null, "locale": null }, "instructions": "Answer in French. Keep answers short.", "output": { "mode": "views", "json_schema": null, "template": null }, "tools": { "allow": null, "client": [] }, "metadata": { "workspace": "north" }, "external_user_id": "u_1842", "pending_approvals": [], "pending_tool_calls": [], "last_event_id": null }
status is idle, running (a reply is being written), or requires_action (waiting on an approval or a client tool
result). One run at a time: sending a message while one is running answers 409 run_in_progress.
Messages
POST /conversations/{id}/messages takes content (up to 8000 characters) and streams the reply by default. Pass
"stream": false to wait for the finished message instead. You can also override output and context for this one
message.
A finished assistant message:
{ "id": "agmsg_…", "role": "assistant", "created_at": "2026-11-16T09:12:05Z", "status": "completed", "text": "Three courses are below 30% completion.", "views": [{ "id": "view_…", "call_id": "call_1", "schema_version": 1, "title": null, "layout": "stack", "components": [{ "type": "kpis", "items": [{ "label": "Below 30%", "value": 3 }] }], "fallback_markdown": "- **Below 30%**: 3" }], "citations": [], "tool_calls": [{ "call_id": "call_1", "name": "list_courses", "ok": true, "client": false }], "approvals": [], "plan": null, "suggestions": ["Email the learners who stalled"], "output": null, "rendered": null, "usage": { "credits": 3, "requests": 2, "input_tokens": 0, "output_tokens": 0 }, "error": null }
status is completed, requires_action, cancelled or failed. GET /conversations/{id}/messages returns the
whole history in this shape, so you can render a past conversation exactly like a live one.
Plans, AI settings and credits
The Agent API is part of the Enterprise Edition. On LearnHouse Cloud, API tokens need the Pro plan
or higher, and each agent follows the plan rules it has in the app; an agent your plan does not include answers
403 plan_required.
The agents obey the organization's AI settings:
| Error code | Meaning |
|---|---|
AI_DISABLED | AI is turned off for the organization |
AI_FEATURE_DISABLED | This agent's feature is off (learner agents need |
AI_STAFF_ONLY | AI is limited to staff, and the caller is a learner |
AI_MONTHLY_CAP_REACHED | The organization's monthly AI cap is used up |
out_of_credits402 | No AI credits left |
Messages use AI credits like the same agents do in LearnHouse. Each reply ends with a
usage event, and each message keeps its usage, so you can show or log the cost.
Errors
Errors outside a stream have an HTTP status and a body like:
{ "detail": { "code": "run_in_progress", "message": "A reply is already being written." } }
| Status | Codes |
|---|---|
401 | unauthorized |
402 | out_of_credits |
403 | missing_scopeforbiddenagent_not_availableplan_requiredAI_DISABLEDAI_FEATURE_DISABLEDAI_STAFF_ONLYAI_MONTHLY_CAP_REACHED |
404 | conversation_not_foundapproval_not_foundagent_not_found |
409 | run_in_progressapproval_conflictno_pending_tool_calls |
413 | payload_too_large |
422 | challenge_failedinvalid_requestinvalid_schemainvalid_template |
429 | rate_limitedretry_afterRetry-After |
503 | unavailable |
Errors during a stream arrive as an error event instead.