文档

照片修复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..."
}

说明

  • output为图片的URL(推荐)或base64字符串(部分图片/大文件时)
  • 不会返回流对象,用户可直接用于img标签或下载

错误响应

400 错误请求

{
  "message": "Invalid input"
}

401 未授权

{
  "message": "Invalid or expired API key"
}

402 需要付款

{
  "message": "Insufficient credits"
}

500 内部服务器错误

{
  "message": "Service error"
}

429 请求过多

{
  "message": "Rate limit exceeded. Please try again later."
}

频率限制

  • 限制: 每个API密钥每小时100次请求
  • 时间窗口: 60分钟
  • 超出限制响应: 429 请求过多

使用示例

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 Error: ${response.status} - ${error}`);
    }
 
    const result = await response.json();
    
    // output始终为字符串(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. 输出处理:output始终为字符串,无需流处理

故障排除

常见问题

401 未授权

  • 检查您的API密钥是否正确
  • 确保API密钥处于活动状态且未过期

402 需要付款

  • 向您的账户添加积分
  • 检查当前积分余额

400 错误请求

  • 验证imageUrl是有效的、可访问的URL
  • 确保图像格式受支持

无效输出格式

  • output应该始终为字符串(URL或base64)
  • 检查API响应是否包含预期的output字段

429 请求过多

  • 您已超过每小时100次请求的频率限制
  • 请等待频率限制窗口重置后再进行请求

支持

如果您遇到此处未涵盖的问题,请联系我们的支持团队。