SDKs

Official client libraries for TypeScript and Python. Each provides one method per endpoint, typed errors, and a retry policy that never resends a request that may have been charged.

LanguagePackageInstallRequirements
TypeScript and JavaScript@writehuman/sdk 0.2.0npm install @writehuman/sdkNode 18 or later, or any runtime with a global fetch. No dependencies.
Pythonwritehuman 0.2.0pip install writehumanPython 3.9 or later. AsyncWriteHuman has the same methods for asyncio.

Version 0.2.0 of both packages supports all API features except freezing. To send freeze_citations, call the REST API directly. <freeze> tags are part of text and are supported by the SDKs.

Calling the API#

Create a single client instance and reuse it. Both clients take the API key as an argument. The samples read it from an environment variable.

import { WriteHuman } from "@writehuman/sdk"; const wh = new WriteHuman({ apiKey: process.env.WRITEHUMAN_API_KEY! }); // Humanize text. All options are optional.const out = await wh.humanize(text, { tone: "professional", language: "English" });console.log(out.results[0]); // Score text for AI authorship.const scan = await wh.detect(text, { includeSentences: true });console.log(scan.ai_probability, scan.predicted_class); // Retrieve usage. This call is not billed.const usage = await wh.usage();console.log(usage.topup_balance);

Responses contain the same fields as the REST API: see humanize, detect and usage. In TypeScript, responses are typed objects. In Python, responses are dictionaries, and the package exports type definitions for static type checkers.

MethodTypeScriptPython
Humanizewh.humanize(text, { tone, language, enhanced, timeoutMs })wh.humanize(text, tone=None, language=None, enhanced=False, timeout=None)
Detectwh.detect(text, { language, includeSentences, timeoutMs })wh.detect(text, language=None, include_sentences=False, timeout=None)
Usagewh.usage({ timeoutMs })wh.usage(timeout=None)

Async Python#

AsyncWriteHuman provides the same three methods as coroutines.

import osfrom writehuman import AsyncWriteHuman async with AsyncWriteHuman(os.environ["WRITEHUMAN_API_KEY"]) as wh:    out = await wh.humanize(text)

Errors#

In the official SDKs every failure is a subclass of WriteHumanError carrying code, status and the last Retry-After (retry_after in Python, retryAfter in TypeScript). InsufficientBalanceError adds words_remaining / wordsRemaining, and PlanRequiredError adds upgrade_url / upgradeUrl. A code the installed SDK version does not know becomes APIError with code preserved. A response that is not the API's JSON, no response within the client timeout, or a failed connection becomes ProtocolError, ClientTimeoutError or ConnectionError, with no code.

import { InsufficientBalanceError, RateLimitError } from "@writehuman/sdk"; try {  await wh.humanize(text);} catch (e) {  if (e instanceof InsufficientBalanceError) {    console.log("out of words:", e.wordsRemaining);  } else if (e instanceof RateLimitError) {    console.log("retry in", e.retryAfter, "seconds");  } else {    throw e;  }}

The Errors page lists the error class for each code.

Retries#

A 429, 503 or 504 response that includes the API's error body is retried after the interval given in Retry-After, up to a maximum of 2 retries. If Retry-After exceeds 60 s, as with an authentication lockout, the SDK does not wait and raises the error immediately, with the interval available as retry_after (Python) or retryAfter (TypeScript). A humanize or detect request that may have been charged is never resent.

No other failures are retried. On humanize and detect, a client timeout or a dropped connection raises an error immediately, because the request may have completed and been charged. usage is read-only and not billed, so it is also retried in these cases.

SettingTypeScriptPythonDefault
Retries per requestmaxRetriesmax_retries2
Maximum Retry-After honoredmaxRetryAfterMsmax_retry_after60 seconds
Wait time when no Retry-After is sentfallbackRetryAfterMsfallback_retry_after2 seconds

Timeouts#

A timeout is a deadline for the entire response, not a per-read limit. The defaults are 120 seconds for humanize, 30 for detect and 15 for usage. Timeouts can be set for the client, per operation or per call.

const wh = new WriteHuman({  apiKey: process.env.WRITEHUMAN_API_KEY!,  timeoutMs: { humanize: 180_000 },  maxRetries: 3,}); // Or for one call:await wh.detect(text, { timeoutMs: 10_000 });

The API responds to every humanize request within 170 seconds. With the default 120-second timeout, a slow request can complete, and be charged, after the client has timed out. For long documents, increase the timeout to 180 seconds. See Production best practices.