Parameters
fromstringrequiredThe source format. Common spellings are accepted: md, jpeg, yml, .TXT.
tostringrequiredThe target format.
urlstringFetch the source from there. Checked by the address guard, capped at 50 MB.
fileBuffer | Blob | Uint8ArrayThe bytes, uploaded. Use this or url.
Neither from nor to may be left out — the format is not guessed from the bytes, because a wrong guess produces a plausible file that is not the one you asked for.
The four families
| Family | Sources | Targets |
|---|---|---|
| Image | jpg png webp gif tiff svg avif | the encodable ones, plus pdf and base64 |
| Data | json yaml csv tsv xml jsonl | each other, plus markdown html xlsx |
| Document | pdf docx pptx xlsx markdown html text | text, HTML, pdf, docx, images from a PDF |
| Media | mp3 wav ogg m4a aac flac opus · mp4 webm mkv mov avi | each other; video to audio; to and from an animated gif |
Examples
// A PDF on the web, as markdown
const doc = await api.tools.convert({ from: "pdf", to: "markdown", url: "https://example.com/report.pdf" });
console.log(doc.content);
// A spreadsheet in hand, as rows
const rows = await api.tools.convert({ from: "xlsx", to: "json", file: buffer });
// An image, re-encoded
const webp = await api.tools.convert({ from: "png", to: "webp", file: png });
await pc.files.write("Assets/logo.webp", Buffer.from(webp.base64, "base64"));import base64
# A PDF on the web, as markdown
doc = api.tools.convert({"from_format": "pdf", "to": "markdown", "url": "https://example.com/report.pdf"})
print(doc["content"])
# A spreadsheet in hand, as rows
rows = api.tools.convert({"from_format": "xlsx", "to": "json", "file": xlsx_bytes})
# An image, re-encoded
webp = api.tools.convert({"from_format": "png", "to": "webp", "file": png_bytes})
pc.files.write("Assets/logo.webp", base64.b64decode(webp["base64"]))Returns
{
ok: true,
family: "document",
conversion: "pdf-to-markdown",
from: "pdf",
to: "markdown",
mimeType: "text/markdown",
content: "# Quarterly report\n\n…", // text targets
base64: "…", // binary targets
metadata: { originalSize: 184_221, convertedSize: 9_118, durationMs: 1_204 },
creditsUsed: 1,
timing: { durationMs: 1_240 }
}{
"ok": True,
"family": "document",
"conversion": "pdf-to-markdown",
"from": "pdf",
"to": "markdown",
"mimeType": "text/markdown",
"content": "# Quarterly report\n\n…", # text targets
"base64": "…", # binary targets
"metadata": {"originalSize": 184_221, "convertedSize": 9_118, "durationMs": 1_204},
"creditsUsed": 1,
"timing": {"durationMs": 1_240},
}A text target fills content; a binary one fills base64. Test for the field rather than assuming one — the same call with a different to gives the other.
An impossible target says what is possible
A pair that is not supported comes back as unsupported_conversion, and the message names every target reachable from that source. One refusal instead of a series of attempts.
import { IaGenifyError } from "iagenify";
try {
await api.tools.convert({ from: "pdf", to: "mp3", url });
} catch (err) {
if (err instanceof IaGenifyError && err.code === "unsupported_conversion") {
console.log(err.message);
// La conversion de 'pdf' vers 'mp3' n'est pas prise en charge.
// Depuis 'pdf' : text, markdown, html, json, png, jpg, webp.
}
}from iagenify import IaGenifyError
try:
api.tools.convert({"from_format": "pdf", "to": "mp3", "url": url})
except IaGenifyError as error:
if error.code != "unsupported_conversion":
raise
print(error)
# La conversion de 'pdf' vers 'mp3' n'est pas prise en charge.
# Depuis 'pdf' : text, markdown, html, json, png, jpg, webp.The HTTP response also carries it as a supportedTargets array, which is what a direct call gets. Through the package you read the message — so parse it, or keep the matrix on this page beside your own call.
Spellings are normalised
md and mdown are markdown; jpeg and jfif are jpg; yml is yaml; txt is text; a leading dot and any case are ignored. The fields that come back carry the normalised names, which is what makes conversion safe to use as a key.
Bounds
| Thing | Bound |
|---|---|
| Source size | 50 MB, uploaded or fetched |
| Fetch timeout | 20 seconds |
| Price | 1 credit per conversion, whatever the size |
There is no timeout on the call itself: a video transcode takes minutes and it is charged, so abandoning the request would pay for a result you never see.
Errors
| Code | Status | When |
|---|---|---|
| thrown locally | — | from or to is absent, or neither file nor url: the package refuses before any request. |
| unsupported_conversion | 400 | The pair is not in the matrix. Carries supportedTargets. |
| url_refusee | 400 | The address is refused by the guard. |
| invalid_url_source | 400 | The source could not be fetched. |
| conversion_failed | 502 | The converter refused the bytes. The credit is given back. |
| NotEnoughCredits | 402 | The balance will not cover one credit. |
As a tool
Declared to a model it takes one parameter, url: the source format is read from the address and the target is chosen for it — text out of a PDF, DOCX or PPTX, rows out of a spreadsheet. The full matrix is for your own calls.