ドキュメント

クイックスタート

数分で写真復元APIを開始できます。このガイドでは、AI駆動の写真復元をアプリケーションに統合するための重要な手順をご案内します。

前提条件

開始する前に、以下を確認してください:

  • アカウント: restoreoldphotos.online で登録
  • APIキー: 設定でAPIキーを作成
  • クレジット: 写真復元クレジットを購入
  • 画像URL: テスト用の公開アクセス可能な画像URL

ステップ1: APIキーを取得

  1. restoreoldphotos.online にアクセス
  2. Googleアカウントでサインイン
  3. 設定 > APIキーに移動
  4. 「新しいAPIキーを作成」ボタンをクリック
  5. キー名を入力(例:「マイアプリ」)
  6. キー作成後、完全なキー値をコピー(安全に保管してください!)

APIキーフォーマット

  • sk- で始まる
  • ランダムに生成された文字を含む
  • 例: sk-abc123def456ghi789...

ステップ2: 最初のAPI呼び出しを行う

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"
  }'

JavaScriptを使用

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) {
      throw new Error(`API Error: ${response.status}`);
    }
 
    const result = await response.json();
    return result.output; // URLまたはbase64文字列
  } catch (error) {
    console.error('Error:', error);
    throw error;
  }
}
 
// 使用例
const restoredImage = await restorePhoto(
  'https://example.com/old-photo.jpg',
  'your-api-key-here'
);
console.log('Restored image:', restoredImage);

ステップ3: レスポンスを処理

APIは復元された画像を含むJSONレスポンスを返します:

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

またはbase64形式:

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

outputフィールドには以下が含まれます:

  • 画像URL: 復元された画像への直接リンク
  • Base64文字列: base64でエンコードされた画像データ

ステップ4: 結果を表示

HTMLで

<img src="https://replicate.delivery/pbxt/xxx.png" alt="復元された写真" />

JavaScriptで

// URLまたはbase64用
const img = document.createElement('img');
img.src = restoredImage; // APIレスポンスのoutputフィールド
document.body.appendChild(img);

ステップ5: エラーハンドリング

適切なエラーハンドリングを常に実装してください:

try {
  const restoredImage = await restorePhoto(imageUrl, apiKey);
  // 成功を処理
} catch (error) {
  if (error.message.includes('401')) {
    console.error('無効なAPIキー');
  } else if (error.message.includes('402')) {
    console.error('クレジット不足');
  } else if (error.message.includes('429')) {
    console.error('レート制限を超過');
  } else {
    console.error('APIエラー:', error.message);
  }
}

APIキー管理

設定でのキー管理

  • すべてのAPIキーリストを表示
  • キー使用統計を表示
  • 未使用のキーを無効化または削除
  • キーの最終使用時間を表示

セキュリティのベストプラクティス

  • APIキーをクライアントサイドコードにハードコーディングしない
  • 環境変数を使用してキーを保存
  • APIキーを定期的にローテーション
  • 異なる環境で異なるキーを使用

環境変数の例

# .envファイル
PHOTO_RESTORE_API_KEY=sk-your-api-key-here
// コードで使用
const apiKey = process.env.PHOTO_RESTORE_API_KEY;