{
 "openapi": "3.1.0",
 "info": {
  "title": "Unays API",
  "version": "v1",
  "summary": "Public status, platform, education, auth, IoT, webhook and AI chat endpoints.",
  "description": "Key management is free. Create a key in your developer dashboard at https://unays.net/developers/dashboard/ and keep it on your server. A key works only for the endpoints its scopes allow, and paid education content also needs EDU access on the account.",
  "contact": {
   "name": "Unays LLC",
   "email": "contact@unays.net",
   "url": "https://unays.net/developers/"
  },
  "termsOfService": "https://unays.net/legal/terms/"
 },
 "servers": [
  {
   "url": "https://unays.net/api/v1"
  },
  {
   "url": "https://unays.net/ai/api/v1",
   "description": "Same API under the AI path"
  }
 ],
 "externalDocs": {
  "description": "API quickstart",
  "url": "https://unays.net/developers/api/"
 },
 "security": [
  {
   "bearerKey": []
  },
  {
   "apiKeyHeader": []
  }
 ],
 "tags": [
  {
   "name": "Status"
  },
  {
   "name": "Platforms"
  },
  {
   "name": "Education"
  },
  {
   "name": "Auth"
  },
  {
   "name": "IoT"
  },
  {
   "name": "Webhooks"
  },
  {
   "name": "AI"
  }
 ],
 "paths": {
  "/status": {
   "get": {
    "tags": [
     "Status"
    ],
    "operationId": "getStatus",
    "summary": "Service status",
    "description": "Public. No key required and not rate limited per key.",
    "security": [],
    "responses": {
     "200": {
      "description": "Current status.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "ok",
          "version",
          "status",
          "services",
          "timestamp"
         ],
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "version": {
           "type": "string",
           "const": "v1"
          },
          "status": {
           "type": "string",
           "examples": [
            "operational"
           ]
          },
          "services": {
           "type": "array",
           "items": {
            "type": "string"
           }
          },
          "timestamp": {
           "type": "string",
           "format": "date-time"
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/platforms": {
   "get": {
    "tags": [
     "Platforms"
    ],
    "operationId": "listPlatforms",
    "summary": "List Unays products",
    "description": "Any valid key.",
    "responses": {
     "200": {
      "description": "Products.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "products": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "id": {
              "type": "string"
             },
             "name": {
              "type": "string"
             },
             "status": {
              "type": "string",
              "enum": [
               "active",
               "experimental"
              ]
             },
             "url": {
              "type": "string",
              "format": "uri"
             }
            }
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/education/catalog": {
   "get": {
    "tags": [
     "Education"
    ],
    "operationId": "getEducationCatalog",
    "summary": "Curriculum catalog",
    "description": "Scope edu:read. The key's account also needs paid EDU access.",
    "x-unays-scope": "edu:read",
    "responses": {
     "200": {
      "description": "Catalog summary.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "totalUnits": {
           "type": "integer"
          },
          "unitsPerClass": {
           "type": "object"
          },
          "unitsPerSubject": {
           "type": "object"
          },
          "classes": {
           "type": "array",
           "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 12
           }
          },
          "terms": {
           "type": "array",
           "items": {
            "type": "integer"
           }
          },
          "subjects": {}
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "description": "The catalog is temporarily unavailable.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/auth/verify": {
   "post": {
    "tags": [
     "Auth"
    ],
    "operationId": "verifyUserToken",
    "summary": "Verify a Unays user session token",
    "description": "Scope auth:verify. Send the token in the x-unays-user-token header or as userToken in the body.",
    "x-unays-scope": "auth:verify",
    "parameters": [
     {
      "name": "x-unays-user-token",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "userToken": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The token is valid.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "user": {
           "type": "object",
           "description": "Public profile fields of the account."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing or invalid API key, or the user token is invalid or expired.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/iot/authorize": {
   "post": {
    "tags": [
     "IoT"
    ],
    "operationId": "authorizeIotKey",
    "summary": "Authorize an IoT or UnaysNET client",
    "description": "Scope iot:monitor. Limited to 600 requests per minute per key.",
    "x-unays-scope": "iot:monitor",
    "responses": {
     "200": {
      "description": "The key is authorized.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "authorized": {
           "type": "boolean"
          },
          "keyId": {
           "type": "string"
          },
          "accountId": {
           "type": "string"
          },
          "scopes": {
           "type": "array",
           "items": {
            "type": "string"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/webhooks": {
   "get": {
    "tags": [
     "Webhooks"
    ],
    "operationId": "listWebhooks",
    "summary": "List your webhooks",
    "x-unays-scope": "webhooks:write",
    "responses": {
     "200": {
      "description": "Active webhooks.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "webhooks": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Webhook"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Webhooks"
    ],
    "operationId": "createWebhook",
    "summary": "Register a webhook",
    "description": "Public HTTPS URLs only, up to five per account.",
    "x-unays-scope": "webhooks:write",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "url",
         "events"
        ],
        "properties": {
         "url": {
          "type": "string",
          "format": "uri",
          "description": "Public https:// URL."
         },
         "events": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "items": {
           "$ref": "#/components/schemas/WebhookEvent"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "webhook": {
           "$ref": "#/components/schemas/Webhook"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Invalid URL or no supported event.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "The account already has five webhooks.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Webhooks"
    ],
    "operationId": "deleteWebhook",
    "summary": "Revoke a webhook",
    "x-unays-scope": "webhooks:write",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "id"
        ],
        "properties": {
         "id": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Revoked.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "Webhook not found.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/ai/chat": {
   "post": {
    "tags": [
     "AI"
    ],
    "operationId": "createChat",
    "summary": "Ask Unays AI",
    "description": "Scope ai:read.",
    "x-unays-scope": "ai:read",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "prompt"
        ],
        "properties": {
         "prompt": {
          "type": "string",
          "maxLength": 12000
         },
         "mode": {
          "type": "string",
          "enum": [
           "general",
           "educational",
           "research",
           "coder",
           "business"
          ],
          "default": "general"
         }
        }
       },
       "example": {
        "prompt": "Explain photosynthesis in two sentences.",
        "mode": "educational"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The answer.",
      "headers": {
       "x-ratelimit-limit": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests allowed per minute for this key."
       },
       "x-ratelimit-remaining": {
        "schema": {
         "type": "integer"
        },
        "description": "Requests left in the current minute."
       },
       "x-ratelimit-reset": {
        "schema": {
         "type": "string",
         "format": "date-time"
        },
        "description": "When the current window resets."
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "answer": {
           "type": "string"
          },
          "profile": {
           "type": "string"
          },
          "usage": {
           "type": "object",
           "properties": {
            "rateLimitRemaining": {
             "type": "integer"
            }
           }
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Missing prompt, or the prompt was blocked by safety rules.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "description": "Temporarily unavailable. Retry with backoff.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Error"
          },
          {
           "type": "object",
           "properties": {
            "retryable": {
             "type": "boolean"
            }
           }
          }
         ]
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearerKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "Authorization: Bearer uak_live_…"
   },
   "apiKeyHeader": {
    "type": "apiKey",
    "in": "header",
    "name": "X-API-Key"
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "ok",
     "error"
    ],
    "properties": {
     "ok": {
      "type": "boolean",
      "const": false
     },
     "error": {
      "type": "string"
     }
    }
   },
   "WebhookEvent": {
    "type": "string",
    "enum": [
     "ai.response.completed",
     "education.progress.updated",
     "iot.alert.created"
    ]
   },
   "Webhook": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "format": "uri"
     },
     "events": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/WebhookEvent"
      }
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     }
    }
   }
  },
  "responses": {
   "Unauthorized": {
    "description": "A valid Unays API key is required.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "Forbidden": {
    "description": "The key does not have the required scope.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   },
   "RateLimited": {
    "description": "Rate limit exceeded. Retry after x-ratelimit-reset.",
    "headers": {
     "x-ratelimit-limit": {
      "schema": {
       "type": "integer"
      },
      "description": "Requests allowed per minute for this key."
     },
     "x-ratelimit-remaining": {
      "schema": {
       "type": "integer"
      },
      "description": "Requests left in the current minute."
     },
     "x-ratelimit-reset": {
      "schema": {
       "type": "string",
       "format": "date-time"
      },
      "description": "When the current window resets."
     }
    },
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  }
 }
}