MPP API — Guide d'intégration

Tout ce dont vous avez besoin pour intégrer la suppression d'arrière-plan en utilisant le protocole de paiement MPP.

Démarrage rapide

Envoyez une requête POST avec votre image comme corps brut. L'API renvoie un challenge HTTP 402 avec un en-tête WWW-Authenticate: Payment conformément à la spécification MPP.

# 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

Authentification via MPP

MPP est un protocole de paiement HTTP ouvert co-lancé par Stripe et Tempo. Lors de la première requête, l'API renvoie HTTP 402 avec un challenge WWW-Authenticate: Payment. Signez un transfert pathUSD sur Tempo avec le SDK mppx, puis renvoyez avec l'en-tête Authorization: Payment.

Voir la documentation du SDK mppx

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)

Format de requête

  • Endpoint
  • Body : octets d'image bruts (PNG, JPEG ou WebP)
  • Content-Type : image/png | image/jpeg | image/webp
  • Optionnel : ?format=webp pour une sortie WebP

Format de réponse

  • HTTP 200 — image binaire (PNG ou WebP)
  • HTTP 402 — paiement requis (challenge WWW-Authenticate: Payment)

Gestion des erreurs

  • 400 — Image invalide (mauvais format, magic bytes non concordants, ou dimension dépassée)
  • 413 — Fichier trop volumineux (> 25 Mo)
  • 415 — Content-Type non supporté
  • 429 — Limite de débit dépassée (requêtes non payées : 30/min/IP)
  • 500 — Échec du traitement (retryable : true)
  • 503 — Processeur temporairement indisponible (retryable : true)

Limites et formats

  • Taille max. du fichier : 25 Mo
  • Dimensions max. : 10 000 × 10 000 px
  • Entrée supportée : PNG, JPEG, WebP
  • Sortie : PNG (par défaut) ou WebP

Réseau

L'API fonctionne sur Tempo mainnet. Les paiements sont réglés en pathUSD (0,05 $ par image). Assurez-vous que votre wallet Tempo contient des pathUSD avant d'effectuer des requêtes. Utilisez le testnet Tempo pour des tests de bout en bout sans frais.

Prêt à intégrer ?