Case Study Writer
Developer reference

API & MCP

Case Study Writer turns your Ounie brain into cited customer case studies. Everything the dashboard does is a REST endpoint and an MCP tool, so an agent can drive it end to end — spending your shared Ounie credits, never able to overdraw.

Authentication

Two credentials work everywhere — send either as a bearer token, or (for MCP clients that can’t set headers) as an ?api_key= query parameter.

KeyWhat it can do
csw_live_…This app’s own key. Mint up to 5 in the dashboard. Can list, read, export, and publish. Cannot reach your brains, so a generation call with it is refused (see below).
ounie_live_…Your fleet master key— an ounie.com developer key with “use across Ounie apps” enabled (ounie.com → Settings → API keys). It forwards upstream to ounie.com, so it grounds generations in your private brain and cites them. Draws the same shared wallet.

The browser dashboard authenticates with the shared .ounie.com session cookie; the same routes accept a bearer key. A bad or missing token returns 401 (never a redirect).

# header form
curl https://case-study.ounie.com/api/studies -H "Authorization: Bearer ounie_live_…"

# query form (for hosts that can't set headers)
curl "https://case-study.ounie.com/api/studies?api_key=csw_live_…"
Why a master key for generation? A case study is composed from — and cited to — your private Ounie brain. Only the master key can read it on your behalf. A per-app csw_live_ key has no upstream credential, so a POST /api/studies (or regenerate) with one returns 403 use_master_key — you were not charged. Reads, listing, and export all work with a csw_live_ key.

Credits & billing

Usage draws your shared Ounie credit wallet (1 credit = 1¢), the same balance every Ounie product spends. Generating (or regenerating) one case study costs a flat 8 credits. If your brain holds nothing on the topic, you’re refunded in full and get a 422 thin_material. Listing, reading, export, publishing, and public views are free forever.

When the wallet is short, a generate returns 402 with a buy_credits_url — an agent can never overdraw. Buy credits at ounie.com.

REST endpoints

Base URL https://case-study.ounie.com. All routes accept the cookie or a bearer key.

GET/api/brains

List the Ounie brains you can build a case study from. Needs a cookie or the master key (it proxies ounie.com).

Response
{ "brains": [ { "id": "…", "name": "…", "sourceCount": 12 } ] }
POST/api/studies

Generate one cited case study. Bills 8 credits (thin → full refund). Grounded → requires the master key.

Request
{
  "brain_ids": ["<uuid>", "..."],   // 1–5 brains
  "brief": "how Acme cut onboarding 60%"   // optional angle
}
Response
{ "ok": true, "study_id": "<uuid>",
  "grounded": true, "credits_spent": 8 }

// 403 use_master_key   — per-app key, no brain access (not charged)
// 402 insufficient_credits { required_credits, balance_credits, buy_credits_url }
// 422 thin_material     — no brain pages matched (not charged)
GET/api/studies

List your case studies (newest first).

Response
{ "studies": [ { "id", "title", "status", "share_slug", … } ] }
GET/api/studies/{id}

Fetch one study you own — full narrative, metrics, quotes, citations.

Response
{ "study": { "title", "challenge", "solution", "results",
  "metrics": [...], "quotes": [...], "citations": [...], … } }
PATCH/api/studies/{id}

Free edit of any field — title, subtitle, the narrative sections, metrics, quotes.

Request
{ "title": "…", "results": "…", "metrics": [ { "label", "value", "detail" } ] }
Response
{ "ok": true }
POST/api/studies/{id}/regenerate

Re-compose from fresh retrieval over the same brains. Re-bills 8 credits. Keeps the share slug + publish state. Requires the master key.

Request
{ "brief": "optional new angle" }
Response
{ "ok": true, "grounded": true, "credits_spent": 8 }
POST/api/studies/{id}/publish

Publish or unpublish the public share page (free). Publishing makes /p/<slug> live.

Request
{ "publish": true }
Response
{ "ok": true, "status": "published", "share_slug": "…" }
GET/api/studies/{id}/export

Download the study as a polished DOCX (free — a read of already-paid work).

Response
200 application/vnd.openxmlformats-officedocument.wordprocessingml.document

MCP server

One endpoint speaks the Model Context Protocol to any host — Claude, Cursor, ChatGPT, the AI SDK, and the Ounie AI Team. Tools are discovered automatically.

Endpoint  https://case-study.ounie.com/api/mcp   (Streamable HTTP; legacy SSE at /api/sse)
Auth      Authorization: Bearer csw_live_…   (or ounie_live_… to ground)
          or https://case-study.ounie.com/api/mcp?api_key=…   (headerless hosts)
ToolCreditsWhat it does
list_brainsfreeYour brains (master key only)
list_studiesfreeYour library
get_studyfreeOne study, full body + citations
export_studyfreeStudy as clean Markdown
generate_case_study8Compose a cited study (master key)
regenerate_case_study8Re-compose (master key)
publish_studyfreePublish/unpublish the /p page
get_credit_balancefreeSpendable Ounie credits
get_pricingfreePublic — no auth required
whoamifreeOwner + key metadata

Connect the Ounie AI Team (TabTab)

The AI Team’s HTTP-MCP entries can’t set an Authorization header, so ride the key on the URL. Add an MCP server with this URL and the AI Team can generate and publish case studies for you:

https://case-study.ounie.com/api/mcp?api_key=ounie_live_…

# use ounie_live_ (your fleet master key) so it can reach your brains.
# a csw_live_ app key connects too, but can only read/list/export/publish.

x402 (pay-per-call)

Case Study Writer does notship an x402 rail: every generation is grounded in your own private Ounie brain, which a keyless payer can’t access — so agent access is API keys / MCP (credits) only.

Get a key

Mint a csw_live_ key in the dashboard, or enable your fleet master key on ounie.com to ground in your brains.