Text to HTML API
Convert your plain text paragraphs into simple HTML <p> tags.
| Endpoint | POST https://astraltext.com/api/v1/text-to-html |
| Auth | Bearer token, free |
| Sends | input: text |
| Returns | result: text |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
Anything that takes writing from a plain-text field and puts it on a page has to decide where the paragraphs are. Doing it in one shared place stops the three different half-answers that otherwise appear in the CMS, the newsletter and the app.
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/text-to-html \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "First paragraph, written plainly.\n\nSecond paragraph, after a blank line."}'response
{
"tool": "text-to-html",
"result": "<p>First paragraph, written plainly.</p>\n<p>Second paragraph, after a blank line.</p>",
"chars": 85,
"ms": 1
}In your language
JavaScript
const res = await fetch("https://astraltext.com/api/v1/text-to-html", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"input": "First paragraph, written plainly.\n\nSecond paragraph, after a blank line."}),
});
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/text-to-html",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": "First paragraph, written plainly.\n\nSecond paragraph, after a blank line."},
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
- What markup does it produce?
- One p element per paragraph. No wrapper div, no classes and no inline styles, so it drops into any stylesheet.
- Is the text escaped?
- Characters that would be read as markup are escaped, so text containing a less-than sign does not open a tag.
- What decides a paragraph?
- A blank line. Single line breaks inside a paragraph are treated as wrapping, not as structure.
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