BoundaryML/baml · error · Error
Pdf is not a URL
Error message
Pdf is not a URL
What it means
BamlPdf.asUrl() only returns this.content when the PDF was constructed from a URL. If the instance holds base64 data instead, the accessor throws 'Pdf is not a URL' to prevent silently misusing base64 bytes as a URL.
Solutions
- Check pdf.isUrl() before calling asUrl(), and fall back to asBase64() otherwise.
- Use toBase64() or asBase64() when you need the binary content regardless of source form.
- If a URL is required, construct the Pdf from a URL (BamlPdf.fromUrl) at the source.
Example fix
// before
const url = pdf.asUrl();
// after
if (pdf.isUrl()) { const url = pdf.asUrl(); } else { const [b64, mediaType] = pdf.asBase64(); } Defensive patterns
Strategy: type-guard
Type guard
function pdfHasUrl(pdf: BamlPdf): boolean { return pdf.isUrl(); } Try / catch
try {
const url = pdf.asUrl();
} catch (e) {
if (e.message === 'Pdf is not a URL') {
const [b64, mediaType] = pdf.asBase64();
// handle base64 path
} else throw e;
} Prevention
- Always branch on isUrl()/type before choosing an accessor.
- Normalize PDFs to one representation (e.g. toBase64) early in your pipeline.
When it happens
Trigger: Calling pdf.asUrl() on a BamlPdf created via BamlPdf.fromBase64(...) (type !== 'url'), i.e. whenever isUrl() returns false.
Common situations: Receiving a BamlPdf from a function result or user upload that is base64-encoded and blindly calling asUrl(); assuming all Pdf objects carry a remote URL.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Pdf is not base64
- Audio is not a URL
- Audio is not base64
- BAML internal error (AWSBedrock): Pdf file should have been…
- Could not determine mime type for PDF input. Only…
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/0efafaf074859f0d.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_typescript/pdf.js:68
*/
static async fromUrlAsync(url) {
const response = await fetch(url);
const blob = await response.blob();
return BamlPdf.fromBlob(blob);
}
/**
* Check if the pdf is stored as a URL
*/
isUrl() {
return this.type === "url";
}
/**
* Get the URL of the pdf if it's stored as a URL
* @throws Error if the pdf is not stored as a URL
*/
asUrl() {
if (!this.isUrl()) {
throw new Error("Pdf is not a URL");
}
return this.content;
}
/**
* Get the base64 data and media type if the pdf is stored as base64
* @returns [base64Data, mediaType]
* @throws Error if the pdf is not stored as base64
*/
asBase64() {
if (this.type !== "base64") {
throw new Error("Pdf is not base64");
}
return [this.content, this.mediaType || ""];
}
/**
* Convert the pdf to a JSON representation
*/
toJSON() {View on GitHub (pinned to bd85ce9dee)