# API 文档

[HTML](https://pdfcraft.ai/zh-CN/api/) · [Site index](https://pdfcraft.ai/llms.txt)

[OpenAPI](https://pdfcraft.ai/openapi.json)

将 PDF 转电子书功能集成到您的应用中

## 认证

所有请求需要在 Authorization 请求头中携带 API 密钥（格式：Bearer YOUR_API_KEY）



```text
Authorization: Bearer YOUR_API_KEY
```


## API 请求

https://fusion-api.oomol.com/v1

POST /pdf-transform-markdown/submit

POST /pdf-transform-epub/submit

- pdfURL: PDF 文件的云端 URL（string，必需，从文件上传接口获取）

- model: 转换模型（string，必需，固定值为 "gundam"）

- filename: 文件名(不含扩展名,可选),用于用户下载后识别文件

- ignore_pdf_errors: 是否忽略 PDF 解析错误(可选,默认为 true)

- ignore_ocr_errors: 是否忽略 OCR 错误(可选,默认为 true)



```json
{
  "pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf",
  "model": "gundam",
  "filename": "my-document",
  "ignore_pdf_errors": true,
  "ignore_ocr_errors": true
}
```




```json
{
  "success": true,
  "sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"
}
```


GET /pdf-transform-markdown/result/:taskId

GET /pdf-transform-epub/result/:taskId



```json
{
  "success": true,
  "state": "processing",
  "progress": 66
}
```




```json
{
  "success": true,
  "state": "completed",
  "progress": 100,
  "data": {
    "downloadURL": "https://cdn.oomol.com/result.md"
  }
}
```




```json
{
  "success": true,
  "state": "completed",
  "progress": 100,
  "data": {
    "downloadURL": "https://cdn.oomol.com/result.epub"
  }
}
```




```json
{
  "success": false,
  "state": "failed",
  "progress": 0,
  "error": "转换失败原因"
}
```


## cURL



```bash
# 1. 提交 PDF 转 Markdown 任务
curl -X POST https://fusion-api.oomol.com/v1/pdf-transform-markdown/submit \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf",
    "model": "gundam",
    "filename": "my-document"
  }'

# 响应: {"success": true, "sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"}

# 2. 查询转换结果
curl -X GET https://fusion-api.oomol.com/v1/pdf-transform-markdown/result/019aa097-f28d-7000-8d56-6a2987a7b144 \
  -H "Authorization: Bearer YOUR_API_KEY"

# 响应: {"success": true, "state": "completed", "data": {"downloadURL": "https://cdn.oomol.com/result.md"}}
```


## Python SDK



```python
pip install pdf-craft-sdk
```




```python
from pdf_craft_sdk import PDFCraftClient

# Initialize the client
client = PDFCraftClient(api_key="YOUR_API_KEY")

# Convert a local PDF to Markdown
try:
    download_url = client.convert_local_pdf("document.pdf")
    print(f"Conversion successful! Download URL: {download_url}")
except Exception as e:
    print(f"An error occurred: {e}")
```




```python
from pdf_craft_sdk import PDFCraftClient, UploadProgress

def on_progress(progress: UploadProgress):
    print(f"Upload: {progress.percentage:.2f}% - Part {progress.current_part}/{progress.total_parts}")

client = PDFCraftClient(api_key="YOUR_API_KEY")

# Upload local file with progress tracking
download_url = client.convert_local_pdf(
    "large_document.pdf",
    progress_callback=on_progress
)
```




```python
from pdf_craft_sdk import PDFCraftClient, FormatType

client = PDFCraftClient(api_key="YOUR_API_KEY")

# Convert remote PDF to EPUB
download_url = client.convert(
    pdf_url="https://example.com/file.pdf",
    format_type=FormatType.EPUB,
    includes_footnotes=True
)
print(f"Download URL: {download_url}")
```




```python
from pdf_craft_sdk import PDFCraftClient, FormatType

client = PDFCraftClient(api_key="YOUR_API_KEY")

# Step 1: Upload file
cache_url = client.upload_file("document.pdf")

# Step 2: Submit conversion task
task_id = client.submit_conversion(
    cache_url,
    format_type=FormatType.MARKDOWN
)
print(f"Task submitted. ID: {task_id}")

# Step 3: Wait for completion
download_url = client.wait_for_completion(task_id)
print(f"Download URL: {download_url}")
```




```python
from pdf_craft_sdk import PDFCraftClient, FormatType, PollingStrategy

client = PDFCraftClient(api_key="YOUR_API_KEY")

# Example with custom polling configuration
download_url = client.convert(
    pdf_url="https://example.com/file.pdf",
    format_type=FormatType.MARKDOWN,
    model="gundam",
    includes_footnotes=True,
    ignore_pdf_errors=True,
    ignore_ocr_errors=True,
    max_wait_ms=600000,           # Maximum wait time: 10 minutes
    check_interval_ms=2000,       # Initial polling interval: 2 seconds
    max_check_interval_ms=10000,  # Maximum polling interval: 10 seconds
    backoff_factor=PollingStrategy.EXPONENTIAL  # or 1.5
)
```


## TypeScript SDK



```typescript
npm install pdf-craft-sdk-ts
# or
yarn add pdf-craft-sdk-ts
```




```typescript
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';

const client = new PDFCraftClient("YOUR_API_KEY");

async function main() {
    try {
        const downloadUrl = await client.convert("cache://your-pdf-file.pdf", {
            formatType: FormatType.Markdown
        });
        console.log(`Success! Download: ${downloadUrl}`);
    } catch (error) {
        console.error("Error:", error);
    }
}

main();
```




```typescript
import { PDFCraftClient, FormatType, UploadProgress } from 'pdf-craft-sdk-ts';

const client = new PDFCraftClient("YOUR_API_KEY");

const onProgress = (progress: UploadProgress) => {
    console.log(`Progress: ${progress.percentage.toFixed(2)}%`);
    console.log(`Part ${progress.currentPart}/${progress.totalParts}`);
};

// Upload and convert local file
const downloadUrl = await client.convertLocalPdf("document.pdf", {
    formatType: FormatType.Markdown,
    progressCallback: onProgress,
    includesFootnotes: true,
    uploadMaxRetries: 5
});
```




```typescript
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';

const client = new PDFCraftClient("YOUR_API_KEY");

// Create batch conversion
const files = [
    { url: "cache://file1.pdf", fileName: "document1.pdf" },
    { url: "cache://file2.pdf", fileName: "document2.pdf" }
];

const batch = await client.createBatch(files, FormatType.Markdown, false);
const result = await client.startBatch(batch.batchId);

// Monitor progress
const status = await client.getBatchStatus(batch.batchId);
console.log(`Completed: ${status.completedCount}/${status.totalCount}`);
```




```typescript
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';

const client = new PDFCraftClient("YOUR_API_KEY");

// Step 1: Submit task
const taskId = await client.submitConversion(
    "cache://file.pdf",
    FormatType.Markdown
);
console.log(`Task submitted. ID: ${taskId}`);

// Step 2: Poll for completion
const downloadUrl = await client.waitForCompletion(
    taskId,
    FormatType.Markdown
);
console.log(`Download URL: ${downloadUrl}`);
```




```typescript
import { PDFCraftClient, FormatType, PollingStrategy } from 'pdf-craft-sdk-ts';

const client = new PDFCraftClient("YOUR_API_KEY");

// Example with custom polling configuration
const downloadUrl = await client.convert("cache://file.pdf", {
    formatType: FormatType.Markdown,
    model: "gundam",
    wait: true,
    includesFootnotes: true,
    ignorePdfErrors: true,
    ignoreOcrErrors: true,
    maxWaitMs: 600000,           // Maximum wait time: 10 minutes
    checkIntervalMs: 2000,       // Initial polling interval: 2 seconds
    maxCheckIntervalMs: 10000,   // Maximum polling interval: 10 seconds
    backoffFactor: PollingStrategy.Exponential  // or use a number like 1.5
});
```
