{
  "openapi": "3.1.0",
  "info": {
    "title": "iTabletki Agent API",
    "version": "1.0.0",
    "description": "Read-only public reference API. Payments are not activated yet. Historical snapshots are not live medical advice."
  },
  "servers": [
    {
      "url": "https://itabletki.ru"
    }
  ],
  "paths": {
    "/api/agent/v1/search": {
      "get": {
        "operationId": "search",
        "summary": "Поиск публичных записей",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 3,
              "maxLength": 120
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Данные справочника",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/SearchData"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "После активации x402: требования оплаты",
            "headers": {
              "PAYMENT-REQUIRED": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Запись отсутствует или скрыта"
          },
          "422": {
            "description": "Ошибка параметров"
          },
          "429": {
            "description": "Лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Сервис временно недоступен"
          }
        }
      }
    },
    "/api/agent/v1/drugs/{id}": {
      "get": {
        "operationId": "drugs",
        "summary": "Историческая карточка препарата",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Данные справочника",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/DrugData"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "После активации x402: требования оплаты",
            "headers": {
              "PAYMENT-REQUIRED": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Запись отсутствует или скрыта"
          },
          "422": {
            "description": "Ошибка параметров"
          },
          "429": {
            "description": "Лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Сервис временно недоступен"
          }
        }
      }
    },
    "/api/agent/v1/records/{id}": {
      "get": {
        "operationId": "records",
        "summary": "Запись активного снимка реестра",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Данные справочника",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/RegistryData"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "После активации x402: требования оплаты",
            "headers": {
              "PAYMENT-REQUIRED": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Запись отсутствует или скрыта"
          },
          "422": {
            "description": "Ошибка параметров"
          },
          "429": {
            "description": "Лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Сервис временно недоступен"
          }
        }
      }
    },
    "/api/agent/v1/compare": {
      "get": {
        "operationId": "compare",
        "summary": "Сравнение 2–4 карточек",
        "parameters": [
          {
            "name": "drugs",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Slug через запятую, например ibuprofen,nurofen"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Данные справочника",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Envelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/CompareData"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "После активации x402: требования оплаты",
            "headers": {
              "PAYMENT-REQUIRED": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Запись отсутствует или скрыта"
          },
          "422": {
            "description": "Ошибка параметров"
          },
          "429": {
            "description": "Лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Сервис временно недоступен"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Envelope": {
        "type": "object",
        "required": [
          "api_version",
          "data",
          "payment"
        ],
        "properties": {
          "api_version": {
            "const": "1"
          },
          "data": {
            "type": "object"
          },
          "payment": {
            "type": "object",
            "properties": {
              "enabled": {
                "type": "boolean"
              },
              "page_price_usdc": {
                "type": "string"
              },
              "compare_price_usdc": {
                "type": "string"
              }
            }
          }
        }
      },
      "SearchData": {
        "type": "object",
        "required": [
          "results",
          "limit"
        ],
        "properties": {
          "limit": {
            "type": "integer",
            "maximum": 10
          },
          "results": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "object",
              "required": [
                "name",
                "url",
                "type"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "type": {
                  "type": "string"
                },
                "type_label": {
                  "type": "string"
                },
                "subtitle": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "DrugData": {
        "type": "object",
        "required": [
          "id",
          "slug",
          "name",
          "kind",
          "canonical_url",
          "source",
          "ingredients"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "medicine",
              "supplement"
            ]
          },
          "manufacturer": {
            "type": [
              "string",
              "null"
            ]
          },
          "ingredients": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "canonical_url": {
            "type": "string",
            "format": "uri"
          },
          "source": {
            "type": "object",
            "properties": {
              "kind": {
                "const": "historical_catalog"
              },
              "snapshot_date": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "record_updated_at": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "limitations": {
            "type": "string"
          }
        }
      },
      "RegistryData": {
        "type": "object",
        "required": [
          "id",
          "name",
          "canonical_url",
          "source"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "ingredients": {
            "type": [
              "string",
              "null"
            ]
          },
          "registration_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "status_kind": {
            "type": "string"
          },
          "source": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "dataset_snapshot_at": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "record_snapshot_date": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "details": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "canonical_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "CompareData": {
        "type": "object",
        "required": [
          "cards",
          "message",
          "comparison_url"
        ],
        "properties": {
          "message": {
            "type": "string"
          },
          "comparison_url": {
            "type": "string",
            "format": "uri"
          },
          "cards": {
            "type": "array",
            "minItems": 2,
            "maxItems": 4,
            "items": {
              "type": "object",
              "required": [
                "name",
                "type",
                "ingredients",
                "manufacturer",
                "url"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "type": {
                  "enum": [
                    "Лекарство",
                    "БАД"
                  ]
                },
                "ingredients": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "manufacturer": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        }
      }
    }
  }
}
