{
  "openapi": "3.1.0",
  "info": {
    "title": "consumenergie.ro Public API",
    "description": "Public JSON endpoints for SEN—MONITOR (Romania National Power System). Data from Transelectrica. Instantaneous values, refreshed roughly once a minute; history and context are derived as described on the site.",
    "version": "1.0.0",
    "termsOfService": "https://consumenergie.ro/surse/",
    "contact": {
      "name": "consumenergie.ro",
      "url": "https://consumenergie.ro/"
    }
  },
  "servers": [
    { "url": "https://consumenergie.ro" }
  ],
  "paths": {
    "/api/sen": {
      "get": {
        "summary": "Current state (live)",
        "description": "Returns the upstream 'sen-filter' payload as an array of single-key objects. Key fields (MW): CONS, PROD, SOLD (NEGATIVE = export, POSITIVE = import); sources: CARB, GAZE, APE, NUCL, EOLIAN, FOTO, BMASA. `row1_HARTASEN_DATA` is the measurement timestamp (Romanian local time).",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": {
                      "oneOf": [
                        { "type": "number" },
                        { "type": "string" }
                      ]
                    }
                  }
                },
                "examples": {
                  "example": {
                    "value": [
                      { "CONS": 6521 },
                      { "PROD": 6310 },
                      { "SOLD": 211 },
                      { "carb": 522 },
                      { "gaze": 1021 },
                      { "ape": 1789 },
                      { "nucl": 1377 },
                      { "eolian": 990 },
                      { "foto": 190 },
                      { "bmasa": 44 },
                      { "row1_HARTASEN_DATA": "12-08-2026 22:10:00" }
                    ]
                  }
                }
              }
            }
          },
          "502": {
            "description": "Upstream unavailable (stale snapshot may be served under caps)",
            "content": {
              "application/json": {
                "schema": { "type": "object", "properties": { "error": { "type": "string" } } },
                "example": { "error": "upstream" }
              }
            }
          }
        }
      }
    },
    "/api/sen/history": {
      "get": {
        "summary": "Historical series and daily rollups",
        "parameters": [
          {
            "name": "range",
            "in": "query",
            "required": false,
            "description": "Time window",
            "schema": { "type": "string", "enum": ["today", "7d", "30d"], "default": "today" }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HistoryResponse" },
                "examples": {
                  "example": {
                    "value": {
                      "range": "7d",
                      "days": [
                        { "date": "2026-08-12", "soldAvg": -412, "state": "export", "consMax": 7850, "consMin": 4160, "consAvg": 6120, "renPct": 42.1, "points": 123 }
                      ],
                      "points": [
                        { "t": "2026-08-12T21:50:00", "cons": 6512, "prod": 6731, "sold": -219, "carb": 500, "gaze": 1002, "ape": 1760, "nucl": 1400, "eolian": 1021, "foto": 140, "bmasa": 48 }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad range",
            "content": {
              "application/json": {
                "schema": { "type": "object", "properties": { "error": { "type": "string" } } },
                "example": { "error": "range" }
              }
            }
          },
          "502": {
            "description": "Upstream unavailable and no usable snapshot"
          }
        }
      }
    },
    "/api/context": {
      "get": {
        "summary": "Forecast and context (30-min refresh)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ContextResponse" }
              }
            }
          },
          "503": {
            "description": "Context temporarily unavailable",
            "content": {
              "application/json": {
                "schema": { "type": "object", "properties": { "error": { "type": "string" } } },
                "example": { "error": "context" }
              }
            }
          }
        }
      }
    },
    "/api/news": {
      "get": {
        "summary": "Latest news items (newest first)",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100 }, "required": false },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0 }, "required": false }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": { "type": "integer" },
                    "offset": { "type": "integer" },
                    "limit": { "type": "integer" },
                    "items": { "type": "array", "items": { "$ref": "#/components/schemas/NewsItem" } }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/news/alerts": {
      "get": {
        "summary": "High-signal recent items for alerts",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": { "type": "array", "items": { "$ref": "#/components/schemas/NewsItem" } }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "NewsItem": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "title": { "type": "string" },
          "source": { "type": "string" },
          "published_at": { "type": "string", "format": "date-time" },
          "summary": { "type": "string" },
          "ingested_at": { "type": "string", "format": "date-time" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "severity": { "type": "string", "enum": ["low", "normal", "high"] }
        },
        "required": ["id", "url", "title", "published_at"]
      },
      "HistoryResponse": {
        "type": "object",
        "properties": {
          "range": { "type": "string", "enum": ["today", "7d", "30d"] },
          "days": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": { "type": "string", "format": "date" },
                "soldAvg": { "type": "number" },
                "state": { "type": "string", "enum": ["import", "export"] },
                "consMax": { "type": "number" },
                "consMin": { "type": "number" },
                "consAvg": { "type": "number" },
                "renPct": { "type": ["number", "null"] },
                "points": { "type": "integer" }
              },
              "required": ["date", "soldAvg", "state", "consMax", "consMin", "consAvg", "points"]
            }
          },
          "points": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "t": { "type": "string", "description": "Bucharest wall-clock ISO-like 'YYYY-MM-DDTHH:MM:SS'" },
                "cons": { "type": "number" },
                "prod": { "type": "number" },
                "sold": { "type": "number", "description": "NEGATIVE = export" },
                "carb": { "type": "number" },
                "gaze": { "type": "number" },
                "ape": { "type": "number" },
                "nucl": { "type": "number" },
                "eolian": { "type": "number" },
                "foto": { "type": "number" },
                "bmasa": { "type": "number" }
              },
              "required": ["t", "cons", "prod", "sold"]
            }
          }
        },
        "required": ["range", "days", "points"]
      },
      "ContextResponse": {
        "type": "object",
        "properties": {
          "at": { "type": "string", "format": "date-time" },
          "weather": {
            "type": ["object", "null"],
            "properties": { "tempNow": { "type": "number" } }
          },
          "demand": {
            "type": ["object", "null"],
            "properties": {
              "series": {
                "type": "array",
                "items": { "type": "object", "properties": {
                  "t": { "type": "string" },
                  "mw": { "type": "number" },
                  "c": { "type": "number", "description": "population-weighted °C" }
                } }
              },
              "slope": { "type": "number" },
              "maePct": { "type": "number" },
              "peakToday": { "type": ["object", "null"] },
              "peakTomorrow": { "type": ["object", "null"] }
            }
          },
          "wind": {
            "type": ["object", "null"],
            "properties": {
              "now": { "type": ["object", "null"] },
              "peak24": { "type": ["object", "null"] },
              "series": { "type": "array", "items": { "type": "object" } },
              "calibrated": { "type": "boolean" }
            }
          },
          "solar": {
            "type": ["object", "null"],
            "properties": {
              "peakTomorrow": { "type": ["object", "null"] },
              "series": { "type": "array", "items": { "type": "object" } },
              "calibrated": { "type": "boolean" }
            }
          },
          "hydro": {
            "type": ["object", "null"],
            "properties": {
              "name": { "type": "string" },
              "discharge": { "type": "number" },
              "mean30": { "type": "number" },
              "pct": { "type": "number" },
              "trend": { "type": "string", "enum": ["up", "down", "flat"] }
            }
          },
          "prices": {
            "type": ["object", "null"],
            "properties": {
              "eurRon": { "type": ["number", "null"] },
              "today": { "type": "array", "items": { "type": "object" } },
              "tomorrow": { "type": "array", "items": { "type": "object" } }
            }
          },
          "official": {
            "type": ["object", "null"],
            "description": "ENTSO-E transparency platform series (when configured)"
          },
          "degraded": { "type": "array", "items": { "type": "string" } }
        }
      }
    }
  }
}

