{
  "openapi": "3.1.0",
  "info": {
    "title": "Fichalith",
    "version": "0.1.0",
    "description": "Which version of a Spanish CAE ficha can be used for an action, with the BOE transitional periods, cited to the BOE."
  },
  "servers": [],
  "security": [
    {
      "bearer": []
    },
    {}
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "paths": {
    "/v1/tools/find_ficha": {
      "post": {
        "operationId": "find_ficha",
        "summary": "Find a CAE ficha by name or code",
        "description": "Searches the Spanish CAE fichas by code (RES060, TRA050.P) or by words from the official Spanish title, with common English words translated (heat pump, windows, insulation, boiler, LED, electric vehicle, energy poverty). Returns up to 10 fichas per page with code, Spanish title, sector, the version in force on the date (default today) and whether it is in force, withdrawn or split. Call it when you know the measure but not the code. Do not call it when you already have the code: go to ficha_in_force. It matches words, not meaning, so try the Spanish term if an English one finds nothing; it cannot tell you which ficha an action legally falls under.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "A code such as RES060, or words from the title, for example bomba de calor aerotermia or heat pump replacing a boiler."
                  },
                  "sector": {
                    "type": "string",
                    "enum": [
                      "AGR",
                      "IND",
                      "TER",
                      "RES",
                      "TRA",
                      "agr",
                      "ind",
                      "ter",
                      "res",
                      "tra"
                    ],
                    "description": "Optional sector: AGR agriculture, IND industry, TER tertiary buildings, RES residential, TRA transport."
                  },
                  "date": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Date for the version shown, YYYY-MM-DD. Defaults to today."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 25,
                    "description": "Results per page, default 10."
                  },
                  "cursor": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "next_cursor from the previous answer, to get the next page."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/ficha_in_force": {
      "post": {
        "operationId": "ficha_in_force",
        "summary": "Which ficha version can be used",
        "description": "For one CAE ficha, the date certification is requested and the date works started, returns the version in force (code, version as printed, title, the BOE act and pages that published it), every version that can still be used in a transitional period with its last day (counted under article 30.4 of Ley 39/2015, including extensions such as TRA050 V1.1 to 1 February 2027), versions whose position the BOE leaves unclear (a resolution that set no transitional period, works started on the day of the change), and caveats (a ficha added after the works started, the multiplier coefficient windows and cap). Pass version to get a verdict on a claimed version: usable, usable_if_started_before, unclear or not_usable. Status is in_force, not_yet_in_catalogue, withdrawn or split. It also shows what MITECO's compilation page lists for the code. Call it first for any question about a ficha on a date. It does not check eligibility, documentation or the savings amount, and it only knows acts already published in the BOE.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "maxLength": 16,
                    "description": "CAE ficha code from the catálogo de medidas estandarizadas, for example RES060, TER181, TRA050.P or RES090_FM (also accepted: res 060, tra050p). Sectors: AGR, IND, TER, RES, TRA."
                  },
                  "request_date": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Date the certification of savings is (or will be) requested, YYYY-MM-DD. Defaults to today."
                  },
                  "works_start": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Date execution of the works started, YYYY-MM-DD: the earlier of the start of works and the first firm commitment to buy equipment. Needed to know whether a replaced version is still usable in its transitional period."
                  },
                  "version": {
                    "type": "string",
                    "maxLength": 40,
                    "description": "A version as Fichalith lists it, for example V1.1, V2.0 or V1.1+BOE-A-2026-23657 (a text amended by instruction without a new number)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/check_actions": {
      "post": {
        "operationId": "check_actions",
        "summary": "Check the ficha versions of a dossier",
        "description": "Checks up to 50 actions at once, each { code, works_start, request_date, version }, and returns per action a verdict (usable, not_usable, unclear, error), the version to use, other usable versions, the reason and the BOE act, plus counts. Use it before submitting or verifying a CAE dossier, or to audit a list of actions exported from a spreadsheet. A claimed version that is only usable with proof of the works start date comes back unclear. For the full reasoning on one action, call ficha_in_force. It does not check eligibility, documentation or savings amounts.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "actions"
                ],
                "properties": {
                  "actions": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "description": "The actions to check.",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "code"
                      ],
                      "properties": {
                        "id": {
                          "type": "string",
                          "maxLength": 60,
                          "description": "Your own reference for the action, echoed back."
                        },
                        "code": {
                          "type": "string",
                          "maxLength": 16,
                          "description": "CAE ficha code from the catálogo de medidas estandarizadas, for example RES060, TER181, TRA050.P or RES090_FM (also accepted: res 060, tra050p). Sectors: AGR, IND, TER, RES, TRA."
                        },
                        "works_start": {
                          "type": "string",
                          "maxLength": 10,
                          "description": "Date execution of the works started, YYYY-MM-DD: the earlier of the start of works and the first firm commitment to buy equipment. Needed to know whether a replaced version is still usable in its transitional period."
                        },
                        "request_date": {
                          "type": "string",
                          "maxLength": 10,
                          "description": "Date the certification of savings is (or will be) requested, YYYY-MM-DD. Defaults to today."
                        },
                        "version": {
                          "type": "string",
                          "maxLength": 40,
                          "description": "A version as Fichalith lists it, for example V1.1, V2.0 or V1.1+BOE-A-2026-23657 (a text amended by instruction without a new number)."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/ficha_text": {
      "post": {
        "operationId": "ficha_text",
        "summary": "BOE text of a ficha section",
        "description": "Returns the Spanish BOE text of one section of a ficha version: ambito, requisitos, calculo, resultado, documentacion, anexos (ambito is Ámbito de aplicación; calculo holds the savings formula and its variables; anexos holds the declaración responsable and annex tables). Pick the version by date (in force that day, default today) or by version. Long sections are paged: up to 3,000 characters per call, continue with next_offset. Call it to quote a requirement or read the savings formula exactly. Do not call it to find which version applies (ficha_in_force). Text is reflowed from the PDF; formulas built as fractions or images may lose their layout, so check the cited BOE pages before computing. Versions published only as images in the BOE (October 2023) have no text here.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "code",
                  "section"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "maxLength": 16,
                    "description": "CAE ficha code from the catálogo de medidas estandarizadas, for example RES060, TER181, TRA050.P or RES090_FM (also accepted: res 060, tra050p). Sectors: AGR, IND, TER, RES, TRA."
                  },
                  "section": {
                    "type": "string",
                    "enum": [
                      "ambito",
                      "requisitos",
                      "calculo",
                      "resultado",
                      "documentacion",
                      "anexos"
                    ],
                    "description": "Which section to return."
                  },
                  "date": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Version in force on this date, YYYY-MM-DD. Defaults to today."
                  },
                  "version": {
                    "type": "string",
                    "maxLength": 40,
                    "description": "A version as Fichalith lists it, for example V1.1, V2.0 or V1.1+BOE-A-2026-23657 (a text amended by instruction without a new number)."
                  },
                  "offset": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 500000,
                    "description": "Character offset to start from, from next_offset."
                  },
                  "max_chars": {
                    "type": "integer",
                    "minimum": 200,
                    "maximum": 3000,
                    "description": "Characters to return, default 3,000."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/diff_versions": {
      "post": {
        "operationId": "diff_versions",
        "summary": "What changed between two ficha versions",
        "description": "Lists what changed between two versions of a ficha, paragraph by paragraph, per section (title, ámbito, requisitos, cálculo, resultado, documentación) plus annexes added or removed, each change marked added, removed or reworded with the text before and after (clipped). For a text amended by instruction (such as RES060 on 11 November 2026) it also returns the BOE's own wording of the change. Defaults to the two latest readable versions; pass from_version and to_version to choose, and section to narrow. Pages of 20 changes with next_cursor. Call it when a version switches, or to explain to a client or verifier what moved. It cannot tell you why a change was made.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "maxLength": 16,
                    "description": "CAE ficha code from the catálogo de medidas estandarizadas, for example RES060, TER181, TRA050.P or RES090_FM (also accepted: res 060, tra050p). Sectors: AGR, IND, TER, RES, TRA."
                  },
                  "from_version": {
                    "type": "string",
                    "maxLength": 40,
                    "description": "A version as Fichalith lists it, for example V1.1, V2.0 or V1.1+BOE-A-2026-23657 (a text amended by instruction without a new number)."
                  },
                  "to_version": {
                    "type": "string",
                    "maxLength": 40,
                    "description": "A version as Fichalith lists it, for example V1.1, V2.0 or V1.1+BOE-A-2026-23657 (a text amended by instruction without a new number)."
                  },
                  "section": {
                    "type": "string",
                    "enum": [
                      "ambito",
                      "requisitos",
                      "calculo",
                      "resultado",
                      "documentacion"
                    ],
                    "description": "Only this section."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 50,
                    "description": "Changes per page, default 20."
                  },
                  "cursor": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "next_cursor from the previous answer, to get the next page."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    },
    "/v1/tools/catalogue_changes": {
      "post": {
        "operationId": "catalogue_changes",
        "summary": "Dated changes to the CAE catalogue",
        "description": "Lists dated changes across the catalogue between two dates, oldest first: ficha_added, new_version, amended, withdrawn, split, transition_ends, correction, coefficient, window (a ficha enters, a new version replaces one, a text is amended by instruction, a ficha is withdrawn or split, the last day of a transitional period, a correction of errors, a correction coefficient, a multiplier coefficient window opening or closing). Defaults to 90 days back to a year ahead. Filter by code, sector and kinds; pages of 25 with next_cursor. Call it to plan requests around a transition deadline, or poll it weekly for what moved. It only knows acts already published in the BOE.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "from": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "First date, YYYY-MM-DD. Defaults to 90 days ago."
                  },
                  "to": {
                    "type": "string",
                    "maxLength": 10,
                    "description": "Last date, YYYY-MM-DD. Defaults to 455 days after from."
                  },
                  "code": {
                    "type": "string",
                    "maxLength": 16,
                    "description": "CAE ficha code from the catálogo de medidas estandarizadas, for example RES060, TER181, TRA050.P or RES090_FM (also accepted: res 060, tra050p). Sectors: AGR, IND, TER, RES, TRA."
                  },
                  "sector": {
                    "type": "string",
                    "enum": [
                      "AGR",
                      "IND",
                      "TER",
                      "RES",
                      "TRA",
                      "agr",
                      "ind",
                      "ter",
                      "res",
                      "tra"
                    ],
                    "description": "Optional sector: AGR agriculture, IND industry, TER tertiary buildings, RES residential, TRA transport."
                  },
                  "kinds": {
                    "type": [
                      "array",
                      "string"
                    ],
                    "maxItems": 9,
                    "maxLength": 200,
                    "items": {
                      "type": "string",
                      "enum": [
                        "ficha_added",
                        "new_version",
                        "amended",
                        "withdrawn",
                        "split",
                        "transition_ends",
                        "correction",
                        "coefficient",
                        "window"
                      ]
                    },
                    "description": "Only these kinds, as a list or a comma-separated string: ficha_added, new_version, amended, withdrawn, split, transition_ends, correction, coefficient, window."
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "description": "Changes per page, default 25."
                  },
                  "cursor": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "next_cursor from the previous answer, to get the next page."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "429": {
            "description": "Limit reached"
          }
        }
      }
    }
  }
}
