{
  "openapi": "3.0.3",
  "info": {
    "title": "Onyxcine Commerce & Creator Toolkit API",
    "version": "1.0.0",
    "description": "Fast, zero-storage edge utilities by Onyxcine Studio for Shopify merchants, TikTok Shop affiliates, and e-commerce automation workflows: validate and auto-repair Shopify product CSV feeds, audit short-form video scripts against 2026 TikTok Shop & FTC compliance rules, and model Spark Ads / GMV Max creator-vs-brand unit economics.",
    "contact": {
      "name": "Onyxcine Studio",
      "url": "https://onyxcine.com"
    }
  },
  "servers": [
    {
      "url": "https://api.onyxcine.com",
      "description": "Production Edge API (Cloudflare Workers)"
    }
  ],
  "tags": [
    {
      "name": "System",
      "description": "Health and service discovery"
    },
    {
      "name": "Shopify",
      "description": "Shopify catalog validation and repair"
    },
    {
      "name": "TikTok Shop",
      "description": "Compliance auditing and Spark Ads ROI modeling"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "Health check & active endpoints",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "Service health status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": true,
                  "service": "onyxcine-api",
                  "brand": "Onyxcine Studio",
                  "version": "1.0.0",
                  "endpoints": [
                    "/v1/shopify/csv-fix",
                    "/v1/tiktok/policy-check",
                    "/v1/tiktok/spark-ads-roi"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/shopify/csv-fix": {
      "post": {
        "tags": [
          "Shopify"
        ],
        "summary": "Validate & auto-repair Shopify Product CSV",
        "operationId": "fixShopifyCsv",
        "description": "Detects silent SKU drops, duplicate variants, missing handles, mixed currency formats, negative prices, HTTP image URLs, missing Shopify fulfillment/inventory defaults, and spreadsheet formula injections in Shopify product CSV files (up to 5,000 rows / 1 MB per request).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "csv"
                ],
                "properties": {
                  "csv": {
                    "type": "string",
                    "description": "Raw Shopify CSV text (UTF-8)"
                  },
                  "handleSuffix": {
                    "type": "string",
                    "description": "Optional suffix appended to product handles for safe multi-store imports"
                  },
                  "neutralizeFormulas": {
                    "type": "boolean",
                    "default": true,
                    "description": "Prefix spreadsheet formula characters (=,+,-,@) to prevent CSV injection"
                  }
                }
              },
              "example": {
                "csv": "Handle,Title,Option1 Name,Option1 Value,Variant Price,Image Src\n,Classic Linen Shirt,Size,S,\"$29.00\",http://cdn.example.com/shirt.jpg\n,Classic Linen Shirt,,M,\"$29.00\",\n",
                "handleSuffix": "us",
                "neutralizeFormulas": true
              }
            },
            "text/csv": {
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation report, repaired statistics, and cleaned Shopify CSV output",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": true,
                  "brand": "Onyxcine Catalog API",
                  "stats": {
                    "products": 1,
                    "rows": 2,
                    "errors": 0,
                    "warnings": 0,
                    "fixed": 4
                  },
                  "issues": [],
                  "fixedCsv": "Handle,Title,Option1 Name,Option1 Value,Variant Price,Image Src\nclassic-linen-shirt-us,Classic Linen Shirt,Size,S,29.00,https://cdn.example.com/shirt.jpg\n"
                }
              }
            }
          },
          "400": {
            "description": "Invalid CSV or JSON payload"
          },
          "413": {
            "description": "Payload exceeds 1 MB cap"
          },
          "415": {
            "description": "Unsupported media type"
          }
        }
      }
    },
    "/v1/tiktok/policy-check": {
      "post": {
        "tags": [
          "TikTok Shop"
        ],
        "summary": "Audit script or caption for TikTok Shop & 2026 AIGC compliance",
        "operationId": "checkTikTokPolicy",
        "description": "Scans video scripts, captions, or livestream outlines against US/VN TikTok Shop Content Policy, 2026 AIGC rules, and FTC affiliate disclosure requirements, returning violation score, matched spans, and auto-suggested safe copy.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "Script, caption, or product pitch text (max 20,000 chars)"
                  },
                  "usingAI": {
                    "type": "boolean",
                    "default": false
                  },
                  "affiliate": {
                    "type": "boolean",
                    "default": true
                  }
                }
              },
              "example": {
                "text": "This serum cures acne permanently! DM me on WhatsApp or click link in bio for 95% off.",
                "usingAI": true,
                "affiliate": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Compliance score (0-100), pass/fail verdict, matched violations, disclosures, and cleaned suggestion",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": true,
                  "brand": "Onyxcine Policy API",
                  "score": 15,
                  "passed": false,
                  "matches": [],
                  "reminders": [],
                  "suggestedText": "..."
                }
              }
            }
          },
          "400": {
            "description": "Missing text or malformed JSON"
          },
          "413": {
            "description": "Payload exceeds 64 KB cap"
          }
        }
      }
    },
    "/v1/tiktok/spark-ads-roi": {
      "post": {
        "tags": [
          "TikTok Shop"
        ],
        "summary": "Calculate TikTok Shop Spark Ads ROI & Creator Commission Split",
        "operationId": "calculateSparkAdsRoi",
        "description": "Models both creator affiliate net payouts (Open Collab vs. reduced Shop Ads / GMV Max commission rates + return clawbacks) and seller post-return ad economics (break-even CPA, break-even ROAS, 20% refund admin fee, and net profit).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sellingPrice": {
                    "type": "number",
                    "default": 28
                  },
                  "landedCogs": {
                    "type": "number",
                    "default": 6.8
                  },
                  "shippingPerOrder": {
                    "type": "number",
                    "default": 4.5
                  },
                  "referralFeePct": {
                    "type": "number",
                    "default": 6
                  },
                  "openCollabPct": {
                    "type": "number",
                    "default": 18
                  },
                  "shopAdsPct": {
                    "type": "number",
                    "default": 6
                  },
                  "returnRatePct": {
                    "type": "number",
                    "default": 8
                  },
                  "totalViews": {
                    "type": "number",
                    "default": 250000
                  },
                  "paidViewSharePct": {
                    "type": "number",
                    "default": 85
                  },
                  "cartCtrPct": {
                    "type": "number",
                    "default": 1.8
                  },
                  "checkoutCvrPct": {
                    "type": "number",
                    "default": 4.5
                  },
                  "cpmUsd": {
                    "type": "number",
                    "default": 8.5
                  }
                }
              },
              "example": {
                "sellingPrice": 28,
                "landedCogs": 6.8,
                "shippingPerOrder": 4.5,
                "referralFeePct": 6,
                "openCollabPct": 18,
                "shopAdsPct": 6,
                "returnRatePct": 8,
                "totalViews": 250000,
                "paidViewSharePct": 85,
                "cartCtrPct": 1.8,
                "checkoutCvrPct": 4.5,
                "cpmUsd": 8.5
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Detailed creator and brand Spark Ads unit economics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": true,
                  "brand": "Onyxcine Spark Ads ROI API",
                  "result": {
                    "price": 28,
                    "creatorNetActual": 392.41,
                    "creatorHaircutPct": 56.67,
                    "adSpendUsd": 1806.25,
                    "actualPaidRoas": 2.6685,
                    "breakEvenPaidRoas": 2.3827,
                    "brandNetProfitTotal": 158.13,
                    "brandProfitableOnAds": true
                  }
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON payload"
          },
          "413": {
            "description": "Payload exceeds 64 KB cap"
          }
        }
      }
    }
  }
}