{
  "openapi": "3.1.0",
  "info": {
    "title": "finKO API",
    "version": "1.0.0",
    "description": "Estado (cada hora), licencias y series abiertas de las APIs financieras públicas de Perú y la región. Solo lectura, sin clave, CORS abierto, 60 consultas por minuto por IP. Cita siempre la fuente original (cada respuesta trae la cita). Las respuestas sobre licencias son un resumen operativo, no asesoría legal. También disponible como servidor MCP en https://finko.fyi/mcp.",
    "contact": {
      "name": "finKO",
      "email": "finko.peru@gmail.com",
      "url": "https://finko.fyi"
    }
  },
  "servers": [
    {
      "url": "https://finko.fyi"
    }
  ],
  "paths": {
    "/api/v1/estado": {
      "get": {
        "operationId": "estadoFuentes",
        "summary": "Estado actual de las fuentes",
        "description": "Si cada fuente responde, su código HTTP, si pide clave y los últimos cambios confirmados.",
        "parameters": [
          {
            "name": "ambito",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "peru",
                "pagos",
                "internacional",
                "banca_abierta"
              ]
            }
          },
          {
            "name": "solo_problemas",
            "in": "query",
            "description": "Solo fuentes monitoreadas que no están operativas.",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Estado de las fuentes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Estado"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/fuentes/{id}": {
      "get": {
        "operationId": "fuente",
        "summary": "Detalle de una fuente",
        "description": "Documentación, formatos, límites, clave, licencia completa, último chequeo y cambios recientes.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Id (bcrp, sbs, smv, mef, worldbank, imf…) o parte del nombre.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ficha de la fuente",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Fuente"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/fuentes/{id}/puedo-usar": {
      "get": {
        "operationId": "puedoUsar",
        "summary": "¿La licencia permite este uso?",
        "description": "Aplica la regla de la matriz de licencias de finKO a una fuente y un uso. Resumen operativo, no asesoría legal.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "uso",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "interno",
                "consultoria",
                "producto",
                "redistribuir"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Veredicto de licencia",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Veredicto"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/series": {
      "get": {
        "operationId": "buscarSeries",
        "summary": "Buscar series de datos abiertos",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Palabras a buscar (sin distinguir tildes). Vacío lista todas.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Series encontradas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Busqueda"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/series/{id}": {
      "get": {
        "operationId": "serie",
        "summary": "Valores de una serie",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "pe_tc_sbs_venta"
          },
          {
            "name": "desde",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}(-\\d{2}(-\\d{2})?)?$"
            }
          },
          {
            "name": "hasta",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}(-\\d{2}(-\\d{2})?)?$"
            }
          },
          {
            "name": "max",
            "in": "query",
            "description": "Máximo de observaciones (las más recientes), hasta 1000.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Valores con fuente, licencia y cita",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Serie"
                }
              }
            }
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "FuenteResumen": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "nombre": {
            "type": "string"
          },
          "ambito": {
            "type": "string"
          },
          "estado": {
            "type": "string",
            "description": "operativo, senal_debil, caido, caida_oficial, bloqueado o sin_prueba"
          },
          "http": {
            "type": [
              "integer",
              "null"
            ]
          },
          "ultimo_chequeo": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "clave": {
            "type": "string"
          },
          "disponibilidad_14d": {
            "type": [
              "object",
              "null"
            ],
            "description": "Porcentaje de nuestros chequeos de los últimos 14 días que respondieron lo esperado (no es un SLA del proveedor).",
            "properties": {
              "porcentaje": {
                "type": "number"
              },
              "chequeos": {
                "type": "integer"
              },
              "ok": {
                "type": "integer"
              }
            }
          },
          "que_probamos": {
            "type": [
              "string",
              "null"
            ],
            "description": "Qué alcanza nuestra prueba automática: la API de datos, la descripción del servicio, la API sin credenciales o solo la página del portal. Un portal en línea no implica que la API funcione."
          }
        }
      },
      "Estado": {
        "type": "object",
        "properties": {
          "generado": {
            "type": "string",
            "format": "date-time"
          },
          "resumen": {
            "type": "object",
            "properties": {
              "monitoreadas": {
                "type": "integer"
              },
              "responden": {
                "type": "integer"
              },
              "estados": {
                "type": "object",
                "additionalProperties": {
                  "type": "integer"
                }
              },
              "ultimo_chequeo": {
                "type": "string"
              }
            }
          },
          "estados_posibles": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "fuentes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FuenteResumen"
            }
          },
          "ultimos_cambios": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "ver": {
            "type": "string"
          }
        }
      },
      "Licencia": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "commercial_use": {
            "type": "string"
          },
          "redistribution": {
            "type": "string"
          },
          "attribution_required": {
            "type": "boolean"
          },
          "url": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Fuente": {
        "allOf": [
          {
            "$ref": "#/components/schemas/FuenteResumen"
          },
          {
            "type": "object",
            "properties": {
              "categoria": {
                "type": "string"
              },
              "documentacion": {
                "type": "string"
              },
              "formatos": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "limites": {
                "type": "string"
              },
              "notas": {
                "type": "string"
              },
              "licencia": {
                "$ref": "#/components/schemas/Licencia"
              },
              "cambios": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "aviso": {
                "type": "string"
              }
            }
          }
        ]
      },
      "Veredicto": {
        "type": "object",
        "properties": {
          "fuente": {
            "type": "string"
          },
          "nombre": {
            "type": "string"
          },
          "uso": {
            "type": "string"
          },
          "uso_descripcion": {
            "type": "string"
          },
          "respuesta": {
            "type": "string",
            "enum": [
              "si",
              "con_condiciones",
              "no",
              "sin_verificar"
            ]
          },
          "motivo": {
            "type": "string"
          },
          "licencia": {
            "type": "string"
          },
          "licencia_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "cita_requerida": {
            "type": "boolean"
          },
          "cita": {
            "type": "string"
          },
          "aviso": {
            "type": "string"
          }
        }
      },
      "FichaSerie": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "nombre": {
            "type": "string"
          },
          "unidad": {
            "type": "string"
          },
          "frecuencia": {
            "type": "string"
          },
          "desde": {
            "type": [
              "string",
              "null"
            ]
          },
          "hasta": {
            "type": [
              "string",
              "null"
            ]
          },
          "observaciones": {
            "type": "integer"
          },
          "nota": {
            "type": [
              "string",
              "null"
            ]
          },
          "fuente": {
            "type": "string"
          },
          "fuente_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "licencia": {
            "type": "string"
          },
          "licencia_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "cita": {
            "type": "string"
          }
        }
      },
      "Busqueda": {
        "type": "object",
        "properties": {
          "consulta": {
            "type": "string"
          },
          "series": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FichaSerie"
            }
          },
          "excluidas": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "motivo": {
                  "type": "string"
                }
              }
            }
          },
          "descargas": {
            "type": "object"
          }
        }
      },
      "Serie": {
        "allOf": [
          {
            "$ref": "#/components/schemas/FichaSerie"
          },
          {
            "type": "object",
            "properties": {
              "datos": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "fecha": {
                      "type": "string"
                    },
                    "valor": {
                      "type": "number"
                    }
                  }
                }
              },
              "recortado": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        ]
      }
    }
  }
}