APIリファレンス
強力でシンプルなRESTful API - わずか数行のコードでプロフェッショナルなPDFから電子書籍への変換を実装
APIリクエスト
ベースURL:
https://fusion-api.oomol.com/v1認証
すべてのリクエストにはAuthorizationヘッダーにAPIキーが必要です(形式:Bearer YOUR_API_KEY)
Authorization: Bearer YOUR_API_KEY
POST
/pdf-transform-markdown/submitPDFからMarkdownへのタスクを送信
PDFファイルのURLをアップロードし、Markdown形式への変換タスクを送信する
リクエストパラメータ
pdfURL- PDFファイルのクラウドURL(文字列、必須、ファイルアップロードAPIから取得)model- 変換モデル(文字列、必須、固定値:"gundam")filename- 拡張子なしの出力ファイル名(任意)、ファイルを識別しやすくするために使用ignore_pdf_errors- PDF解析エラーを無視する(任意、デフォルト:true)ignore_ocr_errors- OCRエラーを無視する(任意、デフォルト:true)
リクエスト例
{
"pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf",
"model": "gundam",
"filename": "my-document",
"ignore_pdf_errors": true,
"ignore_ocr_errors": true
}レスポンス例
{
"success": true,
"sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"
}GET
/pdf-transform-markdown/result/:taskIdPDFからMarkdownへの結果を照会
タスクIDで変換タスクのステータスと結果を照会する
URLパラメータ
taskId- タスクID(送信APIから返されるsessionID)
レスポンス例(処理中)
{
"success": true,
"state": "processing",
"progress": 66
}レスポンス例(完了)
{
"success": true,
"state": "completed",
"progress": 100,
"data": {
"downloadURL": "https://cdn.oomol.com/result.md"
}
}レスポンス例(失敗)
{
"success": false,
"state": "failed",
"progress": 0,
"error": "変換失敗の理由"
}POST
/pdf-transform-epub/submitPDFからEPUBへのタスクを送信
PDFファイルのURLをアップロードし、EPUB形式への変換タスクを送信する
リクエストパラメータ
pdfURL- PDFファイルのクラウドURL(文字列、必須、ファイルアップロードAPIから取得)model- 変換モデル(文字列、必須、固定値:"gundam")filename- 拡張子なしの出力ファイル名(任意)、ファイルを識別しやすくするために使用ignore_pdf_errors- PDF解析エラーを無視する(任意、デフォルト:true)ignore_ocr_errors- OCRエラーを無視する(任意、デフォルト:true)
リクエスト例
{
"pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf",
"model": "gundam",
"filename": "my-document",
"ignore_pdf_errors": true,
"ignore_ocr_errors": true
}レスポンス例
{
"success": true,
"sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"
}GET
/pdf-transform-epub/result/:taskIdPDFからEPUBへの結果を照会
タスクIDで変換タスクのステータスと結果を照会する
URLパラメータ
taskId- タスクID(送信APIから返されるsessionID)
レスポンス例(処理中)
{
"success": true,
"state": "processing",
"progress": 66
}レスポンス例(完了)
{
"success": true,
"state": "completed",
"progress": 100,
"data": {
"downloadURL": "https://cdn.oomol.com/result.epub"
}
}レスポンス例(失敗)
{
"success": false,
"state": "failed",
"progress": 0,
"error": "変換失敗の理由"
}cURL
# 1. Submit PDF to Markdown taskcurl -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"}'# Response: {"success": true, "sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"}# 2. Query conversion resultcurl -X GET https://fusion-api.oomol.com/v1/pdf-transform-markdown/result/019aa097-f28d-7000-8d56-6a2987a7b144 \-H "Authorization: Bearer YOUR_API_KEY"# Response: {"success": true, "state": "completed", "data": {"downloadURL": "https://cdn.oomol.com/result.md"}}
Python SDK
PDF Craft APIと連携するためのPython SDKです。認証、タスク送信、結果のポーリングを処理することで、PDFをMarkdownやEPUBに変換するプロセスを簡素化します。
インストール
pip install pdf-craft-sdk
基本的な使い方
from pdf_craft_sdk import PDFCraftClient# Initialize the clientclient = PDFCraftClient(api_key="YOUR_API_KEY")# Convert a local PDF to Markdowntry: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}")
進捗追跡付きのローカルファイルアップロード
from pdf_craft_sdk import PDFCraftClient, UploadProgressdef 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 trackingdownload_url = client.convert_local_pdf("large_document.pdf",progress_callback=on_progress)
リモートPDF変換
from pdf_craft_sdk import PDFCraftClient, FormatTypeclient = PDFCraftClient(api_key="YOUR_API_KEY")# Convert remote PDF to EPUBdownload_url = client.convert(pdf_url="https://example.com/file.pdf",format_type=FormatType.EPUB,includes_footnotes=True)print(f"Download URL: {download_url}")
高度な使い方(ステップバイステップ)
from pdf_craft_sdk import PDFCraftClient, FormatTypeclient = PDFCraftClient(api_key="YOUR_API_KEY")# Step 1: Upload filecache_url = client.upload_file("document.pdf")# Step 2: Submit conversion tasktask_id = client.submit_conversion(cache_url,format_type=FormatType.MARKDOWN)print(f"Task submitted. ID: {task_id}")# Step 3: Wait for completiondownload_url = client.wait_for_completion(task_id)print(f"Download URL: {download_url}")
設定オプション
- max_wait_ms:最大待機時間(ミリ秒、デフォルト:7200000、つまり2時間)
- check_interval_ms:初回ポーリング間隔(ミリ秒、デフォルト:1000)
- max_check_interval_ms:最大ポーリング間隔(ミリ秒、デフォルト:5000)
- backoff_factor:間隔を増やすための乗数、またはPollingStrategy enumを使用(デフォルト:PollingStrategy.EXPONENTIAL / 1.5)
- model:変換に使用するモデル(デフォルト:'gundam')
from pdf_craft_sdk import PDFCraftClient, FormatType, PollingStrategyclient = PDFCraftClient(api_key="YOUR_API_KEY")# Example with custom polling configurationdownload_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 minutescheck_interval_ms=2000, # Initial polling interval: 2 secondsmax_check_interval_ms=10000, # Maximum polling interval: 10 secondsbackoff_factor=PollingStrategy.EXPONENTIAL # or 1.5)
TypeScript SDK
PDF Craft APIと連携するためのTypeScript SDKです。認証、タスク送信、結果のポーリングを処理することで、PDFをMarkdownやEPUBに変換するプロセスを簡素化します。
インストール
npm install pdf-craft-sdk-ts# oryarn add pdf-craft-sdk-ts
基本的な使い方
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();
進捗追跡付きのローカルファイルアップロード
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 fileconst downloadUrl = await client.convertLocalPdf("document.pdf", {formatType: FormatType.Markdown,progressCallback: onProgress,includesFootnotes: true,uploadMaxRetries: 5});
バッチ処理
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");// Create batch conversionconst 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 progressconst status = await client.getBatchStatus(batch.batchId);console.log(`Completed: ${status.completedCount}/${status.totalCount}`);
高度な使い方(ステップバイステップ)
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");// Step 1: Submit taskconst taskId = await client.submitConversion("cache://file.pdf",FormatType.Markdown);console.log(`Task submitted. ID: ${taskId}`);// Step 2: Poll for completionconst downloadUrl = await client.waitForCompletion(taskId,FormatType.Markdown);console.log(`Download URL: ${downloadUrl}`);
設定オプション
- formatType:FormatType.Markdown | FormatType.EPUB(デフォルト:FormatType.Markdown)
- model: 使用するモデル(デフォルト: 'gundam')
- wait: 完了を待機するかどうか(デフォルト: true)
- maxWaitMs: 最大待機時間(ミリ秒)(デフォルト: 7200000、つまり2時間)
- checkIntervalMs: 初回ポーリング間隔(ミリ秒)(デフォルト: 1000)
- maxCheckIntervalMs: 最大ポーリング間隔(ミリ秒)(デフォルト: 5000)
- backoffFactor: 間隔を増やすための乗数、または PollingStrategy enum を使用(デフォルト: PollingStrategy.Exponential / 1.5)
import { PDFCraftClient, FormatType, PollingStrategy } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");// Example with custom polling configurationconst 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 minutescheckIntervalMs: 2000, // Initial polling interval: 2 secondsmaxCheckIntervalMs: 10000, // Maximum polling interval: 10 secondsbackoffFactor: PollingStrategy.Exponential // or use a number like 1.5});