文檔

照片修復 API

使用 AI 技術修復舊照片

照片修復 API 允許您使用先進的 AI 技術修復舊的、受損的照片。此端點處理圖像並返回修復版本。體驗 Restore Old Photos 的強大 AI 照片修復功能。

端點

POST /api/api-call/photo-restore

身份驗證

需要在 Authorization 標頭中使用有效的 API 金鑰:

Authorization: Bearer YOUR_API_KEY

請求

標頭

標頭必需描述
Content-Type必須是 application/json
Authorization您的 API 金鑰,格式為 Bearer YOUR_API_KEY

主體參數

參數類型必需描述
imageUrlstring要修復的圖像 URL(必須可公開訪問)

請求範例

{
  "imageUrl": "https://example.com/old-photo.jpg"
}

回應

成功回應 (200)

API 返回修復圖像的 URL 或 base64 字串。平台自動處理所有串流類型,output 欄位始終是 URL 或 base64 字串。

{
  "output": "https://replicate.delivery/pbxt/xxx.png"
}

或:

{
  "output": "data:image/png;base64,iVBORw0KGgoAAAANS..."
}

描述

  • 輸出是圖像的 URL(推薦)或 base64 字串(適用於部分圖像/大檔案)
  • 不返回串流物件,用戶可以直接用於 img 標籤或下載

錯誤回應

400 Bad Request

{
  "message": "無效輸入"
}

401 Unauthorized

{
  "message": "無效或過期的 API 金鑰"
}

402 Payment Required

{
  "message": "積分不足"
}

500 Internal Server Error

{
  "message": "服務錯誤"
}

429 Too Many Requests

{
  "message": "超出速率限制。請稍後再試。"
}

速率限制

  • 限制:每個 API 金鑰每小時 100 個請求
  • 時間窗口:60 分鐘
  • 回應:超出時返回 429 Too Many Requests

使用範例

JavaScript/Node.js

async function restorePhoto(imageUrl, apiKey) {
  try {
    const response = await fetch('https://restoreoldphotos.online/api/api-call/photo-restore', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${apiKey}`
      },
      body: JSON.stringify({
        imageUrl: imageUrl
      })
    });
 
    if (!response.ok) {
      const error = await response.text();
      throw new Error(`API 錯誤:${response.status} - ${error}`);
    }
 
    const result = await response.json();
    
    // 輸出始終是字串(URL 或 base64)
    if (result.output.startsWith('data:image')) {
      // Base64 圖像資料
      return result.output;
    } else if (result.output.startsWith('http')) {
      // 圖像 URL
      return result.output;
    } else {
      throw new Error('無效的輸出格式');
    }
  } catch (error) {
    console.error('修復照片時出錯:', error);
    throw error;
  }
}
 
// 使用
const restoredImage = await restorePhoto(
  'https://example.com/old-photo.jpg',
  'your-api-key-here'
);
console.log('修復的圖像:', restoredImage);

cURL

curl -X POST https://restoreoldphotos.online/api/api-call/photo-restore \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "imageUrl": "https://example.com/old-photo.jpg"
  }'

圖像要求

  • 格式:JPG、PNG、WebP
  • 大小:最大 5MB
  • 可訪問性:圖像 URL 必須可公開訪問
  • 內容:必須是有效的圖像檔案

處理時間

  • 典型:10-30 秒
  • 大圖像:可能需要長達 60 秒

積分

  • 成本:每次修復 1 積分
  • 扣除:成功處理後扣除積分

最佳實踐

  1. 圖像品質:使用高品質圖像以獲得更好結果
  2. 錯誤處理:始終實施適當的錯誤處理
  3. 積分管理:定期監控您的積分餘額
  4. 輸出處理:輸出始終是字串,無需串流處理

故障排除

常見問題

401 Unauthorized

  • 檢查您的 API 金鑰是否正確
  • 確保 API 金鑰處於活動狀態且未過期

402 Payment Required

  • 為您的帳戶添加積分
  • 檢查您當前的積分餘額

400 Bad Request

  • 驗證 imageUrl 是有效的、可訪問的 URL
  • 確保圖像格式受支援

無效輸出格式

  • 輸出應始終是字串(URL 或 base64)
  • 檢查 API 回應是否包含預期的輸出欄位

429 Too Many Requests

  • 您已超出每小時 100 個請求的速率限制
  • 在發出更多請求之前等待速率限制窗口重置

支援

如果您遇到此處未涵蓋的問題,請聯繫我們的支援團隊。