Skip to main content

Remove line breaks API

Unwrap text that was hard-wrapped into short lines, keeping the blank lines that separate paragraphs.

EndpointPOST https://astraltext.com/api/v1/remove-line-breaks
AuthBearer token, free
Sendsinput: text
Returnsresult: text
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

Text copied out of a PDF, an email client or a terminal arrives wrapped at whatever width it was displayed in. Those breaks are not in the writing, they are in the rendering, and they have to go before the text can be reflowed, stored in a single field or sent to a model.

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/remove-line-breaks \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "A sentence that was\nwrapped by the viewer.\n\nA second paragraph\nwrapped the same way."}'
response
{
  "tool": "remove-line-breaks",
  "result": "A sentence that was wrapped by the viewer.\n\nA second paragraph wrapped the same way.",
  "chars": 84,
  "ms": 1
}

In your language

JavaScript
const res = await fetch("https://astraltext.com/api/v1/remove-line-breaks", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "A sentence that was\nwrapped by the viewer.\n\nA second paragraph\nwrapped the same way."}),
});
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/remove-line-breaks",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "A sentence that was\nwrapped by the viewer.\n\nA second paragraph\nwrapped the same way."},
    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 destroy paragraphs?
No. A blank line between two blocks is a paragraph break and is kept. Only the breaks inside a paragraph are joined.
Are Windows line endings handled?
Yes. Carriage return, line feed and the pair are all treated the same, so text from any platform behaves identically.
What replaces the removed break?
A single space, so the words on either side do not run together. Runs of whitespace around the join are collapsed to that one space.

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