{
  "openapi": "3.1.1",
  "info": {
    "title": "FlowPrime ff-ai",
    "description": "Multi-org LLM gateway: provider accounts, routes (priority, weighted, fallback), an OpenAI-compatible proxy with streaming, and a usage ledger.",
    "version": "2.0.3-dc046c6"
  },
  "servers": [
    {
      "url": "https://ai.fastflow.tech",
      "description": "The org comes from the API key or the X-Org-Slug header, not the host."
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bot/{slug}/chat": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/admin/databases": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/health/live": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/health/ready": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/version.json": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/providers": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "tags": [
          "FfAi"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProviderAccountRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/providers/{id}": {
      "put": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProviderAccountRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/providers/{id}/verify": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/routes": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "tags": [
          "FfAi"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RouteRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/routes/{id}": {
      "put": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RouteRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bots": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "post": {
        "tags": [
          "FfAi"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BotRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/bots/{id}": {
      "put": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BotRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/usage/summary": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "summary": "What the provider charged the org in the last `days`",
        "description": "Totals, abandoned, errors, fallbacks and the breakdown by route, model, client tag and day. `days` is 1 to 365 (default 30). `clientPrefix` (optional) computes every figure over the rows whose client tag starts with it, compared literally and case-sensitively, so `byClient` lists the tags inside it.",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": [
                "integer",
                "string"
              ],
              "format": "int32",
              "default": 30
            }
          },
          {
            "name": "clientPrefix",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/usage/records": {
      "get": {
        "tags": [
          "FfAi"
        ],
        "summary": "The org's usage ledger rows, newest first",
        "description": "`limit` 1 to 200 (default 50), `offset` for paging, `total` counts the filtered rows. `route` matches one route alias, `client` one exact client tag, `clientPrefix` every client tag that starts with it (literal, case-sensitive). When `client` and `clientPrefix` are both sent, `client` wins.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": [
                "integer",
                "string"
              ],
              "format": "int32",
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "pattern": "^-?(?:0|[1-9]\\d*)$",
              "type": [
                "integer",
                "string"
              ],
              "format": "int32",
              "default": 0
            }
          },
          {
            "name": "route",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "client",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "clientPrefix",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/tenants/provision": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/tenants/activate": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/tenants/deactivate": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/tenants/{orgSlug}": {
      "delete": {
        "tags": [
          "FfAi"
        ],
        "parameters": [
          {
            "name": "orgSlug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/admin/orgs/{slug}/api-key": {
      "post": {
        "tags": [
          "FfAi"
        ],
        "summary": "Mint (or rotate) the org's tenant API key",
        "description": "Returns a new ffai_ key for the org and invalidates the previous one. Platform provisioning key or platform_admin bearer only. The key opens every /v1/* endpoint of this org as X-Api-Key, with or without X-Org-Slug (a different X-Org-Slug is refused).",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "FfAi"
        ],
        "summary": "Revoke the org's tenant API key",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ApiKeyResponse": {
        "required": [
          "slug",
          "apiKey",
          "message"
        ],
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "apiKey": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "BotRequest": {
        "required": [
          "slug",
          "routeAlias",
          "systemPrompt",
          "enabled",
          "requestsPerMinute"
        ],
        "type": "object",
        "properties": {
          "slug": {
            "type": [
              "null",
              "string"
            ]
          },
          "routeAlias": {
            "type": [
              "null",
              "string"
            ]
          },
          "systemPrompt": {
            "type": [
              "null",
              "string"
            ]
          },
          "enabled": {
            "type": [
              "null",
              "boolean"
            ]
          },
          "requestsPerMinute": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "null",
              "integer",
              "string"
            ],
            "format": "int32"
          }
        }
      },
      "ProviderAccountRequest": {
        "required": [
          "label",
          "provider",
          "configJson",
          "enabled"
        ],
        "type": "object",
        "properties": {
          "label": {
            "type": [
              "null",
              "string"
            ]
          },
          "provider": {
            "type": [
              "null",
              "string"
            ]
          },
          "configJson": {
            "type": [
              "null",
              "string"
            ]
          },
          "enabled": {
            "type": [
              "null",
              "boolean"
            ]
          }
        }
      },
      "RouteRequest": {
        "required": [
          "alias",
          "description",
          "fallbackMode",
          "enabled",
          "targets"
        ],
        "type": "object",
        "properties": {
          "alias": {
            "type": [
              "null",
              "string"
            ]
          },
          "description": {
            "type": [
              "null",
              "string"
            ]
          },
          "fallbackMode": {
            "type": [
              "null",
              "string"
            ]
          },
          "enabled": {
            "type": [
              "null",
              "boolean"
            ]
          },
          "targets": {
            "type": [
              "null",
              "array"
            ],
            "items": {
              "$ref": "#/components/schemas/RouteTargetRequest"
            }
          }
        }
      },
      "RouteTargetRequest": {
        "required": [
          "providerAccountId",
          "model",
          "priority",
          "weight",
          "enabled"
        ],
        "type": "object",
        "properties": {
          "providerAccountId": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "null",
              "integer",
              "string"
            ],
            "format": "int32"
          },
          "model": {
            "type": [
              "null",
              "string"
            ]
          },
          "priority": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "null",
              "integer",
              "string"
            ],
            "format": "int32"
          },
          "weight": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "null",
              "integer",
              "string"
            ],
            "format": "int32"
          },
          "enabled": {
            "type": [
              "null",
              "boolean"
            ]
          }
        }
      },
      "VerifyRequest": {
        "required": [
          "model"
        ],
        "type": "object",
        "properties": {
          "model": {
            "type": [
              "null",
              "string"
            ]
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "FfAi"
    }
  ]
}