{
  "openapi": "3.1.0",
  "info": {
    "title": "Axon Networks REST API",
    "version": "1.0.0",
    "description": "Programmatic access to Axon Fabric routes, Gateway rules, Observe metrics/logs/traces, webhooks, system status, and edge regions."
  },
  "servers": [
    {
      "url": "https://api.axon.network/v1",
      "description": "Production API v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    { "name": "Routes", "description": "Edge traffic routing and origin management" },
    { "name": "Gateway", "description": "Edge authentication, rate limiting, and request transformation rules" },
    { "name": "Observe", "description": "Metrics, logs, and distributed traces" },
    { "name": "Webhooks", "description": "Real-time signed event notifications" },
    { "name": "System", "description": "Public operational status and available edge regions" }
  ],
  "paths": {
    "/routes": {
      "get": {
        "operationId": "listRoutes",
        "tags": ["Routes"],
        "summary": "List all routes",
        "description": "Returns a paginated list of all routes in the current project, ordered by creation date descending.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Number of results per page (default 20, max 100).",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Pagination cursor from previous response.",
            "schema": { "type": "string" }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter routes by deployment status.",
            "schema": { "type": "string", "enum": ["active", "inactive", "deploying"] }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of routes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "meta"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Route" } },
                    "meta": { "$ref": "#/components/schemas/PaginationMeta" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createRoute",
        "tags": ["Routes"],
        "summary": "Create a route",
        "description": "Creates a new route and begins deploying it to all PoPs.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/RouteInput" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Route created and deploying.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "$ref": "#/components/schemas/Route" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "409": { "$ref": "#/components/responses/Conflict" }
        }
      }
    },
    "/routes/{route_id}": {
      "parameters": [
        {
          "name": "route_id",
          "in": "path",
          "required": true,
          "description": "Unique identifier of the route (e.g. route_k8xm2n9p).",
          "schema": { "type": "string" }
        }
      ],
      "get": {
        "operationId": "getRoute",
        "tags": ["Routes"],
        "summary": "Get a route",
        "description": "Returns the full configuration and current status of a single route.",
        "responses": {
          "200": {
            "description": "Route details.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "$ref": "#/components/schemas/Route" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      },
      "put": {
        "operationId": "updateRoute",
        "tags": ["Routes"],
        "summary": "Update a route",
        "description": "Replaces the entire route configuration and triggers a zero-downtime redeployment.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/RouteInput" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated route.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "$ref": "#/components/schemas/Route" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      },
      "delete": {
        "operationId": "deleteRoute",
        "tags": ["Routes"],
        "summary": "Delete a route",
        "description": "Permanently deletes a route and removes it from all PoPs.",
        "responses": {
          "204": { "description": "Route deleted." },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/gateway/rules": {
      "get": {
        "operationId": "listGatewayRules",
        "tags": ["Gateway"],
        "summary": "List gateway rules",
        "description": "Returns all gateway rules associated with the current project, ordered by priority.",
        "responses": {
          "200": {
            "description": "List of gateway rules.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/GatewayRule" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "operationId": "createGatewayRule",
        "tags": ["Gateway"],
        "summary": "Create a gateway rule",
        "description": "Adds a new rule to the gateway evaluated in ascending priority order.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/GatewayRuleInput" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Gateway rule created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "$ref": "#/components/schemas/GatewayRule" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/gateway/rules/{rule_id}": {
      "parameters": [
        {
          "name": "rule_id",
          "in": "path",
          "required": true,
          "description": "Unique identifier of the gateway rule.",
          "schema": { "type": "string" }
        }
      ],
      "put": {
        "operationId": "updateGatewayRule",
        "tags": ["Gateway"],
        "summary": "Update a gateway rule",
        "description": "Replaces an existing gateway rule configuration.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/GatewayRuleInput" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Gateway rule updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "$ref": "#/components/schemas/GatewayRule" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      },
      "delete": {
        "operationId": "deleteGatewayRule",
        "tags": ["Gateway"],
        "summary": "Delete a gateway rule",
        "description": "Permanently deletes a gateway rule.",
        "responses": {
          "204": { "description": "Gateway rule deleted." },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/metrics/query": {
      "get": {
        "operationId": "queryMetrics",
        "tags": ["Observe"],
        "summary": "Instant metric query",
        "description": "Evaluates a PromQL-compatible metric query at a single point in time.",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": true,
            "description": "PromQL-compatible expression.",
            "schema": { "type": "string" }
          },
          {
            "name": "time",
            "in": "query",
            "description": "Unix timestamp evaluation time (default: now).",
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": {
            "description": "Metric query result.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/MetricQueryResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/metrics/query_range": {
      "get": {
        "operationId": "queryMetricsRange",
        "tags": ["Observe"],
        "summary": "Range metric query",
        "description": "Evaluates a PromQL-compatible metric query over a time range.",
        "parameters": [
          { "name": "query", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "start", "in": "query", "required": true, "schema": { "type": "integer" } },
          { "name": "end", "in": "query", "required": true, "schema": { "type": "integer" } },
          { "name": "step", "in": "query", "required": true, "schema": { "type": "string", "example": "60s" } }
        ],
        "responses": {
          "200": {
            "description": "Range metric query result.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/MetricQueryResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/logs": {
      "get": {
        "operationId": "queryLogs",
        "tags": ["Observe"],
        "summary": "Query logs",
        "description": "Full-text and structured search across all edge node logs using LogQL-compatible expressions.",
        "parameters": [
          { "name": "query", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "start", "in": "query", "required": true, "schema": { "type": "integer" } },
          { "name": "end", "in": "query", "required": true, "schema": { "type": "integer" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 5000, "default": 100 } },
          { "name": "direction", "in": "query", "schema": { "type": "string", "enum": ["forward", "backward"], "default": "backward" } }
        ],
        "responses": {
          "200": {
            "description": "Matching log entries.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/LogEntry" } }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/traces/{trace_id}": {
      "parameters": [
        {
          "name": "trace_id",
          "in": "path",
          "required": true,
          "description": "Distributed trace identifier.",
          "schema": { "type": "string" }
        }
      ],
      "get": {
        "operationId": "getTrace",
        "tags": ["Observe"],
        "summary": "Get a distributed trace",
        "description": "Returns the complete span tree for a given trace ID.",
        "responses": {
          "200": {
            "description": "Trace details and spans.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Trace" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/webhooks": {
      "get": {
        "operationId": "listWebhooks",
        "tags": ["Webhooks"],
        "summary": "List webhooks",
        "description": "Returns all configured webhook endpoints for the current project.",
        "responses": {
          "200": {
            "description": "List of webhooks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Webhook" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "operationId": "createWebhook",
        "tags": ["Webhooks"],
        "summary": "Create a webhook",
        "description": "Registers a webhook endpoint to receive signed POST event notifications.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/WebhookInput" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "$ref": "#/components/schemas/Webhook" }
                  }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/status": {
      "get": {
        "operationId": "getSystemStatus",
        "tags": ["System"],
        "summary": "System status",
        "description": "Returns current operational status of all platform components. No authentication required.",
        "security": [],
        "responses": {
          "200": {
            "description": "Operational status snapshot.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/SystemStatus" }
              }
            }
          }
        }
      }
    },
    "/regions": {
      "get": {
        "operationId": "listRegions",
        "tags": ["System"],
        "summary": "List regions",
        "description": "Returns all available edge regions with their status and latency measurements. No authentication required.",
        "security": [],
        "responses": {
          "200": {
            "description": "Available edge regions.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Region" } }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Axon API Token",
        "description": "Project-scoped API token with prefix axn_live_, axn_test_, or axn_ro_."
      }
    },
    "responses": {
      "InvalidRequest": {
        "description": "Missing or invalid request parameters.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      },
      "Unauthorized": {
        "description": "Missing or invalid Bearer token.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      },
      "NotFound": {
        "description": "Resource not found.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      },
      "Conflict": {
        "description": "Resource already exists.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      },
      "RateLimited": {
        "description": "Rate limit exceeded. Check Retry-After header.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } }
      }
    },
    "schemas": {
      "PaginationMeta": {
        "type": "object",
        "properties": {
          "count": { "type": "integer" },
          "total": { "type": "integer" },
          "hasMore": { "type": "boolean" },
          "nextCursor": { "type": ["string", "null"] },
          "prevCursor": { "type": ["string", "null"] }
        }
      },
      "Origin": {
        "type": "object",
        "required": ["id", "address", "region"],
        "properties": {
          "id": { "type": "string" },
          "address": { "type": "string" },
          "region": { "type": "string" },
          "weight": { "type": "integer", "minimum": 0, "maximum": 100 }
        }
      },
      "RouteInput": {
        "type": "object",
        "required": ["name", "routing", "origins"],
        "properties": {
          "name": { "type": "string" },
          "routing": { "type": "string", "enum": ["latency", "weighted", "geo", "failover"] },
          "origins": { "type": "array", "minItems": 1, "maxItems": 20, "items": { "$ref": "#/components/schemas/Origin" } },
          "healthCheck": {
            "type": "object",
            "properties": {
              "path": { "type": "string", "default": "/" },
              "interval": { "type": "integer", "default": 30 },
              "threshold": { "type": "integer", "default": 3 }
            }
          },
          "tls": {
            "type": "object",
            "properties": {
              "mode": { "type": "string", "enum": ["mutual", "strict"], "default": "mutual" },
              "minVersion": { "type": "string", "default": "TLSv1.3" }
            }
          },
          "tags": { "type": "object", "additionalProperties": { "type": "string" } }
        }
      },
      "Route": {
        "type": "object",
        "required": ["id", "name", "endpoint", "routing", "status"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "endpoint": { "type": "string" },
          "routing": { "type": "string", "enum": ["latency", "weighted", "geo", "failover"] },
          "status": { "type": "string", "enum": ["active", "inactive", "deploying"] },
          "origins": { "type": "array", "items": { "$ref": "#/components/schemas/Origin" } },
          "deploymentId": { "type": "string" },
          "createdAt": { "type": "string", "format": "date-time" },
          "updatedAt": { "type": "string", "format": "date-time" }
        }
      },
      "GatewayRuleInput": {
        "type": "object",
        "required": ["name", "path", "priority"],
        "properties": {
          "name": { "type": "string" },
          "path": { "type": "string" },
          "priority": { "type": "integer", "minimum": 1 },
          "auth": {
            "type": "object",
            "properties": {
              "type": { "type": "string", "enum": ["jwt", "oauth2", "api_key", "hmac", "none"] },
              "issuer": { "type": "string" },
              "audience": { "type": "string" }
            }
          },
          "rateLimit": {
            "type": "object",
            "properties": {
              "requests": { "type": "integer" },
              "window": { "type": "string" },
              "keyBy": { "type": "string" }
            }
          }
        }
      },
      "GatewayRule": {
        "allOf": [
          {
            "type": "object",
            "required": ["id"],
            "properties": { "id": { "type": "string" } }
          },
          { "$ref": "#/components/schemas/GatewayRuleInput" }
        ]
      },
      "MetricQueryResponse": {
        "type": "object",
        "properties": {
          "status": { "type": "string" },
          "data": {
            "type": "object",
            "properties": {
              "resultType": { "type": "string" },
              "result": { "type": "array", "items": { "type": "object" } }
            }
          }
        }
      },
      "LogEntry": {
        "type": "object",
        "properties": {
          "timestamp": { "type": "string", "format": "date-time" },
          "region": { "type": "string" },
          "route": { "type": "string" },
          "level": { "type": "string" },
          "message": { "type": "string" },
          "traceId": { "type": "string" }
        }
      },
      "Trace": {
        "type": "object",
        "properties": {
          "traceId": { "type": "string" },
          "spans": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "spanId": { "type": "string" },
                "parentSpanId": { "type": ["string", "null"] },
                "operation": { "type": "string" },
                "durationMs": { "type": "number" },
                "region": { "type": "string" }
              }
            }
          }
        }
      },
      "WebhookInput": {
        "type": "object",
        "required": ["url", "events", "secret"],
        "properties": {
          "url": { "type": "string", "format": "uri" },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "route.deployed",
                "route.failed",
                "route.deleted",
                "origin.unhealthy",
                "origin.recovered",
                "gateway.rule.created",
                "slo.breach",
                "alert.fired",
                "alert.resolved"
              ]
            }
          },
          "secret": { "type": "string" }
        }
      },
      "Webhook": {
        "type": "object",
        "required": ["id", "url", "events"],
        "properties": {
          "id": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "events": { "type": "array", "items": { "type": "string" } },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      },
      "SystemStatus": {
        "type": "object",
        "required": ["status", "updatedAt", "components"],
        "properties": {
          "status": { "type": "string", "enum": ["operational", "degraded", "partial_outage", "major_outage", "maintenance"] },
          "updatedAt": { "type": "string", "format": "date-time" },
          "components": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string" },
                "status": { "type": "string" },
                "uptime30d": { "type": "number" }
              }
            }
          }
        }
      },
      "Region": {
        "type": "object",
        "required": ["id", "name", "status"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "status": { "type": "string" },
          "latencyMs": { "type": "number" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message", "status", "requestId"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "status": { "type": "integer" },
              "requestId": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
