MPP API — Integrationsleitfaden

Alles, was Sie benötigen, um die Hintergrundentfernung mit dem MPP-Zahlungsprotokoll zu integrieren.

Schnellstart

Senden Sie eine POST-Anfrage mit Ihrem Bild als Rohinhalt. Die API antwortet mit HTTP 402 und einem WWW-Authenticate: Payment-Header gemäß der MPP-Spezifikation.

# Step 1: discovery — returns HTTP 402 with a "Payment" challenge
curl -X POST https://mpp.clearcanvas.app/v1/remove-background \
  -H "Content-Type: image/png" \
  --data-binary @photo.png

# Step 2: paid request — attach an Authorization: Payment header
curl -X POST https://mpp.clearcanvas.app/v1/remove-background \
  -H "Content-Type: image/png" \
  -H "Authorization: Payment <mpp-credential>" \
  --data-binary @photo.png \
  --output result.png

Authentifizierung via MPP

MPP ist ein offenes HTTP-Zahlungsprotokoll, gemeinsam gestartet von Stripe und Tempo. Bei der ersten Anfrage gibt die API HTTP 402 mit einer WWW-Authenticate: Payment-Challenge zurück. Signieren Sie eine pathUSD-Überweisung auf Tempo mit dem mppx SDK und senden Sie die Anfrage mit dem Authorization: Payment-Header erneut.

mppx SDK-Dokumentation ansehen

TypeScript

import fs from 'fs';
import { MppxClient } from 'mppx/client';

// Configure the mppx client for the Tempo crypto rail (pathUSD).
const client = new MppxClient({
  wallet: process.env.TEMPO_WALLET_PRIVATE_KEY!,
  network: 'tempo',
});

const res = await client.fetch('https://mpp.clearcanvas.app/v1/remove-background', {
  method: 'POST',
  headers: { 'Content-Type': 'image/png' },
  body: fs.readFileSync('photo.png'),
});

const buffer = await res.arrayBuffer();
fs.writeFileSync('result.png', Buffer.from(buffer));

Python

import os
import httpx
from mpp import wrap_httpx   # pip install mpp

client = wrap_httpx(
    wallet=os.environ["TEMPO_WALLET_PRIVATE_KEY"],
    network="tempo",
)
resp = client.post(
    "https://mpp.clearcanvas.app/v1/remove-background",
    content=open("photo.png", "rb").read(),
    headers={"Content-Type": "image/png"},
)
open("result.png", "wb").write(resp.content)

Anfrageformat

  • Endpunkt
  • Body: rohe Bildbytes (PNG, JPEG oder WebP)
  • Content-Type: image/png | image/jpeg | image/webp
  • Optional: ?format=webp für WebP-Ausgabe

Antwortformat

  • HTTP 200 — Binärbild (PNG oder WebP)
  • HTTP 402 — Zahlung erforderlich (WWW-Authenticate: Payment-Challenge)

Fehlerbehandlung

  • 400 — Ungültiges Bild (falsches Format, Magic-Bytes stimmen nicht überein, oder Abmessung überschritten)
  • 413 — Datei zu groß (> 25 MB)
  • 415 — Nicht unterstützter Content-Type
  • 429 — Rate-Limit überschritten (nicht bezahlte Anfragen: 30/min/IP)
  • 500 — Verarbeitung fehlgeschlagen (retryable: true)
  • 503 — Prozessor vorübergehend nicht verfügbar (retryable: true)

Limits & Formate

  • Max. Dateigröße: 25 MB
  • Max. Abmessungen: 10.000 × 10.000 px
  • Unterstützte Eingabe: PNG, JPEG, WebP
  • Ausgabe: PNG (Standard) oder WebP

Netzwerk

Die API läuft auf dem Tempo Mainnet. Zahlungen werden in pathUSD abgewickelt ($0.05 pro Bild). Stellen Sie sicher, dass Ihre Tempo-Wallet pathUSD hält, bevor Sie Anfragen stellen. Nutzen Sie das Tempo-Testnet für End-to-End-Tests zum Nulltarif.

Bereit zur Integration?