Skip to main content

Word count API

Instantly count words, characters, sentences, paragraphs, and get a reading-time estimate.

EndpointPOST https://astraltext.com/api/v1/word-counter
AuthBearer token, free
Sendsinput: text
Returnsresult: text
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

Counts decide things: whether a meta description fits, whether a post is long enough to publish, what reading time to show, whether a field will be truncated. Computing them where the content is created keeps every one of those decisions consistent.

For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.

Example

curl
curl -X POST https://astraltext.com/api/v1/word-counter \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "The first sentence. The second one is a little longer than the first."}'
response
{
  "tool": "word-counter",
  "result": "Words:                  13\nCharacters:             69\nCharacters (no spaces): 57\nSentences:              2\nParagraphs:             1\nReading time:           ~1 min",
  "chars": 163,
  "ms": 5
}

In your language

JavaScript
const res = await fetch("https://astraltext.com/api/v1/word-counter", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "The first sentence. The second one is a little longer than the first."}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();
Python
import os, requests

res = requests.post(
    "https://astraltext.com/api/v1/word-counter",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "The first sentence. The second one is a little longer than the first."},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400input missing or the wrong type.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

What comes back?
A report with word count, character count with and without spaces, sentence count, paragraph count and an estimated reading time.
How is reading time estimated?
From the word count at an average adult reading speed. It is an estimate for display, not a measurement.
How is a word defined?
A run of non-whitespace characters. Hyphenated words count as one, which is what a person counting would say.

Other endpoints

A token takes thirty seconds

Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.

Get a free token