{
  "openapi": "3.1.0",
  "info": {
    "title": "Elmarknad.se Öppet Elpris-API",
    "version": "1",
    "summary": "Svenska spotpriser på el (SE1–SE4) per kvart/timme i JSON.",
    "description": "Publikt, nyckelfritt API över svenska spotpriser. Priserna kommer från Nord Pool och anges exklusive moms, påslag, elcertifikat och nätavgifter. Svaren cachas i 15 minuter; morgondagens priser finns från cirka kl. 13. Villkor: fri användning, även kommersiellt, om Elmarknad.se anges som källa med en synlig, klickbar länk till https://elmarknad.se.",
    "termsOfService": "https://elmarknad.se/elpris-api",
    "contact": {
      "name": "Elmarknad.se",
      "email": "info@elmarknad.se",
      "url": "https://elmarknad.se/elpris-api"
    },
    "license": {
      "name": "Fri användning med attribuering",
      "url": "https://elmarknad.se/elpris-api"
    }
  },
  "externalDocs": {
    "description": "Dokumentation och villkor",
    "url": "https://elmarknad.se/elpris-api"
  },
  "servers": [
    {
      "url": "https://zstmbmllvvrgwngsjnrr.supabase.co/functions/v1/elpris-api",
      "description": "Produktion (Supabase Edge Function)"
    }
  ],
  "tags": [
    {
      "name": "Spotpriser"
    },
    {
      "name": "Metadata"
    }
  ],
  "paths": {
    "/v1/prices/{year}/{month}-{day}_{area}.json": {
      "get": {
        "operationId": "getPricesByDate",
        "tags": [
          "Spotpriser"
        ],
        "summary": "Spotpriser för ett datum och elområde",
        "parameters": [
          {
            "name": "year",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}$"
            },
            "example": "2026"
          },
          {
            "name": "month",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\d{2}$"
            },
            "example": "08"
          },
          {
            "name": "day",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\d{2}$"
            },
            "example": "04"
          },
          {
            "name": "area",
            "in": "path",
            "required": true,
            "description": "Elområde. Skiftläget spelar ingen roll (se3 fungerar också).",
            "schema": {
              "type": "string",
              "enum": [
                "SE1",
                "SE2",
                "SE3",
                "SE4"
              ]
            },
            "example": "SE3"
          }
        ],
        "responses": {
          "200": {
            "description": "Dygnets priser.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PriceDay"
                }
              }
            }
          },
          "400": {
            "description": "Ogiltigt elområde eller datum.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Inga priser för datumet ännu, eller okänd sökväg.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Serverfel.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/prices/{relativeDay}_{area}.json": {
      "get": {
        "operationId": "getPricesRelative",
        "tags": [
          "Spotpriser"
        ],
        "summary": "Spotpriser för idag, imorgon eller igår (svensk tid)",
        "parameters": [
          {
            "name": "relativeDay",
            "in": "path",
            "required": true,
            "description": "Dygn relativt dagens datum i Europe/Stockholm.",
            "schema": {
              "type": "string",
              "enum": [
                "today",
                "tomorrow",
                "yesterday"
              ]
            },
            "example": "today"
          },
          {
            "name": "area",
            "in": "path",
            "required": true,
            "description": "Elområde. Skiftläget spelar ingen roll (se3 fungerar också).",
            "schema": {
              "type": "string",
              "enum": [
                "SE1",
                "SE2",
                "SE3",
                "SE4"
              ]
            },
            "example": "SE3"
          }
        ],
        "responses": {
          "200": {
            "description": "Dygnets priser.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PriceDay"
                }
              }
            }
          },
          "400": {
            "description": "Ogiltigt elområde eller datum.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Inga priser för datumet ännu, eller okänd sökväg.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Serverfel.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/areas.json": {
      "get": {
        "operationId": "listAreas",
        "tags": [
          "Metadata"
        ],
        "summary": "Elområden SE1–SE4",
        "responses": {
          "200": {
            "description": "Elområdena.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AreaList"
                }
              }
            }
          },
          "500": {
            "description": "Serverfel.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/": {
      "get": {
        "operationId": "getApiInfo",
        "tags": [
          "Metadata"
        ],
        "summary": "API-information och lista över endpoints",
        "description": "Samma svar på /v1 och /v1/.",
        "responses": {
          "200": {
            "description": "API-information.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiInfo"
                }
              }
            }
          },
          "500": {
            "description": "Serverfel.",
            "headers": {
              "Cache-Control": {
                "$ref": "#/components/headers/CacheControl"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "headers": {
      "CacheControl": {
        "description": "Svaren får cachas i 15 minuter.",
        "schema": {
          "type": "string",
          "examples": [
            "public, max-age=900"
          ]
        }
      }
    },
    "schemas": {
      "Attribution": {
        "type": "object",
        "description": "Ingår i alla svar. Visa attribution_html eller motsvarande länk där datan visas.",
        "required": [
          "source",
          "source_url",
          "license",
          "attribution_html",
          "terms_url"
        ],
        "properties": {
          "source": {
            "type": "string",
            "const": "Elmarknad.se"
          },
          "source_url": {
            "type": "string",
            "format": "uri",
            "const": "https://elmarknad.se"
          },
          "license": {
            "type": "string"
          },
          "attribution_html": {
            "type": "string"
          },
          "terms_url": {
            "type": "string",
            "format": "uri",
            "const": "https://elmarknad.se/elpris-api"
          }
        }
      },
      "PricePoint": {
        "type": "object",
        "required": [
          "SEK_per_kWh",
          "ore_per_kWh",
          "time_start",
          "time_end"
        ],
        "properties": {
          "SEK_per_kWh": {
            "type": "number",
            "description": "Pris i SEK/kWh exkl. moms (5 decimaler)."
          },
          "ore_per_kWh": {
            "type": "number",
            "description": "Pris i öre/kWh exkl. moms (2 decimaler)."
          },
          "time_start": {
            "type": "string",
            "format": "date-time",
            "examples": [
              "2026-08-04T00:00:00+02:00"
            ]
          },
          "time_end": {
            "type": "string",
            "format": "date-time",
            "examples": [
              "2026-08-04T00:15:00+02:00"
            ]
          }
        }
      },
      "PriceDay": {
        "allOf": [
          {
            "type": "object",
            "required": [
              "date",
              "area",
              "currency",
              "unit",
              "resolution_minutes",
              "summary",
              "prices"
            ],
            "properties": {
              "date": {
                "type": "string",
                "format": "date"
              },
              "area": {
                "type": "string",
                "enum": [
                  "SE1",
                  "SE2",
                  "SE3",
                  "SE4"
                ]
              },
              "currency": {
                "type": "string",
                "const": "SEK"
              },
              "unit": {
                "type": "string",
                "const": "SEK_per_kWh"
              },
              "resolution_minutes": {
                "type": "integer",
                "description": "Upplösning i minuter: 15 (kvartspriser) eller 60 (timpriser).",
                "examples": [
                  15,
                  60
                ]
              },
              "summary": {
                "type": "object",
                "required": [
                  "avg_ore_per_kWh",
                  "min_ore_per_kWh",
                  "max_ore_per_kWh"
                ],
                "properties": {
                  "avg_ore_per_kWh": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "min_ore_per_kWh": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "max_ore_per_kWh": {
                    "type": [
                      "number",
                      "null"
                    ]
                  }
                }
              },
              "prices": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/PricePoint"
                }
              }
            }
          },
          {
            "$ref": "#/components/schemas/Attribution"
          }
        ]
      },
      "Area": {
        "type": "object",
        "required": [
          "area",
          "name",
          "url"
        ],
        "properties": {
          "area": {
            "type": "string",
            "enum": [
              "SE1",
              "SE2",
              "SE3",
              "SE4"
            ]
          },
          "name": {
            "type": "string",
            "examples": [
              "Stockholm"
            ]
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Elprissidan för elområdet."
          }
        }
      },
      "AreaList": {
        "allOf": [
          {
            "type": "object",
            "required": [
              "areas"
            ],
            "properties": {
              "areas": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Area"
                }
              }
            }
          },
          {
            "$ref": "#/components/schemas/Attribution"
          }
        ]
      },
      "ApiInfo": {
        "allOf": [
          {
            "type": "object",
            "required": [
              "name",
              "version",
              "documentation",
              "endpoints"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              },
              "documentation": {
                "type": "string",
                "format": "uri"
              },
              "endpoints": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          {
            "$ref": "#/components/schemas/Attribution"
          }
        ]
      },
      "Error": {
        "allOf": [
          {
            "type": "object",
            "required": [
              "error"
            ],
            "properties": {
              "error": {
                "type": "string"
              },
              "date": {
                "type": "string",
                "format": "date"
              },
              "area": {
                "type": "string"
              },
              "documentation": {
                "type": "string",
                "format": "uri"
              }
            }
          },
          {
            "$ref": "#/components/schemas/Attribution"
          }
        ]
      }
    }
  }
}