{
  "openapi": "3.1.0",
  "info": {
    "title": "vybeflow API — memory",
    "version": "0.1.0",
    "description": "Setiap endpoint memerlukan API key tenant (Pengaturan → API Key di konsol vybeflow) dan hanya berjalan jika kunci itu mencakup izin yang tercantum pada x-vybeflow-scope. Permintaan dibatasi per kunci dan per tenant; setiap jawaban membawa header RateLimit-*, dan penolakan 429 membawa Retry-After."
  },
  "servers": [
    {
      "url": "https://vybeflow.vyber.id"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Kunci berformat vf_live_… Boleh juga dikirim sebagai Authorization: Bearer."
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "contact"
    },
    {
      "name": "campaign"
    },
    {
      "name": "inbox"
    },
    {
      "name": "channel"
    },
    {
      "name": "product"
    },
    {
      "name": "billing"
    },
    {
      "name": "tenant"
    },
    {
      "name": "knowledge"
    },
    {
      "name": "memory"
    }
  ],
  "paths": {
    "/api/ai-knowledge/v1/knowledge/search": {
      "post": {
        "operationId": "memory.search",
        "summary": "Cari memori tenant tanpa menyertakan berkas. Jawabannya berupa blok konteks siap pakai untuk model.",
        "tags": [
          "memory"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "ai.config.read",
        "x-vybeflow-risk": "safe",
        "x-vybeflow-mcp-tool-only": "Di MCP, gunakan tool `search_memory`.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `ai.config.read`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "description": "Pertanyaan bahasa alami ATAU kata kunci telanjang — keduanya bekerja. Dipotong pada 4.000 karakter."
                  },
                  "limit_character": {
                    "type": "integer",
                    "description": "Maksimal karakter konteks. Default 4.000 lewat tool search_memory, rentang 500–100.000."
                  },
                  "kinds": {
                    "type": "array",
                    "description": "Dikunci ke ['memory'] oleh tool search_memory."
                  },
                  "sourceIDs": {
                    "type": "array",
                    "description": "Batasi ke memori tertentu. Maksimal 100."
                  },
                  "rerank": {
                    "type": "boolean",
                    "description": "Paksa cross-encoder reranker hidup atau mati. Default 'auto'."
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai-knowledge/v1/knowledge/memories": {
      "post": {
        "operationId": "memory.add",
        "summary": "Simpan teks sebagai memori tenant (jam operasional, kebijakan, jawaban baku). Teks dijadikan vektor dan bisa ditemukan oleh memory.search, knowledge.search, dan agen AI tenant.",
        "tags": [
          "memory"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "x-vybeflow-scope": "ai.config.manage",
        "x-vybeflow-risk": "confirm",
        "x-vybeflow-mcp-tool-only": "Di MCP ini adalah tool `add_memory`, bukan lewat write_api, karena tool itu juga bisa menunggu sampai memorinya benar-benar siap dicari.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "integer"
                    },
                    "errorCode": {
                      "type": "integer"
                    },
                    "data": {}
                  }
                }
              }
            }
          },
          "401": {
            "description": "API key tidak berlaku, dicabut, atau kedaluwarsa"
          },
          "403": {
            "description": "Kunci tidak mencakup `ai.config.manage`"
          },
          "429": {
            "description": "Batas permintaan terlampaui. Tunggu selama `Retry-After` detik lalu ulangi permintaan yang sama.",
            "headers": {
              "Retry-After": {
                "description": "Detik sampai permintaan ini bisa berhasil.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "description": "Permintaan per menit untuk kunci ini.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Sisa token pada bucket.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Detik sampai bucket penuh kembali.",
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "Isi memori. Maksimal 100.000 karakter."
                  },
                  "title": {
                    "type": "string",
                    "description": "Judul singkat, opsional. Tanpa judul, baris pertama teks dipakai sebagai nama."
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
