{
  "openapi": "3.1.0",
  "info": {
    "title": "ClimatrixAI Risk API",
    "version": "1.0.0 (data 2026-11-09.2)",
    "description": "Climate risk scores (0-100, grade A-E) for any point on Earth. Every response lists its sources and method."
  },
  "servers": [
    {
      "url": "https://api.climatrixai.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Hazard": {
        "type": "object",
        "properties": {
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "grade": {
            "type": "string",
            "enum": [
              "A",
              "B",
              "C",
              "D",
              "E"
            ]
          },
          "level": {
            "type": "string",
            "enum": [
              "very_low",
              "low",
              "medium",
              "high",
              "very_high"
            ]
          },
          "summary": {
            "type": "string"
          },
          "metrics": {
            "type": "object"
          },
          "trend": {
            "type": [
              "object",
              "null"
            ]
          }
        }
      },
      "RiskReport": {
        "type": "object",
        "properties": {
          "location": {
            "type": "object"
          },
          "overall": {
            "type": "object"
          },
          "hazards": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/Hazard"
            }
          },
          "unavailable": {
            "type": "array"
          },
          "sources": {
            "type": "array"
          },
          "data_version": {
            "type": "string"
          },
          "method_url": {
            "type": "string"
          },
          "disclaimer": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/v1/risk": {
      "get": {
        "summary": "All hazards for one location",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "lat",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": -90,
              "maximum": 90
            },
            "example": 6.5244
          },
          {
            "name": "lon",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": -180,
              "maximum": 180
            },
            "example": 3.3792
          },
          {
            "name": "address",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 300
            },
            "description": "Used when lat/lon are absent."
          }
        ],
        "responses": {
          "200": {
            "description": "Risk report",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RiskReport"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/risk/batch": {
      "post": {
        "summary": "Score many sites in one call",
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "sites"
                ],
                "properties": {
                  "sites": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "lat",
                        "lon"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "lat": {
                          "type": "number"
                        },
                        "lon": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "sites": [
                  {
                    "id": "lagos-hq",
                    "lat": 6.5244,
                    "lon": 3.3792
                  },
                  {
                    "id": "dubai-dc",
                    "lat": 25.2048,
                    "lon": 55.2708
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch results"
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/hazards/{type}": {
      "get": {
        "summary": "One hazard in depth, with its scoring curves",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "river_flood",
                "heat",
                "drought",
                "heavy_rain",
                "wind",
                "cold",
                "wildfire",
                "air_quality"
              ]
            }
          },
          {
            "name": "lat",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": -90,
              "maximum": 90
            },
            "example": 6.5244
          },
          {
            "name": "lon",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": -180,
              "maximum": 180
            },
            "example": 3.3792
          },
          {
            "name": "address",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 300
            },
            "description": "Used when lat/lon are absent."
          }
        ],
        "responses": {
          "200": {
            "description": "Hazard detail"
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/hazards": {
      "get": {
        "summary": "List hazards, methods and sources",
        "responses": {
          "200": {
            "description": "Hazard list"
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "Usage this month",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Usage"
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/plans": {
      "get": {
        "summary": "Plans and limits",
        "responses": {
          "200": {
            "description": "Plans"
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "summary": "Create a free API key",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Key created (shown once)"
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/health": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}