{
  "openapi": "3.0.3",
  "info": {
    "title": "iSocialize AI API",
    "description": "Generate platform-optimized social media content — text and images — for Instagram, TikTok, LinkedIn, Facebook, X/Twitter, YouTube, Pinterest, and Threads. Powered by Google Gemini.",
    "version": "1.0.0",
    "contact": {
      "name": "iSocialize AI Support",
      "email": "info@isocialize.me",
      "url": "https://ai.isocialize.me/contact"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://ai.isocialize.me/terms"
    }
  },
  "servers": [
    {
      "url": "https://ufsovdkahowhttxisneo.supabase.co/functions/v1",
      "description": "Production"
    }
  ],
  "paths": {
    "/api-generate": {
      "post": {
        "summary": "Generate social media content",
        "description": "Generate platform-optimized social media content (text or image) using AI. Text requests cost 1 credit; image requests cost 2 credits.",
        "operationId": "generateContent",
        "tags": ["Content Generation"],
        "security": [{ "ApiKeyAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/GenerateRequest" },
              "examples": {
                "instagram_caption": {
                  "summary": "Instagram caption",
                  "value": {
                    "prompt": "Create an engaging caption for a new coffee shop opening",
                    "platform": "instagram",
                    "mode": "marketing",
                    "type": "text"
                  }
                },
                "linkedin_post": {
                  "summary": "LinkedIn thought leadership post",
                  "value": {
                    "prompt": "Write a post about remote work productivity trends",
                    "platform": "linkedin",
                    "mode": "business",
                    "type": "text"
                  }
                },
                "tiktok_image": {
                  "summary": "TikTok image generation",
                  "value": {
                    "prompt": "A vibrant flat lay of workout gear for a fitness brand",
                    "platform": "tiktok",
                    "mode": "social",
                    "type": "image"
                  }
                },
                "multi_turn": {
                  "summary": "Multi-turn conversation",
                  "value": {
                    "messages": [
                      { "role": "user", "content": "Create a caption for my bakery" },
                      { "role": "assistant", "content": "🍞 Fresh from our oven to your heart! Stop by today..." },
                      { "role": "user", "content": "Make it shorter and add croissant emojis" }
                    ],
                    "platform": "instagram",
                    "mode": "social",
                    "type": "text"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Content generated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    { "$ref": "#/components/schemas/TextResponse" },
                    { "$ref": "#/components/schemas/ImageResponse" }
                  ]
                },
                "examples": {
                  "text_success": {
                    "summary": "Text generation response",
                    "value": {
                      "success": true,
                      "type": "text",
                      "data": {
                        "content": "☕ Your morning just got better! Grand opening this Saturday — come taste the difference. Fresh roasts, cozy vibes, and baristas who actually care. 📍 123 Main St\n\n#CoffeeShop #GrandOpening #LocalCoffee #MorningVibes #CoffeeCommunity",
                        "platform": "instagram",
                        "mode": "marketing"
                      },
                      "credits": {
                        "used": 1,
                        "remaining": 499
                      }
                    }
                  },
                  "image_success": {
                    "summary": "Image generation response",
                    "value": {
                      "success": true,
                      "type": "image",
                      "data": {
                        "image_url": "data:image/png;base64,iVBORw0KGgo...",
                        "prompt": "A vibrant flat lay of workout gear for a fitness brand",
                        "platform": "tiktok"
                      },
                      "credits": {
                        "used": 2,
                        "remaining": 498
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": {
                  "error": "Invalid platform",
                  "valid_platforms": ["instagram","twitter","facebook","linkedin","tiktok","youtube","pinterest","threads"],
                  "received": "snapchat"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" },
                "example": { "error": "Invalid API key" }
              }
            }
          },
          "402": {
            "description": "Insufficient credits",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CreditErrorResponse" },
                "example": {
                  "error": "Insufficient credits",
                  "message": "This request requires 2 credits, you have 1",
                  "balance": 1,
                  "required": 2
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key generated at ai.isocialize.me/api-keys. Format: isa_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      }
    },
    "schemas": {
      "GenerateRequest": {
        "type": "object",
        "description": "Request body for content generation. Either `prompt` or `messages` is required.",
        "properties": {
          "prompt": {
            "type": "string",
            "maxLength": 5000,
            "description": "The content generation request. Required unless `messages` is provided.",
            "example": "Create an engaging caption for a new coffee shop opening"
          },
          "platform": {
            "type": "string",
            "enum": ["instagram","twitter","facebook","linkedin","tiktok","youtube","pinterest","threads"],
            "default": "instagram",
            "description": "Target social media platform. Affects tone, length, hashtag strategy, and formatting."
          },
          "mode": {
            "type": "string",
            "enum": ["social","marketing","personal","business"],
            "default": "social",
            "description": "Content style and intent.\n- `social`: Engagement-focused, hashtags + emojis\n- `marketing`: Conversion-focused, urgency, CTA\n- `personal`: Authentic, relatable, community-building\n- `business`: Professional, thought leadership, B2B tone"
          },
          "type": {
            "type": "string",
            "enum": ["text","image"],
            "default": "text",
            "description": "Content type. `text` costs 1 credit; `image` costs 2 credits. Images are returned as base64 data URIs."
          },
          "messages": {
            "type": "array",
            "maxItems": 50,
            "description": "Multi-turn conversation history. Use instead of `prompt` for iterative content refinement. Each message's content is limited to 10,000 characters.",
            "items": {
              "type": "object",
              "required": ["role","content"],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": ["user","assistant","system"]
                },
                "content": {
                  "type": "string",
                  "maxLength": 10000
                }
              }
            }
          }
        }
      },
      "TextResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "type": { "type": "string", "enum": ["text"] },
          "data": {
            "type": "object",
            "properties": {
              "content": { "type": "string", "description": "Generated text content ready to post" },
              "platform": { "type": "string", "description": "Echoed platform from request" },
              "mode": { "type": "string", "description": "Echoed mode from request" }
            }
          },
          "credits": {
            "type": "object",
            "properties": {
              "used": { "type": "integer", "example": 1 },
              "remaining": { "type": "integer", "example": 499 }
            }
          }
        }
      },
      "ImageResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "example": true },
          "type": { "type": "string", "enum": ["image"] },
          "data": {
            "type": "object",
            "properties": {
              "image_url": { "type": "string", "description": "Base64 data URI of the generated image (data:image/png;base64,...)" },
              "prompt": { "type": "string", "description": "Echoed prompt from request" },
              "platform": { "type": "string", "description": "Echoed platform from request" }
            }
          },
          "credits": {
            "type": "object",
            "properties": {
              "used": { "type": "integer", "example": 2 },
              "remaining": { "type": "integer", "example": 498 }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "description": "Machine-readable error message" },
          "details": { "type": "string", "description": "Additional error context (optional)" }
        }
      },
      "CreditErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" },
          "balance": { "type": "integer", "description": "Current credit balance" },
          "required": { "type": "integer", "description": "Credits required for this request" }
        }
      }
    }
  }
}
