Skip to main content

Fix spacing API

Remove double spaces, fix triple line breaks, and humanize robotic formatting.

EndpointPOST https://astraltext.com/api/v1/fix-spacing
AuthBearer token, free
Sendsinput: text
Returnsresult: text
PriceFree. 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

FieldTypeNotes
inputstringRequired. Up to 200,000 characters per call.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400input missing or the wrong type.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 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

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