Parse a PDF from a URL
Send a public PDF, spreadsheet or image URL to Webcite, get an asset ID back, and extract it to Markdown with page positions, in two calls and without downloading the file.
Last updated
How do I extract text from a PDF at a URL without downloading it?
Send the public HTTPS URL to POST /api/v1/upload/url, which fetches the file on Webcite's side and returns an asset_id, for 0 credits. Then POST /api/v1/extract with that asset_id returns the text as Markdown, one unit per page with element positions. The file never passes through your code, as the recorded IRS Form W-9 calls below show.
Endpoint and minimal request
POST https://api.webcite.co/api/v1/upload/url takes a public HTTPS url and an optional filename, fetches the file on Webcite's side and returns an asset_id. Uploading from a URL costs 0 credits. Then POST /api/v1/extract with that asset_id returns Markdown for each page. Send the key in the x-api-key header. Agents call upload_url, then extract_document.
curl --fail-with-body -X POST 'https://api.webcite.co/api/v1/upload/url' \
-H "x-api-key: $WEBCITE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf", "filename": "fw9.pdf"}'Recorded response for the IRS Form W-9, with account fields removed (full file):
{
"successCode": 200,
"message": "File uploaded successfully",
"data": {
"asset_id": "3f20860c-0dbb-4047-ab0d-f57e5e370572",
"source_version_id": "4b8b2b29-722a-4279-8ee2-ccfc2b92b81d",
"filename": "fw9.pdf",
"size": 140815
}
}Upload and extract in Python
import os
import requests
API = "https://api.webcite.co/api/v1"
HEADERS = {"x-api-key": os.environ["WEBCITE_API_KEY"]}
upload = requests.post(f"{API}/upload/url", headers=HEADERS,
json={"url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf", "filename": "fw9.pdf"}, timeout=60)
upload.raise_for_status()
asset_id = upload.json()["data"]["asset_id"]
document = requests.post(f"{API}/extract", headers=HEADERS,
json={"asset_id": asset_id, "mode": "standard"}, timeout=(10, 900))
document.raise_for_status()
result = document.json()
print(result["state"])
for unit in result["units"]:
print(unit["provenance"]["page"], unit["reader"]["page_type"], len(unit["elements"]))For the first page of the same form, the recorded extract has state: complete, and its unit reports page 1, read as a form with 45 elements, each with a bounding box on the page. The top-level markdown field holds the whole document as one string. Branch on state and code before you use the text; document workflows lists each code.
What the URL fetch accepts
The URL must be public HTTPS. The fetch sends no credentials or headers of yours, checks every redirect, and refuses private, loopback, link-local and metadata addresses, so an agent cannot use it to reach your internal network. The body is limited to 100 MB and the fetch to 30 seconds. PDF, images, office files, spreadsheets, CSV, TXT and Markdown are accepted; upload from a URL lists every type and error. For a file on disk or behind a login, use upload a file instead.
What to do with the asset ID
Keep the asset_id and source_version_id with your record of the document. The same asset feeds anchored chunks for retrieval, figure extraction, source preview for page links, and a full document review. Lite mode reads faster and costs less a page than standard.