POST /remove_whitespace • Credits: 0.5 credits per call
Remove Whitespace takes one string and returns a normalized copy of that string. It converts every tab, newline and Unicode space character to a regular space. It then collapses each run of two or more spaces to one space, and trims both ends. Single spaces between words survive. Each POST call costs 0.5 credits.
What does Remove Whitespace do?
Scraped text carries whitespace that a person never sees. A LinkedIn job title arrives as Senior Product Manager with two spaces. A table cell arrives with a trailing tab. A copied name arrives with a non-breaking space instead of a regular space. Remove Whitespace turns all of those into one predictable form, so that two values that look the same to a person also match as strings. RichAPI runs the normalization inside its own service. The endpoint calls no external provider, so the response is immediate.
Remove Whitespace does not delete all whitespace. It reduces whitespace to a single regular space between words, and to nothing at the two ends.
Which endpoint does Remove Whitespace use?
Method:
POSTURL:
https://api.richapi.ai/api/v1/remove_whitespaceAuthentication:
x-api-keyheaderRequest body: A JSON object with
input_textResponse: Synchronous JSON
Credits: 0.5 credits per call
Maximum input: 10485760 characters (10 MB)
Remove Whitespace accepts the POST method only. If you send GET, the API returns 405 with the error remove_whitespace only supports POST.
Exactly what does Remove Whitespace change?
Remove Whitespace applies three steps, in this order.
Replace each run of the 25 whitespace characters below with one regular space.
Collapse each run of two or more regular spaces into one regular space.
Trim the whitespace from the start and the end of the string.
The regular space U+0020 is not in the list for step 1. Step 2 and step 3 handle the regular space.
Which characters does step 1 convert?
Group | Characters | JSON escape |
Tab |
|
|
Line feed |
|
|
Vertical tab |
|
|
Form feed |
|
|
Carriage return |
|
|
No-break space |
|
|
Ogham space mark |
|
|
En quad to hair space |
|
|
Zero-width space |
|
|
Line separator |
|
|
Paragraph separator |
|
|
Narrow no-break space |
|
|
Medium mathematical space |
|
|
Ideographic space |
|
|
Zero-width no-break space, the byte order mark |
|
|
What does Remove Whitespace do to a tab, a newline and a non-breaking space?
The table below shows one input and one output per row. Every value is verified against the normalization code.
Read the markers like this:
Marker | Character | How you send the character |
| Regular space | A literal space |
| Tab |
|
| Newline |
|
| Non-breaking space |
|
| Zero-width space |
|
Input with markers | The | Output with markers | The | What Remove Whitespace did |
|
|
|
| Trimmed the trailing space. |
|
|
|
| Trimmed the leading space. |
|
|
|
| Collapsed the double space to one space. |
|
|
|
| Converted the tab to one space. |
|
|
|
| Converted the newline to one space. |
|
|
|
| Converted the non-breaking space to a regular space. |
|
|
|
| Converted the zero-width space to a regular space, which splits the word. |
|
|
|
| Collapsed the mixed run to one space. |
|
|
|
| Changed nothing. |
Two rows carry the important warning. A newline becomes a space, so a multi-line address collapses into one line. A zero-width space becomes a visible space, so Acme∅Corp becomes two words and not one.
How to send a Remove Whitespace request
Copy your API key from the RichAPI dashboard.
Send a
POSTrequest tohttps://api.richapi.ai/api/v1/remove_whitespace.Set the
x-api-keyheader to your API key.Set the
Content-Typeheader toapplication/json.Put the string to clean in the
input_textparameter.Read
normalized_textfrom the response.
cURL
curl -X POST https://api.richapi.ai/api/v1/remove_whitespace
-H "x-api-key: YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{"input_text": " Senior Product\u00a0Manager\tat Acme Corp \n"}'
Python
import requests
response = requests.post(
"https://api.richapi.ai/api/v1/remove_whitespace",
headers={"x-api-key": "YOUR_API_KEY"},
json={"input_text": " Senior Product\u00a0Manager\tat Acme Corp \n"},
timeout=60,
)
response.raise_for_status()
print(response.json()["normalized_text"])
Node.js
const response = await fetch("https://api.richapi.ai/api/v1/remove_whitespace", {
method: "POST",
headers: {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
input_text: " Senior Product\u00a0Manager\tat Acme Corp \n",
}),
});
const data = await response.json();
console.log(data.normalized_text);
Which parameters does Remove Whitespace accept?
Parameter | Type | Required | Default | Description |
| string | Yes |
| The string to clean. The maximum length is 10485760 characters (10 MB). An empty string returns |
Remove Whitespace accepts no other parameter. The endpoint takes no path parameter and no query parameter.
What does Remove Whitespace return?
The block below is an example response for the request in the code samples above. The request body is {"input_text": " Senior Product\u00a0Manager\tat Acme Corp \n"}.
{
"original_text": " Senior Product\u00a0Manager\tat Acme Corp \n",
"normalized_text": "Senior Product Manager at Acme Corp",
"original_length": 42,
"normalized_length": 35,
"characters_removed": 7,
"changes_applied": true
}
The response is a flat JSON object with no data envelope. Like every RichAPI response, it also carries richapi_meta with the request ID and the credits charged and remaining.
Which response fields does Remove Whitespace return?
Field | Type | Description |
| string | The exact string that you sent in |
| string | The cleaned string. |
| integer | The character count of |
| integer | The character count of |
| integer |
|
| boolean |
|
A tab becomes one space, so the length does not change. In that case characters_removed is 0 and changes_applied is true.
How do I clean scraped text before a comparison?
A trailing space breaks an exact match. "Acme Corp " and "Acme Corp" are two different strings for every programming language, every spreadsheet lookup and every database join. A person reads them as one company. Normalize both values first, then compare or deduplicate.
The script below sends three scraped variants of one company name, and reduces them to one unique value.
import requests
URL = "https://api.richapi.ai/api/v1/remove_whitespace"
HEADERS = {"x-api-key": "YOUR_API_KEY"}
def clean(text):
response = requests.post(
URL, headers=HEADERS, json={"input_text": text}, timeout=60
)
response.raise_for_status()
return response.json()["normalized_text"]
scraped = ["Acme Corp ", "Acme Corp", "Acme\tCorp"]
print(scraped[0] == scraped[1])
# False. The trailing space breaks the exact match.
unique = {clean(value) for value in scraped}
print(unique)
# {'Acme Corp'}. One company, one key.
CAUTION: Remove Whitespace charges 0.5 credits for every call. The script above sends three calls and costs 1.5 credits. Deduplicate the raw list first, then send one call per unique string.
How much does Remove Whitespace cost?
Remove Whitespace 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. RichAPI charges the credits on a 2xx response. A response with a status outside the 200 range costs no credits.
Calls | Credits | Cost |
1 | 0.5 | $0.01 |
100 | 50 | $1.00 |
1,000 | 500 | $10.00 |
10,000 | 5,000 | $100.00 |
CAUTION: A call that changes nothing still returns 200 with changes_applied: false. RichAPI charges 0.5 credits for it.
Which errors can Remove Whitespace return?
Status | Meaning | What to do |
| The request body holds no | Add the |
| The | Send |
| The | Split the text, then send each part in its own request. |
| The API key is missing, wrong or revoked. | Send a valid key in the |
| The organization has no 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 request used a method other than | Send the request again with the |
| The request rate is over the limit. | Wait, then send the request again. |
| The API failed. | Send the request again. If the failure repeats, contact support. |
Every error response holds an error field with a plain-language message.
Frequently asked questions
Does Remove Whitespace delete every space?
No. Remove Whitespace keeps one regular space between words. It converts tabs, newlines and Unicode space characters to a regular space, collapses each run of spaces to one space, and trims both ends.
What does Remove Whitespace do to a newline?
Remove Whitespace converts a newline to one regular space. A multi-line address becomes one line.
Why is characters_removed 0 when changes_applied is true?
The characters_removed field is a length difference. A tab becomes one space, so the length does not change, but the text did change.
Does Remove Whitespace call an external provider?
No. RichAPI runs the normalization inside its own service, so the response is immediate.
