Fix spacing API
Remove double spaces, fix triple line breaks, and humanize robotic formatting.
| Endpoint | POST https://astraltext.com/api/v1/fix-spacing |
| Auth | Bearer token, free |
| Sends | input: text |
| Returns | result: text |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
Spacing damage accumulates: a removed word here, a pasted paragraph there, a template that emits a space whether or not the value exists. It never shows up in testing and always shows up in the published version, so the fix belongs in the step before publishing.
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/fix-spacing \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "Two spaces here ,and a gap before the comma .\n\n\n\nToo many blank lines."}'response
{
"tool": "fix-spacing",
"result": "Two spaces here ,and a gap before the comma .\n\nToo many blank lines.",
"chars": 68,
"ms": 1
}In your language
JavaScript
const res = await fetch("https://astraltext.com/api/v1/fix-spacing", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"input": "Two spaces here ,and a gap before the comma .\n\n\n\nToo many blank lines."}),
});
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/fix-spacing",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": "Two spaces here ,and a gap before the comma .\n\n\n\nToo many blank lines."},
timeout=30,
)
res.raise_for_status()
result = res.json()["result"]Parameters
| Field | Type | Notes |
|---|---|---|
| input | string | Required. Up to 200,000 characters per call. |
Errors
Errors are RFC 7807 problem documents with a stable type you can branch on.
| missing-token | 401 | No Authorization header. |
| bad-request | 400 | input missing or the wrong type. |
| tool-failed | 422 | The input could not be processed. detail says why. |
| quota-exceeded | 429 | Past 1,000 calls today. |
Questions
- Does it touch indentation?
- Leading whitespace on a line is preserved, so indented text and code-like blocks keep their shape.
- How many blank lines survive?
- Runs of blank lines collapse to one, which is enough to keep paragraphs apart without leaving a gap.
- What punctuation spacing is corrected?
- A space before a comma, full stop, semicolon, colon, question mark or exclamation mark is removed, and a missing space after one is added.
Other endpoints
- AI text cleaner API
- Remove em dashes API
- Remove invisible characters API
- Remove emoji API
- Remove line breaks API
- Strip Markdown API
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