# Text Statistics API - Word, Sentence, Syllable Counts (`eliai/text-statistics`) Actor

Exact counts for any text: characters with and without spaces, words, unique words, sentences, paragraphs, syllables, longest words, per-word and per-sentence averages, and lexical diversity. Unicode-correct. Up to 200 texts per run. Currently listed free - see the Pricing tab.

- **URL**: https://apify.com/eliai/text-statistics.md
- **Developed by:** [Broke to Built](https://apify.com/eliai) (community)
- **Categories:** Developer tools, AI, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Text Statistics API - Word, Sentence, Syllable and Character Counts

**Every count you would want about a text, exact and machine-readable.** Characters with and without
spaces, words, unique words, sentences, paragraphs, syllables, longest words, per-word and
per-sentence averages, and lexical diversity - for up to 200 texts in one run. Currently listed
free; inputs with no words are recorded as such rather than counted.

Enforcing word-count limits in a CMS, QA-ing content length before publish, profiling a dataset
before training, building an editorial dashboard, spotting spun or templated copy: all of it reduces
to counting text properties reliably at scale, which is exactly and only what this does.

### What you get

Per text, one record with these exact fields:

- `ok` - true when the text contained countable words
- `text` - your input, truncated to 280 characters in the record
- `characters` - `withSpaces` and `withoutSpaces`, counted in Unicode code points
- `words`, `uniqueWords`, `sentences`, `paragraphs`, `syllables`
- `averages` - `wordLength`, `wordsPerSentence`, `syllablesPerWord`
- `longestWords` - the five longest distinct words
- `lexicalDiversity` - `uniqueWords / words`, 0 to 1
- `error` - present instead of counts when the input had no words. Never charged.

### Example 1: one text

Input:

```json
{ "text": "The quick brown fox jumps over the lazy dog. It was a bright cold day in April, and the clocks were striking thirteen.\n\nNatural language processing turns raw text into structured insight." }
```

Output (real run, 2026-08-15):

```json
{
  "ok": true,
  "characters": { "withSpaces": 187, "withoutSpaces": 155 },
  "words": 32,
  "uniqueWords": 30,
  "sentences": 3,
  "paragraphs": 2,
  "syllables": 45,
  "averages": { "wordLength": 4.72, "wordsPerSentence": 10.67, "syllablesPerWord": 1.41 },
  "longestWords": ["processing", "structured", "language", "striking", "thirteen"],
  "lexicalDiversity": 0.9375
}
```

Two paragraphs, three sentences, and a lexical diversity of 0.94 - almost every word is distinct,
which is what natural prose looks like.

### Example 2: bulk, for a content audit

Input:

```json
{
  "texts": [
    "First article body...",
    "Second article body...",
    "Third article body..."
  ],
  "maxTexts": 200
}
```

One record per text. Sort the results by `words` to find the thin pages, or by `lexicalDiversity`
ascending to find the repetitive ones.

**When `texts` is filled, the single `text` field is ignored** - you get exactly the texts you
listed, with no filler record.

### Example 3: an input with nothing to count

Input:

```json
{ "text": "!!! ???" }
```

Output:

```json
{ "ok": false, "text": "!!! ???", "error": "No words found in text (punctuation/symbols only)" }
```

Recorded so you can see it happened, rather than silently dropped or counted as a zero-word success.
A dataset full of empty or junk rows tells you exactly which rows were junk.

### Pricing

**This Actor is currently listed as free** - no start fee and no per-event charge. The Pricing tab on
this listing is the authoritative source; if it ever disagrees with this paragraph, believe the tab.

The unit that would be charged, if it ever is, is one text fully analyzed: every count, every
average, the longest words and lexical diversity, in a single record. Inputs with no countable words
return `ok: false` and are never billable either way.

For context on what this work costs elsewhere, read from the Apify Store on 2026-08-07:
`moving_beacon/word-character-counter` charges $0.001 per item and
`mahogany_songbird/page-word-count-batch` $0.002 per item, so a 10,000-text audit runs $10 to $20
there.

Also honest: counting words is a few lines of code in any language. Use this when you want it as a
hosted step in a pipeline, over many texts, with a stable output schema, or as a tool an AI agent can
call - not because counting is hard.

### When NOT to use this

- **Chinese, Japanese, Korean, Thai** and other scripts that do not put spaces between words. The
  character counts are correct, but the **word** count will not be meaningful, because tokenization
  here is Latin-script oriented. Use a language-specific segmenter.
- **Exact syllable counts for individual rare words.** The syllable counter is an English heuristic.
  Totals across a paragraph are reliable; a single unusual word can be off by one.
- **Abbreviation-heavy text where the sentence count must be exact.** "Dr. Smith of Ft. Worth" counts
  as three sentences, as it does in every mechanical splitter. If sentence count is your billing
  metric, be aware of that bias.
- **Readability scores.** This is the raw measurement layer. If you want Flesch, Gunning Fog, SMOG or
  a grade level, use `EliAI/text-readability-analyzer` instead - it includes these stats plus the six
  formulas.
- **Counting one document by hand.** Your editor already does that. This is for batches and
  pipelines.

### Honest limits

- Words are runs of letters and digits, allowing internal apostrophes and hyphens. Latin-script
  oriented, as above.
- Sentences split on `.`, `!`, `?` followed by whitespace or end of text.
- Paragraphs split on blank lines. A text with no blank lines is one paragraph.
- Syllables use an English heuristic (roughly 90%+ per-word accuracy).
- Up to 200 texts per run.

### FAQ

**How do I count words and characters in a text via API?**
Send `{"text": "..."}`. You get `words`, `characters.withSpaces`, `characters.withoutSpaces`,
`sentences`, `paragraphs` and `syllables` in one record. For many texts, send `texts` as an array.

**Are emojis and accented characters counted correctly?**
Yes. Character counts use Unicode code points, so an emoji counts as one character rather than two
surrogate halves, and accented letters count as one.

**What is lexical diversity useful for?**
It is `uniqueWords / words`. Low values flag repetitive, templated or spun content; unusually high
values on short texts flag keyword stuffing or disjointed writing. It is a cheap first-pass quality
signal on scraped or machine-generated text.

**Can I enforce a minimum or maximum word count in CI?**
Yes. Batch your documents, then assert on `words` or `averages.wordsPerSentence` per record and fail
the build on the ones that miss. Records with no words come back `ok: false` with the reason.

**How is this different from your readability analyzer?**
This is counts only, and it is the cheaper of the two. The readability analyzer adds the six scoring
formulas, a consensus grade level, an audience label and rewrite suggestions. Use this one when your
pipeline only needs to enforce lengths.

**Does it work on Chinese or Japanese text?**
Character counts, yes. Word counts, no - see "When NOT to use this". Those scripts need a
language-specific segmenter.

**Why did some rows come back `ok: false`?**
The input had no countable words, only punctuation or symbols. Recorded with the reason rather than
returned as a row of zeros.

### Use from code or AI agents

```bash
curl -s "https://api.apify.com/v2/acts/EliAI~text-statistics/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -X POST -H 'Content-Type: application/json' \
  -d '{"text": "Count everything about this text."}'
```

Agents: connect [Apify MCP](https://mcp.apify.com) and call the `EliAI/text-statistics` tool.

- **Capability:** exact counts, averages and lexical diversity for one or many texts
- **Required input:** `text` (string) or `texts` (array)
- **Returns:** one record per text; `words`, `sentences` and `lexicalDiversity` headline it
- **Bounded:** 200 texts per run; failures isolate per text
- **Side effects:** none (texts never leave the run)

### Related actors

- **Readability Analyzer** (`EliAI/text-readability-analyzer`) - these same stats plus Flesch,
  Flesch-Kincaid, Gunning Fog, SMOG, ARI and Coleman-Liau with a consensus grade level.

# Actor input Schema

## `text` (type: `string`):

A single text to analyze. Use this for one-off analysis.

## `texts` (type: `array`):

An array of texts to analyze in one run. Each item is analyzed independently. When this list is filled, the single text above is ignored, so you are only charged for the texts you listed.

## `maxTexts` (type: `integer`):

Safety cap on how many texts to process in a single run.

## Actor input object example

```json
{
  "text": "The quick brown fox jumps over the lazy dog. It was a bright cold day in April, and the clocks were striking thirteen.\n\nNatural language processing turns raw text into structured insight.",
  "maxTexts": 50
}
```

# Actor output Schema

## `results` (type: `string`):

Every item this run produced, as JSON.

## `resultsCsv` (type: `string`):

The same items as a spreadsheet-ready CSV.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "text": `The quick brown fox jumps over the lazy dog. It was a bright cold day in April, and the clocks were striking thirteen.

Natural language processing turns raw text into structured insight.`
};

// Run the Actor and wait for it to finish
const run = await client.actor("eliai/text-statistics").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "text": """The quick brown fox jumps over the lazy dog. It was a bright cold day in April, and the clocks were striking thirteen.

Natural language processing turns raw text into structured insight.""" }

# Run the Actor and wait for it to finish
run = client.actor("eliai/text-statistics").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "text": "The quick brown fox jumps over the lazy dog. It was a bright cold day in April, and the clocks were striking thirteen.\\n\\nNatural language processing turns raw text into structured insight."
}' |
apify call eliai/text-statistics --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,eliai/text-statistics"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/4OWeHhgFUHVeaQ1js/builds/kuHoaG1dD8Gcq4Wkm/openapi.json
