POST /count_occurrences • Credits: 0.5 credits per call
Count Occurrences splits a string on a separator and counts how many times each item appears. The response holds total_items, unique_items and a results array that lists each item with its count, sorted by count. Each call costs 0.5 credits.
What does Count Occurrences do?
A workflow often holds one long string of values: tags from a scraped page, skills from a profile, one column from a CSV export. Count Occurrences turns that string into a frequency table. The endpoint splits the string on the separator that you send. It trims the whitespace around each item and drops every empty item. It then counts the items and returns them sorted by count, from the most frequent to the least frequent. Count Occurrences runs inside RichAPI and calls no external service.
Which endpoint does Count Occurrences use?
Method:
POSTURL:
https://api.richapi.ai/api/v1/count_occurrencesAuthentication:
x-api-keyheaderResponse: Synchronous JSON
Credits: 0.5 credits per call
How to send a Count Occurrences request
Copy your API key from the RichAPI dashboard.
Put the values into one string in the
inputparameter.Set the
separatorparameter to the delimiter that divides the values.Send a
POSTrequest tohttps://api.richapi.ai/api/v1/count_occurrences.Send the API key in the
x-api-keyheader.Read the
resultsarray from the response.
CAUTION: Each Count Occurrences call costs 0.5 credits. A call that returns an empty results array also costs 0.5 credits.
cURL
curl -X POST https://api.richapi.ai/api/v1/count_occurrences
-H "x-api-key: YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{
"input": "SaaS, AI, saas, security, AI, ai, SaaS , , devops",
"separator": ",",
"case_insensitive": true,
"limit": 0
}'
Python
import requests
response = requests.post(
"https://api.richapi.ai/api/v1/count_occurrences",
headers={"x-api-key": "YOUR_API_KEY"},
json={
"input": "SaaS, AI, saas, security, AI, ai, SaaS , , devops",
"separator": ",",
"case_insensitive": True,
"limit": 0,
},
timeout=60,
)
response.raise_for_status()
print(response.json())
Node.js
const response = await fetch("https://api.richapi.ai/api/v1/count_occurrences", {
method: "POST",
headers: {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
input: "SaaS, AI, saas, security, AI, ai, SaaS , , devops",
separator: ",",
case_insensitive: true,
limit: 0,
}),
});
const data = await response.json();
console.log(data);
Which parameters does Count Occurrences accept?
Parameter | Type | Required | Default | Description |
| string | Yes | None | The string to split and count. The maximum length is 1,048,576 characters. |
| string | Yes | None | The delimiter that splits |
| boolean | No |
| Set to |
| integer | No |
| The maximum number of objects in |
Count Occurrences accepts these four parameters and no other field. If the request body holds an unknown field, the API returns status 400 with the message Unknown input field(s): <name>.
The API reference shows a default of , for separator. That default is unreachable. If the request body omits separator, the API returns status 400 with the message Missing required field: separator.
What does Count Occurrences return?
Count Occurrences returns one flat JSON object. Here is the example response for the request above, which sends the string SaaS, AI, saas, security, AI, ai, SaaS , , devops with the separator ,.
{
"total_items": 8,
"unique_items": 4,
"results": [
{ "item": "ai", "count": 3 },
{ "item": "saas", "count": 3 },
{ "item": "devops", "count": 1 },
{ "item": "security", "count": 1 }
]
}
Which fields does the Count Occurrences response hold?
Field | Type | Description |
| integer | The number of items that remain after the split, the whitespace trim and the removal of the empty items. |
| integer | The number of distinct items in |
| array of objects | One object per distinct item, sorted by count from high to low. |
| string | The item. If |
| integer | The number of times the item appears in |
The limit parameter truncates results only. Count Occurrences computes total_items and unique_items across the whole input, before the truncation.
How does Count Occurrences count the items?
Count Occurrences applies these rules in order:
Count Occurrences splits
inputon the exactseparatorstring.Count Occurrences trims the whitespace at both ends of each item.
Count Occurrences drops every item that is empty after the trim.
If
case_insensitiveistrue, Count Occurrences converts each item to lowercase.Count Occurrences counts the items and sorts them by count, from high to low.
If two items hold the same count, Count Occurrences sorts those two in alphabetical order.
If
limitis greater than0, Count Occurrences keeps the firstlimitobjects.
This table walks the example input SaaS, AI, saas, security, AI, ai, SaaS , , devops through those rules. The separator is , and case_insensitive is true.
# | Raw segment | After the trim | Counted as | In the count? |
1 |
|
|
| Yes |
2 |
|
|
| Yes |
3 |
|
|
| Yes |
4 |
|
|
| Yes |
5 |
|
|
| Yes |
6 |
|
|
| Yes |
7 |
|
|
| Yes |
8 | empty | none | No. The segment is empty after the trim. | |
9 |
|
|
| Yes |
Nine segments enter, and eight items are counted. The eighth segment holds one space, so Count Occurrences drops it. total_items is therefore 8, not 9.
Four distinct items remain, so unique_items is 4. The counts are saas 3, ai 3, security 1 and devops 1. Rule 6 breaks the two ties: ai comes before saas, and devops comes before security.
Is Count Occurrences case sensitive?
Count Occurrences is case insensitive by default. The case_insensitive parameter defaults to true, so SaaS, saas and SAAS collapse into one item. The item value in the response is then lowercase. In the example above, the three differently cased SaaS segments produce one result object with a count of 3. To count each spelling on its own, set case_insensitive to false. The item values then keep their original case.
Does Count Occurrences count overlapping matches?
Count Occurrences counts no overlapping match, because separator is a delimiter and not a search term. The endpoint splits the string at every separator and counts what remains between the separators. The separator itself is never counted.
Two examples make the rule concrete.
Request body | Response | Why |
|
| The split removes both instances of |
|
| The split leaves three empty segments, and rule 3 drops all three. |
To count how often one term appears in a block of text, split the text into words. Set separator to one space, then read the count of that term from results.
How do you score a lead with Count Occurrences?
Keyword scoring is the common use of Count Occurrences. You take the text of a lead, count the words, and read the count of the keywords that matter to you. Follow these steps:
Send a Web Scraper request for the website of the lead.
Read
data.markdownfrom the Web Scraper response.Send that text as
inputto Count Occurrences, withseparatorset to one space.Set
limitto the number of top words that you want to keep.Read the
countof each keyword from theresultsarray.
This request scores one profile summary of a lead:
curl -X POST https://api.richapi.ai/api/v1/count_occurrences
-H "x-api-key: YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{
"input": "We build AI security tooling for SaaS teams. Our AI platform ships SaaS security controls.",
"separator": " ",
"case_insensitive": true,
"limit": 5
}'
The response holds the five most frequent words:
{
"total_items": 15,
"unique_items": 12,
"results": [
{ "item": "ai", "count": 2 },
{ "item": "saas", "count": 2 },
{ "item": "security", "count": 2 },
{ "item": "build", "count": 1 },
{ "item": "controls.", "count": 1 }
]
}
The summary scores ai 2, saas 2 and security 2. A lead score of 6 follows from the sum of those three counts.
Two details change a word count. Count Occurrences splits on the separator alone, so punctuation stays attached to the word. The last word of the summary is therefore controls. with a full stop. A double space between two words creates an empty segment, and Count Occurrences drops that segment before the count.
How much does Count Occurrences cost?
Count Occurrences costs 0.5 credits per call. At $0.02 a credit, the rate on the 1,000 and 5,000 credit packs, one call costs $0.01. Larger packs cost less per credit. The credit count does not change with the length of the input or with the number of items in the response.
Calls | Credits | Cost |
1 | 0.5 | $0.01 |
100 | 50 | $1.00 |
1,000 | 500 | $10.00 |
10,000 | 5,000 | $100.00 |
The keyword scoring flow above costs 1.5 credits per lead, or $0.03. One Web Scraper call costs 1 credit, and one Count Occurrences call costs 0.5 credits.
Which errors can Count Occurrences return?
Status | Meaning | What to do |
| The request body failed validation, or | Correct the field that the message names. Send both |
| The API key is missing, wrong or revoked. | Send a valid key in the |
| The organization has too few credits left, or the team reached its monthly spend limit. | Buy credits in the RichAPI dashboard. |
| This API key has no access to this endpoint ( | Call |
| The endpoint name is wrong. | Send the request to |
| The request used a method other than | Send the request with the |
| Too many requests. | Wait, then send the request again. |
| The API failed. | Send the request again. If the failure repeats, contact support. |
RichAPI charges no credit for a 400, 401, 402, 403, 404, 405, 429 or 500 response. A 400 response names the field and lists the fields that Count Occurrences accepts:
{
"error": "Missing required field: separator",
"supported_fields": {
"accepted": ["case_insensitive", "input", "limit", "separator"],
"required": ["input", "separator"]
}
}
Frequently asked questions
Does Count Occurrences count how many times a substring appears?
No. Count Occurrences treats separator as a delimiter, not as a search term, and it never returns a count for the separator itself. To count one term inside a block of text, set separator to one space and read the count of that term from results.
Does Count Occurrences accept several search terms in one call?
Count Occurrences takes no search term at all. One call counts every distinct item in the input at once, so one response already holds the count of each term that you care about.
Can I send input as a JSON array?
No. The input parameter takes a string. If you send an array or a number, Count Occurrences returns status 400 with the message Invalid value for input: expected string.
How do I return only the top 10 items?
Set limit to 10. The results array then holds the 10 items with the highest counts, and total_items and unique_items still describe the whole input.
Does a call that finds nothing cost a credit?
Yes. Count Occurrences costs 0.5 credits for every 200 response, and an empty results array is a 200 response. A 4xx or 5xx error costs no credit.
Why does case_insensitive: "false" still count case insensitively?
Count Occurrences reads case_insensitive as a JSON boolean. A quoted string such as "false" is a non-empty value, and Count Occurrences treats it as true. Send false without the quotation marks.
Can I run Count Occurrences from n8n or from an MCP client?
Yes. The n8n operation name is count_occurrences. The MCP tool name is count_occurrences. Both take the same four parameters as the HTTP endpoint.
