Skip to main content

Scripts and agents

Anything that can hold a bearer token and read a stream can use the API. Get a key from rewr.it/account; see API keys.

curl

curl -N https://rewr.it/api/humanize \
-H "Authorization: Bearer $REWRIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"It is important to note that we should leverage this.","register":"slack"}'

-N disables buffering. Without it the stream looks like a hang.

A shell one-liner that prints the rewrite

rewrit() {
curl -sN https://rewr.it/api/humanize \
-H "Authorization: Bearer $REWRIT_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -Rn --arg t "$(cat)" '{text:$t, register:"email"}')" \
| sed -n 's/^data: //p' \
| jq -rj 'select(.type=="delta") | .text'
}
pbpaste | rewrit

Node

const res = await fetch("https://rewr.it/api/humanize", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.REWRIT_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ text: draft, register: "email" }),
});

if (!res.ok) {
const { error, code } = await res.json();
throw new Error(`${res.status} ${code ?? ""}: ${error}`);
}

let out = "";
for await (const chunk of res.body.pipeThrough(new TextDecoderStream())) {
for (const line of chunk.split("\n")) {
if (!line.startsWith("data: ")) continue;
const event = JSON.parse(line.slice(6));
if (event.type === "delta") out += event.text;
if (event.type === "error") throw new Error(event.message);
}
}

Two things this sketch skips that a real client should not: an SSE frame can be split across chunks, so buffer until you have a complete line, and a trailing NOTES: block should be split off before you show the rewrite.

Things worth getting right

  • Handle 402 and 429 properly. See Errors. Do not retry a 402 in a loop; it will not clear.
  • Do not log the draft. The server does not. A wrapper that writes every request to a log file undoes the whole privacy story on your side of the wire.
  • One key per tool. Five keys per account, revocable individually. When a laptop goes missing you want to revoke one thing, not everything.
  • Check the facts anyway. The engine will not add a claim, but an automated pipeline that never shows a human the diff has removed the step where anyone would notice if it did.