{
  "openapi": "3.0.3",
  "info": {
    "title": "SilverAnt API",
    "version": "1.0.0",
    "description": "Programmatic access to the data samples your account is entitled to. Authenticate every request to `/v1/samples*` with an API token from the dashboard (API tokens page), sent as `Authorization: Bearer sa_live_…`. Requests are rate-limited to 60 per minute per token; exceeding it returns 429. Dashboard routes under `/v1/me/*` take a Firebase ID token instead; `/v1/datasets` is public. Every error response has the shape `{ \"error\": \"<snake_code>\", \"message\": \"<text>\" }`."
  },
  "servers": [
    { "url": "https://api.silverant.ai", "description": "SilverAnt API" },
    { "url": "https://dash.silverant.ai/api", "description": "Same API proxied under the dashboard origin" }
  ],
  "paths": {
    "/v1/samples": {
      "get": {
        "summary": "List your samples",
        "description": "Returns every sample your account is entitled to, newest first, including demographics when present. Sample `id`s are opaque — pass them to the download endpoint as-is.",
        "security": [{ "apiToken": [] }],
        "responses": {
          "200": {
            "description": "The sample manifest",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "samples": { "type": "array", "items": { "$ref": "#/components/schemas/Sample" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/samples/{id}/download": {
      "get": {
        "summary": "Get a download URL for one sample",
        "description": "Returns a signed URL valid for 15 minutes. Fetch the media from that URL directly; it requires no further authentication. With `redirect=1` the response is a 302 straight to the media instead of JSON.",
        "security": [{ "apiToken": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The opaque sample id from the list endpoint",
            "schema": { "type": "string" }
          },
          {
            "name": "redirect",
            "in": "query",
            "required": false,
            "description": "Set to 1 to receive a 302 redirect to the media instead of JSON",
            "schema": { "type": "string", "enum": ["1"] }
          }
        ],
        "responses": {
          "200": {
            "description": "The signed download URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": { "type": "string", "description": "Signed media URL, valid 15 minutes" },
                    "expiresAt": { "type": "string", "format": "date-time" }
                  }
                }
              }
            }
          },
          "302": { "description": "Redirect to the signed media URL (with redirect=1)" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "description": "Unknown sample id, or your account is not entitled to it (`not_found`; the API never discloses which)" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/me/samples": {
      "get": {
        "summary": "List your samples (dashboard)",
        "description": "Same manifest as `/v1/samples`, for the signed-in dashboard user. The first 100 entries carry a short-lived `thumbnailUrl` for first-frame previews. Roles customer|contributor with isApproved; 60 requests per minute per user.",
        "security": [{ "firebase": [] }],
        "responses": {
          "200": {
            "description": "The sample manifest",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "samples": { "type": "array", "items": { "$ref": "#/components/schemas/Sample" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/me/samples/{id}/access-url": {
      "post": {
        "summary": "Mint a 15-minute signed URL for a sample (dashboard)",
        "security": [{ "firebase": [] }],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The opaque sample id from the list endpoint",
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "The signed URL",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AccessUrl" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "description": "Unknown sample id, or your account is not entitled to it (`not_found`)" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/me/tokens": {
      "get": {
        "summary": "List my API tokens (including revoked)",
        "security": [{ "firebase": [] }],
        "responses": {
          "200": {
            "description": "Newest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tokens": { "type": "array", "items": { "$ref": "#/components/schemas/ApiToken" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      },
      "post": {
        "summary": "Create an API token (max 10 active)",
        "security": [{ "firebase": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name"],
                "properties": { "name": { "type": "string", "minLength": 1, "maxLength": 64 } }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created; `token` is shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["id", "token"],
                  "properties": {
                    "id": { "type": "string", "format": "uuid" },
                    "token": { "type": "string", "description": "The plaintext secret (sa_live_…); store it now, it is never shown again" }
                  }
                }
              }
            }
          },
          "400": { "description": "`invalid_request`: name missing or longer than 64 characters", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "409": { "description": "`token_limit`: 10 active tokens already exist", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/me/tokens/{id}": {
      "delete": {
        "summary": "Revoke an API token",
        "security": [{ "firebase": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "204": { "description": "Revoked (idempotent)" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "description": "`not_found`: unknown token or not yours", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/datasets": {
      "get": {
        "summary": "Public datasets catalog",
        "description": "Published datasets ordered by `sort_order`. No authentication.",
        "security": [],
        "responses": {
          "200": {
            "description": "The catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "datasets": { "type": "array", "items": { "$ref": "#/components/schemas/Dataset" } }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiToken": {
        "type": "http",
        "scheme": "bearer",
        "description": "API token from the dashboard (starts with sa_live_). Shown once at creation; revocable at any time."
      },
      "firebase": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Firebase ID token",
        "description": "Firebase ID token of an approved dashboard user (custom claims `{ role: customer|contributor, isApproved: true }`)."
      }
    },
    "responses": {
      "Unauthorized": { "description": "Missing, invalid, or revoked API token" },
      "Forbidden": { "description": "The account is not approved or has no valid role" },
      "RateLimited": { "description": "Over the 60 requests/minute limit for this token" }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["error", "message"],
        "properties": {
          "error": { "type": "string", "example": "rate_limited" },
          "message": { "type": "string" }
        }
      },
      "Sample": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "description": "Opaque id — pass to the download endpoint" },
          "key": { "type": "string", "description": "Object key in the media catalog" },
          "name": { "type": "string", "description": "File name" },
          "size": { "type": "integer", "description": "Size in bytes" },
          "updated": { "type": "string", "format": "date-time", "nullable": true },
          "demographics": {
            "type": "object",
            "additionalProperties": { "type": "string" },
            "nullable": true,
            "description": "Demographic labels for the recording (age, gender, region, language, activity, …)"
          },
          "thumbnailUrl": {
            "type": "string",
            "nullable": true,
            "description": "Short-lived preview URL; present only in the dashboard listing (/v1/me/samples)"
          }
        }
      },
      "AccessUrl": {
        "type": "object",
        "required": ["url", "expiresAt"],
        "properties": {
          "url": { "type": "string", "description": "Signed media URL, valid 15 minutes" },
          "expiresAt": { "type": "string", "format": "date-time" }
        }
      },
      "ApiToken": {
        "type": "object",
        "required": ["id", "name", "prefix", "createdAt", "lastUsedAt", "revokedAt"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "prefix": { "type": "string", "description": "First 14 characters of the secret, for display" },
          "createdAt": { "type": "string", "format": "date-time" },
          "lastUsedAt": { "type": "string", "format": "date-time", "nullable": true },
          "revokedAt": { "type": "string", "format": "date-time", "nullable": true }
        }
      },
      "Dataset": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "modality": { "type": "string" },
          "status": { "type": "string" },
          "volume_value": { "type": "string", "nullable": true },
          "volume_unit": { "type": "string", "nullable": true },
          "languages": { "type": "array", "items": { "type": "string" } },
          "regions": { "type": "array", "items": { "type": "string" } },
          "capture_conditions": { "type": "string", "nullable": true },
          "included_items": { "type": "array", "items": { "type": "string" } },
          "sort_order": { "type": "integer" },
          "published": { "type": "boolean" }
        }
      }
    }
  }
}
