api.tools

convert()

api.tools.convert({ from, to, url | file }) → Promise<Converted>

Converts a document between 244 pairs of formats — 33 sources, 31 targets. Upload the bytes, or give an address and let the platform fetch them.

POST /api/convert1 credit50 MB at most
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Parameters

fromstringrequired

The source format. Common spellings are accepted: md, jpeg, yml, .TXT.

tostringrequired

The target format.

urlstring

Fetch the source from there. Checked by the address guard, capped at 50 MB.

fileBuffer | Blob | Uint8Array

The 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

FamilySourcesTargets
Imagejpg png webp gif tiff svg avifthe encodable ones, plus pdf and base64
Datajson yaml csv tsv xml jsonleach other, plus markdown html xlsx
Documentpdf docx pptx xlsx markdown html texttext, HTML, pdf, docx, images from a PDF
Mediamp3 wav ogg m4a aac flac opus · mp4 webm mkv mov avieach 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},
}
content or base64, never both

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 list is in the message, not on the error object

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

ThingBound
Source size50 MB, uploaded or fetched
Fetch timeout20 seconds
Price1 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

CodeStatusWhen
thrown locally—from or to is absent, or neither file nor url: the package refuses before any request.
unsupported_conversion400The pair is not in the matrix. Carries supportedTargets.
url_refusee400The address is refused by the guard.
invalid_url_source400The source could not be fetched.
conversion_failed502The converter refused the bytes. The credit is given back.
NotEnoughCredits402The 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.