API usage

brainlets.ai is API-first. The full API reference is available at /api/docs (Swagger UI). This page is the on-ramp.

Quick start

Create a public brainlet and invoke it. No auth on the invoke side because public: true means anyone with the URL can run it (you pay).

curl -X POST https://brainlets.ai/api/brainlets/ \
  -H "Authorization: Bearer <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "hello",
    "public": true,
    "spec": {
      "system_prompt": "Be concise and helpful.",
      "tool_grants": ["http_fetch"]
    }
  }'

# The response includes a slug; invoke it:
curl -X POST https://brainlets.run/<slug>/ \
  -d "Summarize today's top story on Hacker News"

Authentication & API keys

Every authenticated API call uses a Bearer JWT. Mint long-lived API keys from your dashboard or the /api/keys/ endpoint. The JWT carries your user identity and (for API keys) a revocable id.

# Mint
curl -X POST https://brainlets.ai/api/keys/ \
  -H "Authorization: Bearer <existing-token>" \
  -d '{"name":"my-cli"}'
# → {"id":"…","name":"my-cli","key":"eyJ…"}  (shown once — save it)

# Revoke (irreversible; key fails immediately on all surfaces)
curl -X POST https://brainlets.ai/api/keys/<id>/revoke \
  -H "Authorization: Bearer <token>"

Session cookies are accepted by the dashboard API only. Brainlet invocation (brainlets.run) accepts Bearer tokens only — no cross-origin cookies.

Public vs private brainlets

A brainlet is created with public: false by default. Private brainlets require the owner's API key (or a short-lived dashboard invoke token) on every invocation. Public brainlets accept any caller; you still pay for invocations.

# Private — default; invokes require Bearer
curl -X POST https://brainlets.run/<private-slug>/ \
  -H "Authorization: Bearer <api-key>" \
  -d "input goes here"

# Public — set at creation; no auth needed on invoke
curl -X POST https://brainlets.run/<public-slug>/ \
  -d "input goes here"

Toggle public via PUT /api/brainlets/{id}. Private brainlets are owner-only; sharing means making it public.

Tool grants

Grants tell the agent which tool families it can call. Without any grants the agent is text-only. Available today:

"tool_grants": [
  "shell",      // run shell commands (see the tools reference)
  "http_fetch", // GET/POST/PUT/PATCH/DELETE; body + body_path + headers + grep
  "file",       // file_read/write/list/stat/delete/move/mkdir under /work
  "image",      // image_info/convert/resize/crop/rotate/thumbnail/compose
                // + image_exif_read/strip
  "data"        // data_base64_encode/decode + data_url_encode/decode
]

egress_allowlist (hosts, or URLs, stored as their host) and services (ids of your linked services, whose hosts are allowed and whose keys are added to requests to them) control what http_fetch and shell can reach. Anything else is blocked at the proxy. Both are part of the versioned spec: see Allowed sites below.

Tools reference: every function, its options, and the programs shell can run →

Allowed sites

What a brainlet's network tools may reach is part of its spec, versioned with the rest: custom hosts in egress_allowlist (and dns_allowlist), and your linked services in services. A service's hosts are allowed by naming it, and its key is added to requests to them; the agent never sees it. Find a service's id with GET /api/links/.

curl https://brainlets.ai/api/links/ -H "Authorization: Bearer <api-key>"

# Publish a version that uses one service and one custom host
curl -X PUT https://brainlets.ai/api/brainlets/<id> \
  -H "Authorization: Bearer <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "weather",
    "spec": {
      "system_prompt": "Report the weather for the city in the input.",
      "tool_grants": ["http_fetch"],
      "services": ["<link-id>"],
      "egress_allowlist": ["https://wttr.in/"],
      "dns_allowlist": ["wttr.in"]
    }
  }'

A URL in an allowlist is stored as its host (https://wttr.in/ becomes wttr.in). A service whose link you delete stays in the spec; its runs go without it and list it under blocked hosts (via "service"). An MCP server service (provider "mcp", with mcp_url) also needs its tools granted: "service_tools": {"<link-id>": ["send_sms"]}, or ["*"] for all; the model calls them as <service>__<tool>.

Invocations & rating

Every invocation creates a row with outcome, duration, token usage, and a telemetry blob. List your own, newest first, 50 at a time: the response is {items, next_before}; pass next_before as before for the next (older) page. Narrow it with brainlet_id, since and until (ISO 8601, UTC if no zone) and outcome (repeatable).

# List
curl https://brainlets.ai/api/invocations/ \
  -H "Authorization: Bearer <api-key>"

# Older runs, errors only, since a date
curl "https://brainlets.ai/api/invocations/?before=<next_before>&outcome=model_error&since=2026-11-01" \
  -H "Authorization: Bearer <api-key>"

# Detail
curl https://brainlets.ai/api/invocations/<id> \
  -H "Authorization: Bearer <api-key>"

# Rate (thumbs: -1, 0, +1) — feeds future model training
curl -X POST https://brainlets.ai/api/invocations/<id>/rate \
  -H "Authorization: Bearer <api-key>" \
  -H "Content-Type: application/json" \
  -d '{"rating": 1}'

You can only rate invocations of brainlets you own. The dashboard exposes rating UI on the brainlet run harness.