Parâmetros
fromstringobrigatórioLe ortografie comuni sono accettate: md, jpeg, yml, .TXT.
tostringobrigatórioFormat di destinazione.
urlstringTrae la fonte da là. Controlato dal guardia di adrede, capsed a 50 MB.
fileBuffer | Blob | Uint8ArrayI 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
| Familia | Fontes | Obictès |
|---|---|---|
| Image | jpg png webp gif tiff svg avif | i codificabili, plus pdf e base64 |
| Dati | json yaml csv tsv xml jsonl | , plus markdown html xlsx |
| Document | pdf docx pptx xlsx markdown html text | text, HTML, pdf, docx, immagini de un PDF |
| Media | mp3 wav ogg m4a aac flac opus · mp4 webm mkv mov avi | l'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},
}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 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
| Coisa | Limite |
|---|---|
| Dimensiòn de la fonte | 50 MB, caricati o recuperati |
| Agarra tempo de uscita | 20 secondi |
| Pret | 1 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ódigo | Status | Quando |
|---|---|---|
| trova localmente | — | from or to è ausente, o né file ni url: il pacchetto rifiuta prima di ogni richiesta. |
| unsupported_conversion | 400 | Il par non è in la matrice. Carres supportedTargets. |
| url_refusee | 400 | L'indirizzo è renied dal guardian. |
| invalid_url_source | 400 | La fonte non puès s'impossa. |
| conversion_failed | 502 | Il convertitore renie i bytes. Il credito è restituit. |
| NonequoCredits | 402 | Il 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.