{
  "openapi": "3.1.0",
  "info": {
    "title": "Send2Bucket management API",
    "version": "1.0.0",
    "description": "Manage an organization's ingestion streams, the destinations they deliver to, and usage. A destination belongs to the organization, and any number of its streams can share it. Authenticate with an account key (`s2b_acct_…`) as a Bearer token. Pro and Team workspaces only."
  },
  "servers": [
    {
      "url": "https://api.send2bucket.com/v1/manage"
    }
  ],
  "security": [
    {
      "accountKey": []
    }
  ],
  "paths": {
    "/streams": {
      "get": {
        "operationId": "listStreams",
        "summary": "List the organization's streams",
        "responses": {
          "200": {
            "description": "The streams",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StreamList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          }
        }
      },
      "post": {
        "operationId": "createStream",
        "summary": "Create a stream",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StreamCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The new stream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stream"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/400"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "409": {
            "$ref": "#/components/responses/409"
          }
        }
      }
    },
    "/streams/{stream_id}": {
      "parameters": [
        {
          "name": "stream_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getStream",
        "summary": "Get a stream",
        "responses": {
          "200": {
            "description": "The stream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stream"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          }
        }
      },
      "patch": {
        "operationId": "updateStream",
        "summary": "Rename a stream, change its destination, or set its aggregation rules or transform",
        "description": "Send any of `name`, `destination_id`, `aggregation_rules` and `transform`. A null `destination_id` detaches the stream; it accepts no data until it has a verified destination again.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StreamUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated stream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stream"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/400"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          },
          "409": {
            "$ref": "#/components/responses/409"
          }
        }
      },
      "delete": {
        "operationId": "deleteStream",
        "summary": "Delete a stream and its keys' access to it; its destination stays",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          },
          "409": {
            "$ref": "#/components/responses/409"
          }
        },
        "description": "A stream that aggregation rules send rows to cannot be deleted: `409 stream_in_use`."
      }
    },
    "/streams/{stream_id}/stats": {
      "parameters": [
        {
          "name": "stream_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getStreamStats",
        "summary": "Ingestion and delivery counters for a stream",
        "responses": {
          "200": {
            "description": "The counters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StreamStats"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          }
        }
      }
    },
    "/destinations": {
      "get": {
        "operationId": "listDestinations",
        "summary": "List the organization's destinations",
        "responses": {
          "200": {
            "description": "The destinations",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DestinationList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          }
        }
      },
      "post": {
        "operationId": "createDestination",
        "summary": "Create a destination",
        "description": "A new destination is unverified. Point streams at it with `destination_id`, then verify it.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DestinationCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Destination"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/400"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "409": {
            "$ref": "#/components/responses/409"
          }
        }
      }
    },
    "/destinations/{destination_id}": {
      "parameters": [
        {
          "name": "destination_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getDestination",
        "summary": "Get a destination (never its secret)",
        "responses": {
          "200": {
            "description": "The destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Destination"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          }
        }
      },
      "patch": {
        "operationId": "updateDestination",
        "summary": "Change a destination",
        "description": "Send any of `name`, `kind`, `config` and `secret`. Changing `kind`, `config` or `secret` makes the destination unverified until verification succeeds; leave `secret` out to keep the stored one.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DestinationUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Destination"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/400"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          },
          "409": {
            "$ref": "#/components/responses/409"
          }
        }
      },
      "delete": {
        "operationId": "deleteDestination",
        "summary": "Delete a destination no stream uses",
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          },
          "409": {
            "$ref": "#/components/responses/409"
          }
        }
      }
    },
    "/destinations/{destination_id}/verify": {
      "parameters": [
        {
          "name": "destination_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "verifyDestination",
        "summary": "Ask the ingestion node to verify the destination",
        "responses": {
          "202": {
            "description": "Verification requested; poll the destination's `status`"
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          },
          "404": {
            "$ref": "#/components/responses/404"
          }
        }
      }
    },
    "/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Ingested bytes and records per billing period and signal",
        "responses": {
          "200": {
            "description": "The usage rows",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/401"
          },
          "403": {
            "$ref": "#/components/responses/403"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "accountKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "An account key: `s2b_acct_` followed by 32 base62 characters."
      }
    },
    "responses": {
      "400": {
        "description": "`invalid_json` or `invalid_request`, such as an empty name, an unknown destination kind or another organization's `destination_id`",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "401": {
        "description": "`unauthorized`: missing, unknown or revoked account key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "403": {
        "description": "`plan_required`: the workspace is not on an active Pro or Team plan",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "404": {
        "description": "`not_found`: no such stream or destination in the organization",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "409": {
        "description": "`name_taken`: another stream or destination of the organization has this name; `destination_in_use`: streams still deliver to the destination; `stream_in_use`: aggregation rules send rows to the stream",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "invalid_json",
              "invalid_request",
              "unauthorized",
              "plan_required",
              "not_found",
              "name_taken",
              "destination_in_use",
              "stream_in_use",
              "unavailable"
            ]
          },
          "detail": {
            "type": "string",
            "description": "Why the request is invalid, when known."
          }
        }
      },
      "DestinationSummary": {
        "type": [
          "object",
          "null"
        ],
        "required": [
          "id",
          "name",
          "kind",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          }
        }
      },
      "Stream": {
        "type": "object",
        "required": [
          "id",
          "name",
          "created_at",
          "destination",
          "aggregation_rules",
          "transform",
          "flush_seconds"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "destination": {
            "$ref": "#/components/schemas/DestinationSummary"
          },
          "aggregation_rules": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/AggregationRule"
            },
            "description": "Stream aggregation rules: matching records are counted into one row per window and group, delivered with `signal` `aggregate`. Invalid rules are rejected with a `detail` saying why."
          },
          "transform": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16384,
            "description": "A VRL program run on each record kept for raw delivery, after aggregation rules read it. A program that does not compile is rejected with the compiler's message in `detail`. Null or blank for none."
          },
          "flush_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 10,
            "maximum": 60,
            "description": "How long the stream's oldest undelivered batch waits before delivery, in seconds. Null follows the plan: 10 on Free, 60 on Trial, Pro and Team."
          }
        }
      },
      "StreamList": {
        "type": "object",
        "required": [
          "streams"
        ],
        "properties": {
          "streams": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Stream"
            }
          }
        }
      },
      "Kind": {
        "type": "string",
        "enum": [
          "s3",
          "gcs",
          "s3_compatible",
          "ducklake",
          "iceberg_rest",
          "s3_tables",
          "supabase_analytics"
        ]
      },
      "Status": {
        "type": "string",
        "enum": [
          "unverified",
          "active",
          "error",
          "blocked"
        ]
      },
      "Destination": {
        "type": "object",
        "required": [
          "id",
          "name",
          "kind",
          "config",
          "status",
          "external_id",
          "stream_ids"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "config": {
            "type": "object"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "status_detail": {
            "type": [
              "string",
              "null"
            ]
          },
          "external_id": {
            "type": "string",
            "description": "The sts:ExternalId for an AWS role's trust policy."
          },
          "verified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "verify_requested_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "stream_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The organization's streams that deliver here."
          }
        }
      },
      "StreamStats": {
        "type": "object",
        "properties": {
          "ingested_batches": {
            "type": "integer"
          },
          "ingested_records": {
            "type": "integer"
          },
          "ingested_bytes": {
            "type": "integer"
          },
          "delivered_batches": {
            "type": "integer"
          },
          "delivered_records": {
            "type": "integer"
          },
          "pending_batches": {
            "type": "integer"
          },
          "pending_bytes": {
            "type": "integer"
          },
          "oldest_pending_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_delivered_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_error_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ]
          },
          "transform_dropped": {
            "type": "integer",
            "description": "Records the stream's transform dropped with `abort`."
          },
          "transform_failed": {
            "type": "integer",
            "description": "Records the stream's transform failed on; they were delivered as they arrived."
          }
        }
      },
      "Usage": {
        "type": "object",
        "required": [
          "usage"
        ],
        "properties": {
          "usage": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "period": {
                  "type": "string",
                  "enum": [
                    "free_month",
                    "trial",
                    "paid"
                  ]
                },
                "period_start": {
                  "type": "string",
                  "format": "date-time"
                },
                "signal": {
                  "type": "string",
                  "enum": [
                    "event",
                    "log",
                    "span",
                    "metric"
                  ]
                },
                "bytes": {
                  "type": "integer"
                },
                "records": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "StreamCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "destination_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The destination the stream delivers to, or null for none."
          },
          "aggregation_rules": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/AggregationRule"
            },
            "description": "Stream aggregation rules: matching records are counted into one row per window and group, delivered with `signal` `aggregate`. Invalid rules are rejected with a `detail` saying why."
          },
          "transform": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16384,
            "description": "A VRL program run on each record kept for raw delivery, after aggregation rules read it. A program that does not compile is rejected with the compiler's message in `detail`. Null or blank for none."
          },
          "flush_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 10,
            "maximum": 60,
            "description": "Sets how long the stream's oldest undelivered batch waits before delivery, 10 to 60 seconds; null follows the plan (10 on Free, 60 on Trial, Pro and Team)."
          }
        }
      },
      "StreamUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "destination_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The destination the stream delivers to, or null for none."
          },
          "aggregation_rules": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/AggregationRule"
            },
            "description": "Replaces the stream's aggregation rules; `[]` removes them."
          },
          "transform": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 16384,
            "description": "Sets the stream's VRL transform; null or a blank string removes it. A program that does not compile is rejected with the compiler's message in `detail`."
          },
          "flush_seconds": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 10,
            "maximum": 60,
            "description": "Sets how long the stream's oldest undelivered batch waits before delivery, 10 to 60 seconds; null follows the plan (10 on Free, 60 on Trial, Pro and Team)."
          }
        }
      },
      "DestinationCreate": {
        "type": "object",
        "required": [
          "name",
          "kind",
          "config"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "config": {
            "type": "object",
            "description": "Non-secret settings, as in the destination pages of the docs."
          },
          "secret": {
            "type": "object",
            "description": "Credentials. Stored in Vault and never returned."
          }
        }
      },
      "DestinationUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "kind": {
            "$ref": "#/components/schemas/Kind"
          },
          "config": {
            "type": "object",
            "description": "Non-secret settings, as in the destination pages of the docs."
          },
          "secret": {
            "type": "object",
            "description": "Credentials. Stored in Vault and never returned."
          }
        }
      },
      "DestinationList": {
        "type": "object",
        "required": [
          "destinations"
        ],
        "properties": {
          "destinations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Destination"
            }
          }
        }
      },
      "AggregationRule": {
        "type": "object",
        "required": [
          "name",
          "signal",
          "interval"
        ],
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$",
            "description": "Unique within the stream; the `rule` of each aggregate row."
          },
          "signal": {
            "type": "string",
            "enum": [
              "event",
              "log",
              "span",
              "metric"
            ]
          },
          "interval": {
            "type": "string",
            "enum": [
              "10s",
              "30s",
              "1m",
              "5m",
              "15m"
            ],
            "description": "The window length."
          },
          "match": {
            "type": "object",
            "maxProperties": 8,
            "additionalProperties": {
              "oneOf": [
                {
                  "type": [
                    "string",
                    "number",
                    "boolean"
                  ]
                },
                {
                  "type": "array",
                  "minItems": 1,
                  "maxItems": 32,
                  "items": {
                    "type": [
                      "string",
                      "number",
                      "boolean"
                    ]
                  }
                }
              ]
            },
            "description": "Fields and the values they must equal; a list matches any of its values."
          },
          "by": {
            "type": "array",
            "maxItems": 8,
            "uniqueItems": true,
            "items": {
              "type": "string"
            },
            "description": "Fields whose values group the rows."
          },
          "value": {
            "type": "string",
            "description": "The numeric field the value outputs read. Spans default to `duration_ms`, metrics to `value`."
          },
          "outputs": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string"
            },
            "description": "Any of `count` (always included), `sum`, `min`, `max`, `avg`, `last` and `quantiles(0.5, 0.99)`."
          },
          "keep_input": {
            "type": "boolean",
            "default": true,
            "description": "Whether matching records are still delivered raw. A record is dropped only when every rule matching it sets false."
          },
          "output_stream_id": {
            "type": "string",
            "format": "uuid",
            "description": "Another stream of the organization, with a destination, whose destination receives this rule's rows. Leave out to use this stream's destination."
          }
        }
      }
    }
  }
}
