Skip to main content

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 token

Overview

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 URLhttps://astralpdf.com/api/v1
AuthBearer token, free
FormatJSON in, JSON out
CORSOpen, callable from a browser
Errorsapplication/problem+json

Quickstart

  1. Create an account on the developer console.
  2. Mint a token. It is shown once, so copy it.
  3. Call any tool.
curl
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."}'
response
{
  "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

LimitValue
Requests per minute, per token60
Calls per day, per token1,000
Input size6,000,000 characters
Quota reset00: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.

401
{
  "type": "https://astralpdf.com/errors/missing-token",
  "title": "Missing token",
  "status": 401,
  "detail": "Send your token as \"Authorization: Bearer ast_...\"."
}
typeStatusWhen
missing-token401No Authorization header.
invalid-token401The token is not a valid Astral token.
expired-token401The token is more than a year old.
revoked-token401The token was revoked from the console.
rate-limited429More than 60 requests in a minute.
quota-exceeded429More than 1000 calls in a day.
unknown-tool404No tool with that slug.
bad-request400The body is not JSON, or input is not a string.
bad-option400option is not one the tool accepts.
input-too-large413input is over the character limit.
tool-failed422The tool could not process that input.
not-configured503The 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/tools

POST /api/v1/{tool}

Runs one tool. Body fields:

FieldTypeNotes
inputstringFor single-document tools. Up to 6,000,000 characters.
inputsstring[]For tools whose input type ends in []. Between 2 and 20 items, counted together against the same character limit.
optionstringOnly for tools that list options.

Several documents in one call

Tools whose input type ends in [] read inputs instead of input.

curl
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/tokenMint a token. Returned once.
GET /api/v1/tokensYour 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.

SlugWhat it doesInputoption
pdf-infoPage count, page sizes, rotation and document metadata.base64-
merge-pdfJoin several PDFs into one, in the order given.base64[]-
split-pdfKeep only the pages you name. Put the range in "option", for example 1-3,7.base64-
rotate-pdfTurn every page by a quarter, a half or three quarters.base6490 | 180 | 270
compress-pdfRe-save with object streams, dropping unreferenced objects. Does not resample images.base64-
protect-pdfEncrypt with a password. Put the password in "option".base64-
unlock-pdfRemove the password from a PDF you can open. Put the password in "option".base64-
watermark-pdfStamp text diagonally across every page. Put the text in "option".base64-
jpg-to-pdfTurn JPEG or PNG images into a PDF, one image per page.base64[]-

Code samples

JavaScript
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();
Python
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.