Browse the docs
Developers
Developer API reference
Every /v1 endpoint — authentication, scopes, limits, request and response shapes, streaming chat and errors.
The Habitat API lets your code create agents, teach them, publish them and talk to them. It's a JSON REST API under /v1 on your Habitat origin, with Server-Sent Events for streaming chat. Try every endpoint in the playground.
Base URL https://YOUR-HABITAT/v1
Auth Authorization: Bearer hb_sk_…
Format JSON (application/json), SSE for chat streams, multipart/form-data for file uploads
Authentication#
Create keys in Account → Developers. Each key belongs to your account and carries a set of scopes. The secret (hb_sk_…) is shown once; Habitat stores only its SHA-256 hash and shows the first characters (the prefix) afterwards. You can have up to 10 active keys and revoke any key instantly.
curl https://YOUR-HABITAT/v1/agents -H "Authorization: Bearer $HABITAT_API_KEY"
The API only accepts API keys — browser cookies are ignored, so a signed-in session can't be used to call /v1. Keep keys on your server; anyone holding a key can act as your account within its scopes.
Scopes
| Scope | Allows |
|---|---|
agents:read | List and read agents, their tools and knowledge sources |
agents:write | Create, update, publish and unpublish your agents |
chat | Chat with your agents and with published public or unlisted agents |
knowledge:write | Add knowledge sources to your agents |
analytics:read | Read aggregate analytics for your agents |
A request without the needed scope fails with 403 forbidden.
Rate limits#
Every authenticated response carries rate-limit headers:
| Header | Meaning |
|---|---|
X-RateLimit-Limit | Requests this key may make per UTC day (1,000 by default; set by the admins) |
X-RateLimit-Remaining | Requests left today |
X-RateLimit-Reset | Unix time (seconds) when the daily quota resets — 00:00 UTC |
X-RateLimit-Burst-Limit | Requests per minute per key (60) |
X-RateLimit-Burst-Remaining | Requests left in the current minute |
Retry-After | On 429 responses: seconds to wait |
X-Request-Id | Identifier for this request — include it when you report a problem |
Chat requests additionally count toward your account's daily message limit and each agent's daily limit (see Models & limits). Those limits return 429 rate_limited with details.scope set to burst, user_daily, agent_daily, api_key_daily or platform_budget, plus details.resetAt.
CORS#
The API sends Access-Control-Allow-Origin: * and answers OPTIONS preflights, so it can be called from browsers. Credentials (cookies) are never used. Calling the API from a public web page exposes your key — do that only for internal tools; use the embed for public sites.
Errors#
Errors are JSON with a stable code:
{
"error": {
"code": "invalid_input",
"message": "Unrecognized key: \"bogus\"",
"details": [{ "path": "", "message": "Unrecognized key: \"bogus\"" }]
}
}
| Status | Typical codes | When |
|---|---|---|
| 400 | bad_request, invalid_input | Validation failed — details lists the fields |
| 401 | unauthorized | Missing, invalid or revoked key |
| 403 | forbidden, account_required, agent_limit | Missing scope, an action that needs a registered account, or the account's agent limit |
| 404 | not_found | Unknown endpoint, or an agent you can't see |
| 409 | handle_unavailable | The handle is already taken |
| 415 | unsupported_media_type | Wrong Content-Type |
| 422 | incomplete | The agent isn't ready to publish (details.issues lists what's missing) |
| 429 | rate_limited, quota_exceeded | A limit was reached — see Retry-After and details |
| 5xx | internal, provider errors | Something failed on our side or at the model provider |
Private agents of other accounts return 404, exactly like agents that don't exist.
Agent objects#
{id} in every path accepts the agent's UUID or its handle.
Agents you own come back as an owner view with the full configuration:
{
"access": "owner",
"url": "https://YOUR-HABITAT/agent/atlas",
"id": "6337491a-f6ba-4ca8-8be8-fde04b420ed3",
"handle": "atlas",
"name": "Atlas",
"tagline": "A research companion that cites its sources.",
"description": "…",
"category": "research",
"avatar": { "kind": "organism", "style": "floater", "seed": "atlas", "palette": ["#F7B7D2", "#E07BA8", "#7A2E52"], "expression": "happy" },
"banner": { "kind": "pattern", "pattern": "waves", "seed": "atlas", "palette": ["#F7B7D2", "#E07BA8", "#7A2E52"] },
"theme": "moss",
"languages": ["en"],
"visibility": "public",
"status": "published",
"disabledReason": null,
"config": {
"personality": { "preset": "research", "style": "Conversational and clear", "tone": "Warm", "traits": ["curious"], "purpose": "…", "instructions": "", "responseLength": "medium", "language": "auto", "expertise": [], "boundaries": "", "customSystemPrompt": null, "instructionsPrivate": true },
"model": { "id": null, "creativity": 0.5, "maxOutputTokens": 900, "contextBudget": "medium", "reasoningEffort": "off", "useOwnKey": false },
"tools": { "enabled": ["web_search", "calculator"] },
"memory": { "mode": "conversation", "sharedNotes": [] },
"knowledge": { "citations": true, "strict": false },
"greeting": "Hi, I'm Atlas.",
"starters": ["What should I read next?"],
"embed": { "enabled": true, "allowedOrigins": [], "accent": null, "position": "right" }
},
"remixable": false,
"remixedFrom": null,
"featured": false,
"publishedAt": "2026-11-30T19:02:11.000Z",
"currentVersion": 1,
"stats": { "conversations": 12, "messages": 40, "favorites": 3 },
"createdAt": "2026-11-30T18:40:02.000Z",
"updatedAt": "2026-11-30T19:02:11.000Z"
}
Other people's published agents come back as a public view ("access": "public") with the public profile only: identity, capabilities, starters, greeting, memory mode, stats, creator summary and ownership status — never private instructions or configuration.
List your agents#
GET /v1/agents · scope agents:read
| Query | Description |
|---|---|
status | draft, published or disabled |
limit | 1–100, default 50 |
offset | Default 0 |
{
"data": [
{
"id": "…", "handle": "atlas", "name": "Atlas", "tagline": "…", "category": "research", "avatar": { "kind": "organism", "…": "…" },
"visibility": "public", "status": "published", "publishedAt": "…", "currentVersion": 1,
"stats": { "conversations": 12, "messages": 40, "favorites": 3 },
"tools": ["web_search", "calculator"], "modelId": null, "knowledgeSources": 2, "memoryMode": "conversation",
"url": "https://YOUR-HABITAT/agent/atlas", "createdAt": "…", "updatedAt": "…"
}
],
"total": 1, "limit": 50, "offset": 0, "hasMore": false
}
Create an agent#
POST /v1/agents · scope agents:write · returns 201 with { "data": <owner view> }
The agent starts as a draft. Only name is required; everything else falls back to sensible defaults (a handle derived from the name, an organism avatar, the Friendly preset, the platform default model).
curl https://YOUR-HABITAT/v1/agents \
-H "Authorization: Bearer $HABITAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Atlas",
"handle": "atlas-research",
"tagline": "A research companion that cites its sources.",
"category": "research",
"config": {
"personality": { "preset": "research", "purpose": "Answer questions using the knowledge base." },
"tools": { "enabled": ["web_search", "calculator"] },
"greeting": "Hi, I am Atlas.",
"starters": ["Summarise my notes"]
}
}'
| Field | Type | Notes |
|---|---|---|
name | string | Required, 2–48 characters |
handle | string | 3–30 chars, [a-z][a-z0-9_-], unique |
tagline, description | string | Up to 120 / 4,000 characters |
category | string | research, productivity, crypto, education, coding, entertainment, creative, business, personal, community |
avatar | object | An organism spec, or an image previously uploaded to Habitat |
theme | string | moss, meadow, dusk, tide, bloom, ember |
languages | string[] | Default ["en"] |
remixable | boolean | Allow remixes |
visibility | string | Used when you publish |
config | object | Partial configuration: personality, model, tools, memory, knowledge, embed (each merged section by section), greeting, starters |
Unknown fields are rejected. Account limits apply (20 agents by default).
Get an agent#
GET /v1/agents/{id} · scope agents:read · returns { "data": <owner or public view> }
Update an agent#
PATCH /v1/agents/{id} · scope agents:write · owner only · returns { "data": <owner view> }
Send any subset of the create fields. Configuration patches are merged per section, so {"config": {"model": {"creativity": 0.3}}} changes only creativity.
curl -X PATCH https://YOUR-HABITAT/v1/agents/atlas-research \
-H "Authorization: Bearer $HABITAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"tagline": "Reads widely, thinks clearly.", "config": {"model": {"creativity": 0.3}}}'
Chat#
POST /v1/agents/{id}/chat · scope chat
Talk to an agent you own, or to any published public or unlisted agent. Conversations are stored on your account (channel api) according to the agent's memory mode.
| Field | Type | Notes |
|---|---|---|
message | string | Required |
conversationId | uuid | null | Continue a conversation you started earlier |
stream | boolean | Default true (SSE). false returns one JSON response |
history | array | Only for agents with memory mode none: prior {role, content} turns you keep |
regenerate | boolean | Re-answer the last message of the conversation |
Streaming (default)
The response is text/event-stream. Each event is event: <type> followed by data: <json>; lines starting with : are keep-alives.
curl -N https://YOUR-HABITAT/v1/agents/atlas/chat \
-H "Authorization: Bearer $HABITAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"message": "What is 12*7?"}'
event: meta
data: {"type":"meta","conversationId":"bfb7b4…","userMessageId":"…","assistantMessageId":"…","model":{"id":"experiential:claude-haiku-5.5","name":"Claude Haiku 5.5"},"persisted":true}
event: tool_call
data: {"type":"tool_call","id":"call_1","tool":"calculator","label":"Calculating","input":{"expression":"12*7"}}
event: tool_result
data: {"type":"tool_result","id":"call_1","tool":"calculator","ok":true,"output":{"result":"84"},"durationMs":3}
event: text
data: {"type":"text","delta":"12 × 7 = 84."}
event: usage
data: {"type":"usage","tokensIn":680,"tokensOut":7,"costUsd":0.000071,"latencyMs":1382,"firstTokenMs":904,"billedTo":"platform","model":"experiential:claude-haiku-5.5"}
event: done
data: {"type":"done","messageId":"…","citations":[]}
| Event | Payload |
|---|---|
meta | conversationId, message ids, the model answering, whether the turn is persisted |
retrieval | sources: citations retrieved from the agent's knowledge |
memory | used: number of the user's memories recalled |
tool_call | id, tool, label, input |
tool_result | id, tool, ok, output or error, durationMs |
text | delta: the next piece of the answer |
memory_saved | A memory the agent saved for you |
usage | Tokens, costUsd, latency, time to first token, billedTo (platform or byok), model |
error | code, message, retryable — the stream then ends with done |
done | Final messageId and citations (n, sourceId, chunkId, title, url, snippet) |
Limits, permissions and validation are checked before streaming starts, so those failures arrive as normal HTTP errors rather than inside the stream.
JSON ("stream": false)
{
"data": {
"conversationId": "bfb7b4…",
"messageId": "…",
"text": "The Habitat API lives under /v1. [1]",
"citations": [{ "n": 1, "sourceId": "…", "chunkId": "…", "title": "API facts", "url": null, "snippet": "The Habitat public API lives under /v1…" }],
"usage": { "tokensIn": 912, "tokensOut": 14, "costUsd": 0.000097, "latencyMs": 1210, "firstTokenMs": 820, "billedTo": "platform", "model": "experiential:claude-haiku-5.5" },
"tools": []
}
}
Knowledge#
Add a source
POST /v1/agents/{id}/knowledge · scope knowledge:write · owner only · returns 202 with { "data": <source> }
Send JSON for text, FAQ and website sources:
{ "type": "text", "title": "Team notes", "body": "Our support hours are 9:00–17:00 CET." }
{ "type": "faq", "title": "FAQ", "items": [{ "q": "Where are keys created?", "a": "On /app/developers." }] }
{ "type": "url", "url": "https://example.com/docs", "maxPages": 10 }
Or upload a file (PDF, TXT, Markdown or CSV) as multipart/form-data with a file field:
curl https://YOUR-HABITAT/v1/agents/atlas/knowledge \
-H "Authorization: Bearer $HABITAT_API_KEY" \
-F "file=@handbook.pdf"
Indexing runs in the background, so new sources start as queued. Poll the list endpoint until status is ready (or error, with a message). Size and count limits, duplicate detection and the website crawling policy are described in Knowledge.
List sources
GET /v1/agents/{id}/knowledge · scope agents:read · owner only
{
"data": [
{
"id": "…", "agentId": "…", "kind": "text", "title": "Team notes", "status": "ready", "error": null,
"filename": null, "mime": null, "sizeBytes": 0, "url": null, "documentCount": 1, "chunkCount": 1, "tokenCount": 18,
"lastIndexedAt": "…", "createdAt": "…", "updatedAt": "…", "warnings": [], "fileUrl": null
}
]
}
Tools#
GET /v1/agents/{id}/tools · scope agents:read
Returns the tools enabled on the agent with live availability. For agents you own, catalog lists every tool you could enable.
{
"data": [
{
"id": "calculator", "name": "Calculator", "description": "Exact arithmetic, percentages, unit conversions…",
"provider": "Habitat (built-in, mathjs)", "capabilities": ["…"], "permissions": ["…"], "cost": "Free",
"status": "available", "available": true, "unavailableReason": null,
"limits": { "perUserDaily": null, "perConversation": 60 }, "enabled": true
}
],
"catalog": [ { "id": "web_search", "…": "…", "enabled": false } ]
}
To change which tools are enabled, PATCH the agent with {"config": {"tools": {"enabled": ["web_search", "calculator"]}}}.
Analytics#
GET /v1/agents/{id}/analytics?days=30 · scope analytics:read · owner only · days 1–90
Aggregate analytics only — never conversation content:
{
"data": {
"agentId": "…", "days": 30, "since": "…", "generatedAt": "…",
"totals": { "conversations": 12, "messages": 40, "uniqueUsers": 7, "returningUsers": 3, "avgLatencyMs": 1300, "tokensIn": 30211, "tokensOut": 8122, "costUsd": 0.0041, "toolRuns": 9, "toolErrors": 0, "…": "…" },
"lifetime": { "conversations": 12, "messages": 40, "favorites": 3 },
"daily": [{ "date": "2026-11-30", "messages": 40, "conversations": 12, "uniqueUsers": 7 }],
"weekly": { "messages": { "thisWeek": 40, "lastWeek": 0, "pct": null } },
"tools": [{ "toolId": "calculator", "runs": 9, "errors": 0, "avgDurationMs": 4 }],
"knowledge": { "sources": [{ "id": "…", "title": "Team notes", "citedInPeriod": 5 }] },
"channels": [{ "channel": "api", "conversations": 4 }]
}
}
"Messages" counts messages people sent; assistant replies are in totals.replies.
Publish and unpublish#
POST /v1/agents/{id}/publish · scope agents:write · owner only
{ "visibility": "unlisted" }
visibility is public (listed in Explore; requires a registered account), unlisted or private, default public. Returns { "data": <owner view>, "firstPublish": true, "version": 1 }. If something is missing, the response is 422 incomplete with details.issues listing each problem and the builder step that fixes it (for example a missing short description or an unavailable tool).
POST /v1/agents/{id}/unpublish · scope agents:write · owner only — returns the agent to draft; its page, embeds and API chat stop serving it.
Not available yet#
- Webhooks — there are no event callbacks yet. Poll instead (for example, the knowledge list for indexing status).
- Deleting agents and deleting knowledge sources are available in the web app, not through the API.