api.tools

convert()

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

转换格式为 244 对的文档, 即 33 源, 31 个目标。 上传字节, 或者给一个地址, 让平台获取它们 。

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.

参数

fromstring必填

源格式。 通用拼法被接受: md, jpeg, yml, .TXT.

tostring必填

目标格式。

urlstring

由地址警卫检查,上限为50 MB。

fileBuffer | Blob | Uint8Array

字节, 已上传。 请使用此 或 url.

两者 from 中 英 to 可能被忽略了—— 格式无法从字节中猜测, 因为错误的猜测产生了一个可信的文件, 而不是您所要求的文件 。

四户家庭

家庭家庭家庭家庭家庭家庭家庭来源来源来源来源来源目标
图像图像图像图像jpg png webp gif tiff svg avif加上可编码的,加上 pdf 和 base64
Datajson yaml csv tsv xml jsonl彼此,加 markdown html xlsx
Documentpdf docx pptx xlsx markdown html text文本, HTML, pdf, docx,图像来自 PDF
媒体媒体媒体媒体媒体mp3 wav ogg m4a aac flac opus · mp4 webm mkv mov avi相互之间;视频到音频; 与动画之间和之间 gif

实例实例实例

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

返回值

{
  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},
}
内容或基数64, 绝不同时

文本目标填满内容; 二进制目标填满基数64。测试字段而不是假设字段—— 同一个调用与给付另一个不同。

无法达到的目标 目标说明什么是可能的

未被支持的对一对返回为 unsupported_conversion, 和 信息名称 每一个目标 从该来源可达到的目标一次拒绝而不是一系列企图。

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.
列表在信件中,而不是错误对象上

下 HTTP 响应也带有支持的具体目标阵列, 直接呼叫就是如此。 您通过软件包读取了信件, 分析它, 或者将矩阵保存在您自己使用的页面上 。

拼写已正常化

md 和 mdown 介 markdown; jpeg 和 jfif 介 jpg; yml 是 yaml; txt 是 text; 引引点和任何情况被忽视。返回的字段带有正常名称,这就是 conversion 安全用作密钥。

双环

事 事 事限制
源码大小50 MB,上载或取出
获取超时20秒20秒
价格价格价格不论大小,每个转换1个信贷额度

电话本身没有超时:视频转码需要几分钟,收费费也很高,所以放弃请求就等于无法看到结果。

错误

代码状态触发条件
当地投掷—from 或 to 缺席或两者兼缺 file 中 英 url:一揽子要求在提出要求之前就被拒绝。
unsupported_conversion400配对不在矩阵中。 supportedTargets.
url_refusee400警卫拒绝提供地址
invalid_url_source400无法获取源代码 。
conversion_failed502转换器拒绝了字节。 信用额被回拨 。
未能达到的更正402余额将不包含一个贷项。

作为一种工具

被宣布为模型 它需要一个参数, url:源格式是从地址读取的,为此选择了目标——从 PDF, DOCX 或 PPTX,从电子表格中排出。完整矩阵是供您自己调用。