Sort lines API
Sort any list alphabetically: imports, todo lists, CSV headers, and more.
| Endpoint | POST https://astraltext.com/api/v1/sort-lines |
| Auth | Bearer token, free |
| Sends | input: text |
| Returns | result: text |
| option | asc | desc |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
A sorted list is a reviewable list: an ordered set of allowed values, imports or translation keys makes a diff show what actually changed. Putting the sort in the pipeline means it happens before the file is committed, not after somebody notices.
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/sort-lines \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "éclair\nbanana\nApple\ncherry", "option": "asc"}'response
{
"tool": "sort-lines",
"result": "Apple\nbanana\ncherry\néclair",
"chars": 26,
"ms": 8
}In your language
JavaScript
const res = await fetch("https://astraltext.com/api/v1/sort-lines", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"input": "éclair\nbanana\nApple\ncherry", "option": "asc"}),
});
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/sort-lines",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": "éclair\nbanana\nApple\ncherry", "option": "asc"},
timeout=30,
)
res.raise_for_status()
result = res.json()["result"]Parameters
| Field | Type | Notes |
|---|---|---|
| input | string | Required. Up to 200,000 characters per call. |
| option | string | One of: asc, desc. |
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. |
| bad-option | 400 | option is not one of the listed values. |
| tool-failed | 422 | The input could not be processed. detail says why. |
| quota-exceeded | 429 | Past 1,000 calls today. |
Questions
- How do I sort in reverse?
- Send "option": "desc". The default is "asc".
- How are accents and case treated?
- The comparison is locale-aware and case-insensitive, so an accented word sorts next to its unaccented neighbour instead of after every ASCII letter.
- Are blank lines kept?
- Yes, they sort with everything else. Remove them first if you do not want them in the result.
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