Rewrite API
One endpoint rewrites text so it reads as written by a person. One gives an agent a key after a person approves it. JSON in, JSON or server-sent events out. Agents should read /agents.md first.
Authentication
Every request to /api/v1/rewrite carries a key in the Authorization header. Keys look like bw_live_ followed by 43 URL-safe characters. An agent gets one through POST /api/v1/trial below. A person can also mint and revoke them at /keys after signing in with Google. We store only a keyed hash of each key, so a key is shown exactly once, when minted.
Authorization: Bearer bw_live_...
POST /api/v1/rewrite
| Field | Type | Notes |
|---|---|---|
voice | string | Optional. A voice id from /api/v1/voices. The default, human, has no named writer. |
text | string | Required. Up to 6000 words. Plain text; markdown in the input is fine, the output never has any. |
stream | boolean | Default false. true returns text/event-stream. Not available with mode: "markdown" (400). |
mode | string | "plain" (default) rewrites the whole text as one piece. "markdown" keeps structure: front matter, code fences, tables, headers, link-only lines, list and blockquote markers, and any line under 12 words stay byte for byte; each paragraph or list item of 12 words or more is rewritten on its own, in parallel. The response adds blocks_rewritten. |
curl https://betterwriting.ai/api/v1/rewrite \
-H "Authorization: Bearer $BW_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"We are thrilled to announce our new pricing."}'Response, 200:
{
"id": "7a1f...",
"voice": "human",
"text": "We changed our prices. Here is why.",
"words_in": 8,
"words_out": 7,
"model": "claude-fable-5-1",
"prompt_version": "v1",
"latency_ms": 2140
}The header x-quota-remaining-words reports what is left. On a paid plan x-plan names the plan and x-quota-resets-at says when the week ends.
Streaming
With "stream": true the response is text/event-stream. Each event is a data: line of JSON. Text arrives as {"delta":"..."} events; the last event is {"done":true, ...} with the same fields as the non-streaming response, including the final cleaned text. Replace what you displayed with that final text: it has markdown stripped and em dashes removed, which the deltas cannot guarantee mid-stream. An error after the stream opened arrives as {"error":"...","message":"..."}.
curl -N https://betterwriting.ai/api/v1/rewrite \
-H "Authorization: Bearer $BW_KEY" \
-H "Content-Type: application/json" \
-d '{"voice":"pg","text":"...","stream":true}'
data: {"delta":"We"}
data: {"delta":" changed our prices."}
data: {"done":true,"id":"...","voice":"pg","text":"We changed our prices. ...","words_in":8,"words_out":7,"model":"...","prompt_version":"v1","latency_ms":2140}POST /api/v1/trial
This is how an agent gets a key. A person approves it once in a browser, so a script cannot mint keys for itself. Send a stable device identifier and, if you like, the agent's name. The answer is a pair of codes.
curl https://betterwriting.ai/api/v1/trial \
-H "Content-Type: application/json" \
-d '{"device":"<sha256 of hostname+user>","agent":"Claude Code"}'
202 {"status":"approval_required","device_code":"bwd_...","user_code":"ABCD-EFGH",
"verify_url":"https://betterwriting.ai/activate?code=ABCD-EFGH","poll_url":"https://betterwriting.ai/api/v1/trial/poll",
"interval":3,"expires_in":900}
429 {"error":"rate_limited"} with Retry-AfterShow the person verify_url. They sign in with Google and click Approve. The same device gets the same pending pair back until it expires, 15 minutes later.
POST /api/v1/trial/poll
curl https://betterwriting.ai/api/v1/trial/poll \
-H "Content-Type: application/json" \
-d '{"device_code":"bwd_..."}'
202 {"status":"pending","interval":3}
200 {"api_key":"bw_live_...","plan":"trial","limits":{...}}
403 {"error":"denied"}
410 {"error":"expired"} or {"error":"claimed"}The key comes back exactly once. Store it in ~/.betterwriting/config.json with mode 0600. Approving the same device again replaces its old key. When the free words are used up, rewrites answer 402 with {"error":"trial_exhausted","upgrade_url":"https://betterwriting.ai/pricing"}.
GET /api/v1/voices
No auth. Returns the roster with what is serving each voice right now.
{
"voices": [
{
"id": "human",
"name": "Human",
"handle": null,
"status": "live",
"prompt_version": "v1",
"model": "claude-fable-5-1",
"served_by": "pg",
"default": true
},
{
"id": "pg",
"name": "Paul Graham",
"handle": "paulg",
"status": "live",
"prompt_version": "v1",
"model": "claude-fable-5-1"
},
{
"id": "jz",
"name": "Julie Zhuo",
"handle": "joulee",
"status": "live",
"prompt_version": "v1",
"model": "claude-fable-5-1"
}
]
}Errors
Errors are JSON: {"error":"<code>","message":"<human text>"}.
| Status | error | When |
|---|---|---|
| 400 | bad_request | Body is not JSON, text is empty, mode is unknown, or stream was combined with mode: "markdown". |
| 401 | unauthorized | Missing, malformed, unknown or revoked key. |
| 402 | trial_exhausted | The free trial is used up. upgrade_url is where a person picks a plan. |
| 404 | unknown_voice | No such voice id. |
| 413 | too_long | More than 6000 words. |
| 429 | limit_reached | A paid plan's weekly limit is reached. resets_at and Retry-After say when the week ends. |
| 429 | quota_exceeded | The free daily quota is reached. Retry-After gives the seconds until 00:00 UTC. |
| 429 | rate_limited | Burst limit per IP. Retry-After: 60. |
| 503 | upstream, refused | The model backend failed or declined the text. Quota is refunded. |
Limits
The trial is 15,000 words in total. On a paid plan you get a weekly limit, and the week starts the first time you use it. We count the words you send, and the smallest call costs 25. What if a request would cross a limit? We refuse it and do not count it. The numbers are on the pricing page.
Paid plans are not open yet. Until they are, a key gets 50 rewrites and 20,000 input words per UTC day for free.
Keys
The dashboard at /keys uses the same JSON routes with a session cookie: GET /api/keys lists keys with today's usage, POST /api/keys {"name":"..."} mints one (at most 5 by hand), DELETE /api/keys/:id revokes.
What we log
For each call: the key id, voice, word counts, latency, backend, model and prompt version. Never the text, in or out. See privacy.