api.tools

convert()

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

Converte un documento fra 244 pairs de formats — 33 fontes, 31 targets. Carga i bytes, o da un addresse e lascia la piattaforma li trae.

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.

Parâmetros

fromstringobrigatório

Le ortografie comuni sono accettate: md, jpeg, yml, .TXT.

tostringobrigatório

Format di destinazione.

urlstring

Trae la fonte da là. Controlato dal guardia di adrede, capsed a 50 MB.

fileBuffer | Blob | Uint8Array

I bytes, uploaded. Use questo o url.

Ni from ni to possono essere oltrati — il formato non è indovinat dai bytes, perché un erro di dop produce un file plausible che non è quello che si pede.

Le quattro famiglie

FamiliaFontesObictès
Imagejpg png webp gif tiff svg avifi codificabili, plus pdf e base64
Datijson yaml csv tsv xml jsonl, plus markdown html xlsx
Documentpdf docx pptx xlsx markdown html texttext, HTML, pdf, docx, immagini de un PDF
Mediamp3 wav ogg m4a aac flac opus · mp4 webm mkv mov avil'un l'altro; video a audio; a e da un animato gif

Exemples

// 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"]))

Retorno

{
  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},
}
o base64, mai ambo

Un testo target riempie il contenit; un binario riempie base64. Teste per il campo invec di supponendo uno — il medesimo appello con un differente da da l'altro.

Un target impossibilita dici ce è possible

Un par non supportat torna come unsupported_conversion, e o messaggio nomina ogni target raggiungibile da quella fonte. Un respinto in lugar di una serie di tentazion.

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.
La lista è nel messaggio, non nel oggetto d'errore

La risposta HTTP lo porta anche come un array Targets supportat, che è ciò che un appello diretto riceve. Attraverso il pacchetto si lee il messaggio — así parsèlo, o mantene la matrice in questa pagina al lado de sua propria chiamata.

Ortografie sono normalizzate

md e mdown sono markdown; jpeg e jfif sono jpg; yml é yaml; txt é text; un punto di rispete e in ogni caso sono ignorati. I campi che reven a portar i nomi normalizzati, che è ciò che rende conversion sicuro da usare come chiave.

Lunghes

CoisaLimite
Dimensiòn de la fonte50 MB, caricati o recuperati
Agarra tempo de uscita20 secondi
Pret1 credito per conversione, qualunque sia la dimensione

Non c'è tempo di richiamo: un video transcodifica dura minuti e il cobra, quindi abbandonando la richiesta paga per un risultato che non vedi.

Erros

CódigoStatusQuando
trova localmente—from or to è ausente, o né file ni url: il pacchetto rifiuta prima di ogni richiesta.
unsupported_conversion400Il par non è in la matrice. Carres supportedTargets.
url_refusee400L'indirizzo è renied dal guardian.
invalid_url_source400La fonte non puès s'impossa.
conversion_failed502Il convertitore renie i bytes. Il credito è restituit.
NonequoCredits402Il saldo non coprirà un credit.

Como un utensilio

Dichiara a un modele che prende un parametro, url: il formato sorgente è let dal indirizzo e l'obiettivo è electuât per il — text out of a PDF, DOCX o PPTX, filas out of a tabler. La matrice completa è para i vostri propri appelli.