API & MCP

Intégrez NanoClone dans vos projets via l'API REST ou le serveur MCP.

Base URL

http://localhost:3000/api

Toutes les requĂȘtes retournent un JSON avec le format :

{
  "success": true,
  "data": { ... },
  "error": null
}
POST

/api/generate

Générer une image à partir d'un prompt texte via Gemini Nano Banana.

Request body

{
  "prompt": "A futuristic city at sunset with flying cars",
  "conversationId": "optional-uuid-to-continue-thread"
}

Response

{
  "success": true,
  "data": {
    "conversationId": "uuid",
    "message": {
      "id": "uuid",
      "role": "assistant",
      "content": "Description of the generated image",
      "imageBase64": "iVBORw0KGgo...",
      "createdAt": "2026-03-09T..."
    },
    "model": "gemini-2.0-flash-exp"
  },
  "error": null
}

Exemple cURL

curl -X POST http://localhost:3000/api/generate \
  -H "Content-Type: application/json" \
  -d '{"prompt": "A cute cat in space"}'

Exemple Python

import requests
import base64

res = requests.post("http://localhost:3000/api/generate", json={
    "prompt": "A cute cat in space"
})

data = res.json()["data"]
if data["message"]["imageBase64"]:
    with open("image.png", "wb") as f:
        f.write(base64.b64decode(data["message"]["imageBase64"]))

Exemple JavaScript

const res = await fetch("http://localhost:3000/api/generate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ prompt: "A cute cat in space" })
});

const { data } = await res.json();
// data.message.imageBase64 contains the PNG in base64
GET

/api/keys

Lister toutes les clés API (masquées).

curl http://localhost:3000/api/keys
POST

/api/keys

Ajouter une nouvelle clé API Gemini.

// Body
{
  "key": "AIzaSy...",
  "label": "Mon compte perso"  // optionnel
}
curl -X POST http://localhost:3000/api/keys \
  -H "Content-Type: application/json" \
  -d '{"key": "AIzaSy...", "label": "Compte 1"}'
DELETE

/api/keys?id=uuid

Supprimer une clé API.

curl -X DELETE "http://localhost:3000/api/keys?id=your-key-uuid"
GET

/api/conversations

Lister toutes les conversations avec nombre de messages et d'images.

curl http://localhost:3000/api/conversations
GET

/api/images

Lister toutes les images générées. Filtrer par conversation avec ?conversation_id=uuid.

# Toutes les images
curl http://localhost:3000/api/images

# Images d'une conversation spécifique
curl "http://localhost:3000/api/images?conversation_id=your-conv-uuid"

Rotation automatique des clés

  • Ajoutez plusieurs clĂ©s API pour maximiser le quota gratuit
  • Quand une clĂ© atteint 500 requĂȘtes/jour, elle est automatiquement dĂ©sactivĂ©e
  • Quand l'API retourne une erreur 429, la clĂ© est marquĂ©e Ă©puisĂ©e et la suivante prend le relais
  • Les clĂ©s Ă©puisĂ©es se rĂ©activent automatiquement aprĂšs 24h
  • La clĂ© avec le moins d'utilisation est toujours choisie en premier (round-robin)