{
  "openapi": "3.1.0",
  "info": {
    "title": "Ganglion Fabric API",
    "version": "0.2.0",
    "description": "Cloud relay to outbound-connected private Dendrite nodes. Prompts transit the relay; inference is local and has no cloud fallback."
  },
  "servers": [
    {
      "url": "https://elasticinferencefabric.airanger.dev"
    }
  ],
  "paths": {
    "/mcp": {
      "post": {
        "summary": "MCP Streamable HTTP with configured Fabric bearer token (not OAuth)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "MCP JSON-RPC response"
          },
          "202": {
            "description": "Notification accepted"
          },
          "401": {
            "description": "Invalid or absent access token"
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "summary": "Current identity and role",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "responses": {
          "200": {
            "description": "Identity, never credentials"
          }
        }
      }
    },
    "/api/tokens": {
      "get": {
        "summary": "Administrator: list token metadata (never secret values)",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "responses": {
          "200": {
            "description": "Token metadata"
          }
        }
      },
      "post": {
        "summary": "Administrator: issue token; secret returned once",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "label",
                  "role"
                ],
                "properties": {
                  "label": {
                    "type": "string"
                  },
                  "role": {
                    "enum": [
                      "viewer",
                      "agent",
                      "node",
                      "admin"
                    ]
                  },
                  "node_id": {
                    "type": "string",
                    "description": "Required for node tokens"
                  },
                  "expires_in_days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365,
                    "default": 30
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "One-time token and metadata"
          }
        }
      }
    },
    "/api/tokens/{id}": {
      "delete": {
        "summary": "Administrator: revoke token and sessions/node connections",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "Public intended-role model roster (not live availability)",
        "responses": {
          "200": {
            "description": "Static roster"
          }
        }
      }
    },
    "/v1/resources": {
      "get": {
        "summary": "Authenticated live fabric inventory",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "responses": {
          "200": {
            "description": "FabricState"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/v1/tasks": {
      "post": {
        "summary": "Submit local inference through the relay",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TaskRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted FabricJob"
          },
          "409": {
            "description": "No eligible idle node"
          }
        }
      }
    },
    "/v1/tasks/{id}": {
      "get": {
        "summary": "Read task status/result",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "FabricJob"
          },
          "404": {
            "description": "Unknown job"
          }
        }
      }
    },
    "/v1/nodes/connect": {
      "get": {
        "summary": "Dendrite outbound WebSocket connection",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "101": {
            "description": "WebSocket upgraded; send an immediate heartbeat and then every 10 seconds"
          }
        }
      }
    },
    "/api/session": {
      "post": {
        "summary": "Exchange token for strict HttpOnly session cookie",
        "responses": {
          "200": {
            "description": "Logged in"
          }
        }
      },
      "delete": {
        "summary": "Clear session cookie",
        "security": [
          {
            "bearerAuth": []
          },
          {
            "sessionCookie": []
          }
        ],
        "responses": {
          "200": {
            "description": "Logged out"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "fabric_session"
      }
    },
    "schemas": {
      "TaskRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "capability",
          "prompt"
        ],
        "properties": {
          "capability": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "prompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 65536
          },
          "prefix": {
            "type": "string",
            "maxLength": 65536
          },
          "model_id": {
            "type": "string"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 4096
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2
          },
          "allow_simulated": {
            "type": "boolean",
            "default": false
          }
        }
      }
    }
  }
}