{
  "openapi": "3.0.3",
  "info": {
    "title": "AI Text Analysis",
    "version": "1.0.0",
    "description": "AI-powered text analysis via Gemini — sentiment analysis, summarization, named-entity recognition, zero-shot classification and keyword extraction. Single-text endpoints, JSON in/out.\n",
    "contact": {
      "name": "AI Text Analysis API Support",
      "email": "api@hiroapp.cc"
    }
  },
  "servers": [
    {
      "url": "https://api.sprytools.com/v1/ai",
      "description": "Production (SpryTools API Gateway)"
    }
  ],
  "tags": [
    {
      "name": "Analysis"
    }
  ],
  "security": [
    {
      "ApiKeyHeader": []
    },
    {
      "RapidApiProxy": []
    }
  ],
  "paths": {
    "/api/v1/sentiment": {
      "post": {
        "operationId": "analyzeSentiment",
        "summary": "Analyse sentiment of a text",
        "tags": [
          "Analysis"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "text": "I absolutely love this product, it works great!"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sentiment result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sentiment": {
                      "type": "string",
                      "description": "positive | negative | neutral"
                    },
                    "score": {
                      "type": "number"
                    },
                    "explanation": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "sentiment": "positive",
                  "score": 0.95,
                  "explanation": "Strong positive language."
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/AnalysisFailed"
          }
        }
      }
    },
    "/api/v1/summarize": {
      "post": {
        "operationId": "summarizeText",
        "summary": "Summarise a text",
        "tags": [
          "Analysis"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "Text to summarise (max ~4000 tokens)"
                  },
                  "sentences": {
                    "type": "integer",
                    "default": 3,
                    "description": "Target number of sentences"
                  }
                }
              },
              "example": {
                "text": "Long article text here ...",
                "sentences": 2
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Summary result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "summary": {
                      "type": "string"
                    },
                    "sentences": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "wordCount": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/AnalysisFailed"
          }
        }
      }
    },
    "/api/v1/entities": {
      "post": {
        "operationId": "extractEntities",
        "summary": "Extract named entities",
        "tags": [
          "Analysis"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "text": "Tim Cook announced the iPhone in Cupertino in 2007."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Entities result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "entities": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "text": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/AnalysisFailed"
          }
        }
      }
    },
    "/api/v1/classify": {
      "post": {
        "operationId": "classifyText",
        "summary": "Zero-shot classify a text into provided categories",
        "tags": [
          "Analysis"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text",
                  "categories"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "categories": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              "example": {
                "text": "My order never arrived and support won't respond.",
                "categories": [
                  "billing",
                  "shipping",
                  "praise",
                  "complaint"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Classification result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "category": {
                      "type": "string"
                    },
                    "confidence": {
                      "type": "number"
                    },
                    "scores": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/AnalysisFailed"
          }
        }
      }
    },
    "/api/v1/keywords": {
      "post": {
        "operationId": "extractKeywords",
        "summary": "Extract keywords from a text",
        "tags": [
          "Analysis"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "topN": {
                    "type": "integer",
                    "default": 10
                  }
                }
              },
              "example": {
                "text": "Machine learning models require large datasets and compute.",
                "topN": 5
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Keywords result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keywords": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/AnalysisFailed"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "RapidApiProxy": {
        "type": "apiKey",
        "in": "header",
        "name": "x-rapidapi-proxy-secret"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Missing or invalid input",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "'text' is required and must be non-empty"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "API key missing",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "API key required"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded (100 requests per minute)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Rate limit exceeded"
            }
          }
        }
      },
      "AnalysisFailed": {
        "description": "Upstream AI analysis failed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "analysis failed"
            }
          }
        }
      }
    }
  }
}