Playtest API.

Add word count and reading time to any page with one API call

Updated

Readers like to know how long a post takes to read before they start. You can work it out yourself, but word counting gets fiddly once you handle punctuation, apostrophes and accented letters. Playtest API does it in one request.

1. Get an API key

Create a free account, then make a key under API keys in the dashboard. The free plan includes 100 requests a month.

2. Send the text

curl -X POST https://api-playtest.plxi.us/v1/example/analyze \
  -H "X-API-Key: $PLAYTEST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "The quick brown fox jumps over the lazy dog. The dog sleeps.", "top": 3}'

top is how many of the most used words to return.

3. Use the result

{
  "characters": 60,
  "characters_no_spaces": 49,
  "words": 12,
  "sentences": 2,
  "paragraphs": 1,
  "reading_time_seconds": 4,
  "top_words": [
    { "word": "dog", "count": 2 },
    { "word": "brown", "count": 1 },
    { "word": "fox", "count": 1 }
  ],
  "credits": 1
}

Reading time is the word count at 230 words a minute, rounded up to the next second. To show minutes:

const minutes = Math.max(1, Math.round(data.reading_time_seconds / 60));
label.textContent = `${minutes} min read`;

When to call it

Call it when a post is saved, not on every page view, and store the numbers with the post. One call per save keeps you well inside the free plan.