API reference
astralpdf.com API
Every tool on this site, callable over HTTP. Free, 1,000 calls a day, no card. You need a token, and a token takes about thirty seconds to get.
Get a free tokenOverview
The API exposes the same 9 tools the site runs in your browser. Same code, same tests, same results. Use it when the work belongs in a script, a build step or a server rather than in a tab.
| Base URL | https://astralpdf.com/api/v1 |
| Auth | Bearer token, free |
| Format | JSON in, JSON out |
| CORS | Open, callable from a browser |
| Errors | application/problem+json |
Quickstart
- Create an account on the developer console.
- Mint a token. It is shown once, so copy it.
- Call any tool.
curl -X POST https://astralpdf.com/api/v1/pdf-info \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"input": "Hello world — from an AI."}'{
"tool": "pdf-info",
"result": "Hello world - from an AI.",
"chars": 24,
"ms": 1
}Authentication
Send the token in the Authorization header. One token works across all four Astral APIs: astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.
Authorization: Bearer ast_...Tokens last a year. You can hold five at once and revoke any of them from the console, which takes effect within a minute. A token is a secret: keep it out of client-side code and out of git.
Rate limits and quota
| Limit | Value |
|---|---|
| Requests per minute, per token | 60 |
| Calls per day, per token | 1,000 |
| Input size | 6,000,000 characters |
| Quota reset | 00:00 UTC |
Every successful response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. The per-minute counter is held in memory per server, so a short burst can occasionally exceed it by a few requests. The daily quota is the one that is enforced strictly.
Errors
Errors are RFC 7807 problem documents. The type is a stable URI you can branch on.
{
"type": "https://astralpdf.com/errors/missing-token",
"title": "Missing token",
"status": 401,
"detail": "Send your token as \"Authorization: Bearer ast_...\"."
}| type | Status | When |
|---|---|---|
| missing-token | 401 | No Authorization header. |
| invalid-token | 401 | The token is not a valid Astral token. |
| expired-token | 401 | The token is more than a year old. |
| revoked-token | 401 | The token was revoked from the console. |
| rate-limited | 429 | More than 60 requests in a minute. |
| quota-exceeded | 429 | More than 1000 calls in a day. |
| unknown-tool | 404 | No tool with that slug. |
| bad-request | 400 | The body is not JSON, or input is not a string. |
| bad-option | 400 | option is not one the tool accepts. |
| input-too-large | 413 | input is over the character limit. |
| tool-failed | 422 | The tool could not process that input. |
| not-configured | 503 | The API is not accepting requests. |
Privacy
The tools on this site run in your browser and your text never leaves it. That is still true, and the API does not change it.
The API is a different surface, and it has to be said plainly: when you call it, the text in input is sent to our server, processed in memory and returned. It is not written to disk, not logged and not used to train anything. What we do record is the shape of the call: which token, which tool, how many calls, how many failed. If you would rather nothing leave your machine at all, use the tools on the site instead.
GET /api/v1/tools
The catalogue: every tool, its endpoint, its options and the current limits. No token needed, so you can read it before signing up.
curl https://astralpdf.com/api/v1/toolsPOST /api/v1/{tool}
Runs one tool. Body fields:
| Field | Type | Notes |
|---|---|---|
| input | string | For single-document tools. Up to 6,000,000 characters. |
| inputs | string[] | For tools whose input type ends in []. Between 2 and 20 items, counted together against the same character limit. |
| option | string | Only for tools that list options. |
Several documents in one call
Tools whose input type ends in [] read inputs instead of input.
curl -X POST https://astralpdf.com/api/v1/merge-pdf \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"inputs": ["first", "second"]}'Managing tokens
The console does this for you. The endpoints are listed for completeness; they authenticate with a Firebase ID token, not with an API token.
| POST /api/v1/token | Mint a token. Returned once. |
| GET /api/v1/tokens | Your tokens and 14 days of usage. |
| DELETE /api/v1/tokens/{id} | Revoke one. |
All 9 tools
Each endpoint has its own page: the call, a worked example, its parameters and the errors it can return.
| Slug | What it does | Input | option |
|---|---|---|---|
| pdf-info | Page count, page sizes, rotation and document metadata. | base64 | - |
| merge-pdf | Join several PDFs into one, in the order given. | base64[] | - |
| split-pdf | Keep only the pages you name. Put the range in "option", for example 1-3,7. | base64 | - |
| rotate-pdf | Turn every page by a quarter, a half or three quarters. | base64 | 90 | 180 | 270 |
| compress-pdf | Re-save with object streams, dropping unreferenced objects. Does not resample images. | base64 | - |
| protect-pdf | Encrypt with a password. Put the password in "option". | base64 | - |
| unlock-pdf | Remove the password from a PDF you can open. Put the password in "option". | base64 | - |
| watermark-pdf | Stamp text diagonally across every page. Put the text in "option". | base64 | - |
| jpg-to-pdf | Turn JPEG or PNG images into a PDF, one image per page. | base64[] | - |
Code samples
const res = await fetch("https://astralpdf.com/api/v1/pdf-info", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ input: text }),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();import os, requests
res = requests.post(
"https://astralpdf.com/api/v1/pdf-info",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"input": text},
timeout=30,
)
res.raise_for_status()
result = res.json()["result"]Something missing or wrong here? Write to taoufik.leon.jabbari@gmail.com.