开发者 API

一个适用于所有文件工作流的通用 API

Converter App 为开发者提供高性能的文件处理接口。用一个 API 替代分散的工具,实现可扩展的文档转换、媒体处理、转写和 OCR。

Converter App API 概览

Converter App API 为开发者提供了一个无缝、通用的接口,满足所有文件处理需求。您的应用无需集成一堆分散的独立工具,只需调用一个高性能服务即可。您可以将我们的完整转换套件直接集成到后端工作流中,处理从常规文件转换到高要求媒体任务的各种需求。

公共基础 URL 为 https://api.converter.app/。本文档中的路径均使用此对外提供的 API 根地址。

全面覆盖

通过一个简化的集成,访问完整的转换工具库。

两种处理模式

对于需要立即响应的情况,请选择同步请求;对于大文件和长时间运行的任务,请选择异步作业。

根据您的需求量身定制

联系我们,我们可以按您的需求提供定制方案,价格无可匹敌。

文档 图片 音频 视频 文本 压缩包

探索支持的转换(无需密钥)

使用公共 pairs 端点作为最简单的连接性测试。它不需要 API 密钥,并会返回平台上可用的全部受支持转换对列表。

获取 /public/pairs

该端点是开放的,因此开发者可以在请求或配置 API 密钥之前查看通用转换目录。

curl "https://api.converter.app/public/pairs"

JavaScript

const response = await fetch('https://api.converter.app/public/pairs');
const pairs = await response.json();
console.log(pairs.supported_pairs);

Python

import requests

response = requests.get('https://api.converter.app/public/pairs')
response.raise_for_status()
pairs = response.json()
print(pairs['supported_pairs'])

示例响应

{
  "supported_pairs": [
    { "from": "mp3", "to": "text" },
    { "from": "mp4", "to": "mp3" },
    { "from": "mov", "to": "mp4" },
    { "from": "wav", "to": "mp3" },
    { "from": "mkv", "to": "mp4" }
  ]
}

身份验证与访问控制

开发者通过在 HTTP 头中传递其 API 密钥 X API Key 来进行身份验证。公共 /public/pairs 端点是本页唯一不需要密钥的端点。

控制工作原理开发者影响
X-API-Key将密钥作为 HTTP 请求头发送。必需用于 /pairs/convert/sync/convert/progress/{jobid}/download/{jobid}
使用额度每个密钥都有一个数值转换配额。创建转换任务时,配额会减少。-1 的配额表示可无限次转换。其他数值表示剩余可用的转换次数。
允许的配对密钥可以限制为特定的转换类型,例如 mp42mp3,或授予对 all 支持的文件格式对的访问权限。/pairs 仅返回您的密钥有权使用的配对,列表之外的转换请求将被拒绝。
curl "https://api.converter.app/pairs" \
  -H "X-API-Key: YOUR_API_KEY"

JavaScript

const response = await fetch('https://api.converter.app/pairs', {
  headers: {
    'X-API-Key': apiKey
  }
});

const pairs = await response.json();
console.log(pairs);

Python

import requests

headers = {'X-API-Key': 'YOUR_API_KEY'}
response = requests.get('https://api.converter.app/pairs', headers=headers)
response.raise_for_status()
print(response.json())

2. 同步转换

帖子 /convert/sync

当您希望在同一个 HTTP 响应中立即获得结果时,请使用同步转换。请求会保持打开状态,直到 API 启动转换任务并等待其完成,最长可达 30 分钟。

表单字段类型说明
target_formatstring所请求的输出扩展名,例如 pdfdocxmp3jpg
filesfile[]一个或多个已上传的源文件。API 会根据已上传文件的文件名确定源格式。
curl -X POST "https://api.converter.app/convert/sync" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "target_format=pdf" \
  -F "files=@/path/to/document.docx" \
  -o converted.pdf

JavaScript

const form = new FormData();
form.append('target_format', 'pdf');
form.append('files', fileInput.files[0]);

const response = await fetch('https://api.converter.app/convert/sync', {
  method: 'POST',
  headers: {
    'X-API-Key': apiKey
  },
  body: form
});

const convertedFile = await response.blob();

Python

import requests

headers = {'X-API-Key': 'YOUR_API_KEY'}
data = {'target_format': 'pdf'}

with open('/path/to/document.docx', 'rb') as document:
    files = {'files': document}
    response = requests.post(
        'https://api.converter.app/convert/sync',
        headers=headers,
        data=data,
        files=files
    )

response.raise_for_status()
with open('converted.pdf', 'wb') as output:
    output.write(response.content)

响应会直接流式传输转换后的文件。如果转换生成多个文件,API 将返回一个 .zip 压缩包。

3. 异步转换

发布文章 /convert

对于大型文件、批量处理、耗时较长的音频或视频任务,或者不应在处理运行期间保持上传请求打开的生产应用,请使用异步转换。

表单字段类型描述
target_format字符串所需的输出格式。源格式和目标格式构成转换对,例如 mp42mp3
filesfile[]一个或多个要转换的文件。

cURL

curl -X POST "https://api.converter.app/convert" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "target_format=mp3" \
  -F "files=@/path/to/video.mp4"

JavaScript

const form = new FormData();
form.append('target_format', 'mp3');
form.append('files', fileInput.files[0]);

const response = await fetch('https://api.converter.app/convert', {
  method: 'POST',
  headers: {
    'X-API-Key': apiKey
  },
  body: form
});

const job = await response.json();
console.log(job.jobid, job.remaining_quota);

Python

import requests

headers = {'X-API-Key': 'YOUR_API_KEY'}
data = {'target_format': 'mp3'}

with open('/path/to/video.mp4', 'rb') as video:
    files = {'files': video}
    response = requests.post(
        'https://api.converter.app/convert',
        headers=headers,
        data=data,
        files=files
    )

response.raise_for_status()
job = response.json()
print(job['jobid'], job['remaining_quota'])

成功响应

{
  "status": "success",
  "jobid": "b3f6b2e8f5c34c4ab01c93c4d1b2f9e8",
  "pair": "mp42mp3",
  "remaining_quota": 42
}

4. 状态跟踪

获取 /progress/{jobid}

在创建异步任务后轮询此端点。它会返回任务状态、从 0.01.0 的数值进度,以及在转换失败时返回错误详情。

页眉说明
X-API-Key您的开发者 API 密钥。
curl "https://api.converter.app/progress/b3f6b2e8f5c34c4ab01c93c4d1b2f9e8" \
  -H "X-API-Key: YOUR_API_KEY"

JavaScript

const response = await fetch('https://api.converter.app/progress/b3f6b2e8f5c34c4ab01c93c4d1b2f9e8', {
  headers: {
    'X-API-Key': apiKey
  }
});

const progress = await response.json();
console.log(progress.status, progress.progress);

Python

import requests

headers = {'X-API-Key': 'YOUR_API_KEY'}
response = requests.get(
    'https://api.converter.app/progress/b3f6b2e8f5c34c4ab01c93c4d1b2f9e8',
    headers=headers
)
response.raise_for_status()
progress = response.json()
print(progress['status'], progress['progress'])
{
  "jobid": "b3f6b2e8f5c34c4ab01c93c4d1b2f9e8",
  "progress": 1.0,
  "status": "completed",
  "error": null
}

可能的状态有 processingcompletedfailed。进度是介于 0.01.0 之间的数字。

5. 文件检索

GET /download/{jobid}

一旦异步任务达到 completed,请使用创建该任务时相同的 API 密钥获取转换后的输出。

结果类型行为
单个输出文件API 直接流式传输转换后的文件。
resultfile 清单如果任务提供结果清单,API 将返回该清单中指定的文件。
多个输出文件API 会在生成文件时即时将其打包为 .zip 压缩包。
curl -L "https://api.converter.app/download/b3f6b2e8f5c34c4ab01c93c4d1b2f9e8" \
  -H "X-API-Key: YOUR_API_KEY" \
  -o converted-output.zip

JavaScript

const response = await fetch('https://api.converter.app/download/b3f6b2e8f5c34c4ab01c93c4d1b2f9e8', {
  headers: {
    'X-API-Key': apiKey
  }
});

const file = await response.blob();

Python

import requests

headers = {'X-API-Key': 'YOUR_API_KEY'}
response = requests.get(
    'https://api.converter.app/download/b3f6b2e8f5c34c4ab01c93c4d1b2f9e8',
    headers=headers
)
response.raise_for_status()

with open('converted-output.zip', 'wb') as output:
    output.write(response.content)

开发者工作流程摘要

该 API 支持两种集成模式,开发者可以根据不同使用场景选择合适的行为。

流程请求模式最适合用于
快速同步流程POST /convert/sync 会在同一个响应中返回转换后的文件。小文件、命令行脚本、原型和简单的服务器端自动化。
稳健的异步流程POST /convert,然后轮询 GET /progress/{jobid},最后调用 GET /download/{jobid}大型视频或音频文件、批量转换、Web 应用后端,以及支持重试的生产系统。

异步流程示例

# 1. Start the job
curl -X POST "https://api.converter.app/convert" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "target_format=mp3" \
  -F "files=@/path/to/video.mp4"

# 2. Poll until completed
curl "https://api.converter.app/progress/JOBID" \
  -H "X-API-Key: YOUR_API_KEY"

# 3. Download the finished output
curl -L "https://api.converter.app/download/JOBID" \
  -H "X-API-Key: YOUR_API_KEY" \
  -o result.mp3

JavaScript

const form = new FormData();
form.append('target_format', 'mp3');
form.append('files', fileInput.files[0]);

const createResponse = await fetch('https://api.converter.app/convert', {
  method: 'POST',
  headers: {
    'X-API-Key': apiKey
  },
  body: form
});
const job = await createResponse.json();

const progressResponse = await fetch(`https://api.converter.app/progress/${job.jobid}`, {
  headers: {
    'X-API-Key': apiKey
  }
});
const progress = await progressResponse.json();

if (progress.status === 'completed') {
  const downloadResponse = await fetch(`https://api.converter.app/download/${job.jobid}`, {
    headers: {
      'X-API-Key': apiKey
    }
  });
  const result = await downloadResponse.blob();
}

Python

import requests

headers = {'X-API-Key': 'YOUR_API_KEY'}
data = {'target_format': 'mp3'}

with open('/path/to/video.mp4', 'rb') as video:
    files = {'files': video}
    create_response = requests.post(
        'https://api.converter.app/convert',
        headers=headers,
        data=data,
        files=files
    )

create_response.raise_for_status()
job = create_response.json()

progress_response = requests.get(
    f"https://api.converter.app/progress/{job['jobid']}",
    headers=headers
)
progress_response.raise_for_status()
progress = progress_response.json()

if progress['status'] == 'completed':
    download_response = requests.get(
        f"https://api.converter.app/download/{job['jobid']}",
        headers=headers
    )
    download_response.raise_for_status()
    with open('result.mp3', 'wb') as output:
        output.write(download_response.content)

错误响应

错误会以 JSON 格式返回,并包含一个 detail 字段,同时使用标准 HTTP 状态码。

状态常见原因
400缺少文件、缺少 target_format、不受支持的任务 ID 格式,或请求输入无效。
401缺少或无效的 X API Key
403API 密钥不允许使用所请求的转换格式对。
404所请求的任务或生成的结果文件不可用。
409当请求下载时,转换仍在处理中。
429该 API 密钥已无剩余额度。
500由于服务器端处理错误,无法准备或完成转换。
{
  "detail": "This API key is not authorized for mp42mp3 conversions."
}