---
name: megachad
description: Adds megachad (megachadcua.com) decisions to code. Send text or speech plus a schema of questions (one of N options, yes/no, or a scale) and get one calibrated answer per field with a confidence; the model decides in ~17 ms. Use when building intent or UI-action selection for computer-use agents, voice commands, call routing, ticket triage or form filling from speech, or when the user mentions megachad, megachadcua or MEGACHAD_API_KEY.
---

# megachad

megachad (https://megachadcua.com) is a decision model API. Send text (or live speech) plus a schema of questions; get one calibrated answer per field, with a confidence. The model decides in ~17 ms. Each field is one of N options, yes/no, or a scale.

## Steps

1. Check the key: run `test -n "$MEGACHAD_API_KEY" && echo set || echo missing`. If missing, stop. Ask the user to sign up at https://megachadcua.com/login?signup=1 ($2 free, no card) and put the key in `MEGACHAD_API_KEY` (shell profile, secret manager, or a gitignored `.env`). Don't sign up for them.
2. Never hardcode, commit, print or log the key. Never put it in a URL or in browser code. Make sure `.env` is in `.gitignore`.
3. Prove the key works with the curl below. 401 `invalid_key`: wrong key. 403 `email_unverified`: the user confirms their email. 402: the user adds a card at https://megachadcua.com/app.
4. Integrate with raw HTTP unless the project already uses an SDK: no dependency to break. Python and JavaScript versions with retries are in https://megachadcua.com/docs.md under "Retries and idempotency".
5. Design the schema (rules below), add a confidence threshold, and mock the HTTP call in tests.

## Call

```bash
curl https://api.megachadcua.com/v1/decide \
  -H "Authorization: Bearer $MEGACHAD_API_KEY" \
  -H "content-type: application/json" \
  -d '{"schema": {"action": {"question": "What should the agent do?", "options": ["Click Sign in", "Scroll down", "Nothing yet"]}}, "text": "take me to sign in"}'
```

Response (200):

```json
{"session_id": "dcd_C8o5VFBm5AH65L7e", "fields": {"action": {"value": "Click Sign in", "confidence": 0.98, "probabilities": {"Click Sign in": 0.98, "Scroll down": 0.012, "Nothing yet": 0.008}}}, "transcript": "take me to sign in", "latency_ms": 112, "model_ms": 15.2, "usage": {"credits": 1}}
```

- Field kinds: `{"question", "options": [...]}` (value: the option text), `{"question", "type": "yes_no"}` (value: true/false), `{"question", "scale": [low ... high]}` (value: the level, plus `level` index).
- `text`: a string, or `[{"speaker": "user" | "other", "text": "..."}]`. Max 200,000 characters; schema max 64 KB.
- Batch: `POST /v1/decide/batch` with `{"schema", "items": [{"id", "text"}]}`, up to 50 items; failed items come back `ok: false`, unbilled.
- Live voice: `WS /v1/listen`. See https://megachadcua.com/docs.md.

## Schema rules

- One question per field; split multi-part questions into fields.
- Short, distinct, mutually exclusive options, worded as the user sees them. Map the verbatim value to your ids.
- Always include a way out: "Nothing yet" (nothing asked yet) and "Not sure" or "Other" (nothing fits).
- yes/no for binary questions, scale (low to high) for ordered levels.

## Confidence and errors

- Act at or above a threshold (start at 0.85); below it, confirm with the user. `confidence` can be `null`: treat as unsure.
- A human confirms destructive, financial or medical actions. Medical: it routes and structures for clinicians; it doesn't diagnose.
- Errors are `{"error": {"code", "message"}}`. Retry 409, 429, 500, 502, 503 with backoff and `Retry-After`, reusing one `Idempotency-Key` (a UUID per request) so retries aren't billed twice. Don't retry 400, 401, 402, 403, 413, 422.

## SDKs, CLI, MCP

- Python: `pip install megachad` (0.1.0): `megachad.decide(schema, text)`, `adecide`, `listen`, `listen_mic`.
- JavaScript: `npm i megachad` (0.1.0): `decide({schema, text})`, `listen`.
- CLI: `uvx megachad decide --text "..." --options "A,B,C"`.
- MCP: `claude mcp add megachad -e MEGACHAD_API_KEY=$MEGACHAD_API_KEY -- npx -y megachad-mcp` (tools `choose`, `decide`).
- Not published yet (coming in 0.1.1): `decide_batch`, `decideBatch`, `megachad batch`, SDK retries. Use raw HTTP for batch and retries.

## Reference

- Everything in one file: https://megachadcua.com/llms-full.txt
- API docs: https://megachadcua.com/docs.md
- Runtime agents, schema design, tool definitions: https://megachadcua.com/agents.md
- Pricing: 10¢ per 1,000 decisions, 6¢ a minute of voice: https://megachadcua.com/pricing.md
