{
  "openapi": "3.1.0",
  "info": {
    "title": "Automata Labs Agent Catalog API",
    "version": "1.0.0",
    "description": "Anonymous, revocable API keys for a read-only product catalog. This is not OAuth. Optional email ownership claims do not add permissions or provide account recovery. Keys cannot authorize contact/support/waitlist submissions, purchases, or personal-data access. Registration and claims are side-effecting: passive scanners must never POST them. JSON bodies are capped at 4096 bytes and must arrive within three seconds. Credential responses are private, no-store. See auth.md for rate limits, secret handling, and retry behavior."
  },
  "servers": [{ "url": "https://automatalabs.ca" }],
  "externalDocs": { "url": "https://automatalabs.ca/auth.md" },
  "security": [],
  "paths": {
    "/agent/auth": {
      "post": {
        "operationId": "registerAnonymousAgent",
        "summary": "Issue a 30-day catalog:read API key and a 24-hour optional claim token",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object", "additionalProperties": false,
            "required": ["type", "requested_credential_type"],
            "properties": {
              "type": { "const": "anonymous" },
              "requested_credential_type": { "const": "api_key" }
            }
          } } }
        },
        "responses": {
          "200": { "description": "Secrets returned once. The key works immediately.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Registration" } } } },
          "default": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/agent/products": {
      "get": {
        "operationId": "listAgentProducts",
        "summary": "Read public product information with catalog:read permission",
        "security": [{ "AgentKey": [] }],
        "responses": {
          "200": { "description": "Product catalog. Not all products are released.", "content": { "application/json": { "schema": {
            "type": "object", "additionalProperties": false, "required": ["products"],
            "properties": { "products": { "type": "array", "items": { "$ref": "#/components/schemas/Product" } } }
          } } } },
          "default": { "$ref": "#/components/responses/Error" }
        }
      },
      "head": {
        "operationId": "checkAgentCatalogAccess",
        "summary": "Return catalog headers without a body; counts toward rate limits",
        "security": [{ "AgentKey": [] }],
        "responses": { "200": { "description": "Authorized; no body." }, "default": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/agent/auth/claim": {
      "post": {
        "operationId": "startAgentOwnershipClaim",
        "summary": "Send one user-approved ownership verification email",
        "description": "The claim token authenticates this operation. There is no extra credential or scope grant. Five guesses per eight-digit code; expires in ten minutes or at claim-token expiry, whichever is sooner. An active code cannot be resent. Quotas persist across restarts.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object", "additionalProperties": false, "required": ["claim_token", "email", "consent"],
            "properties": {
              "claim_token": { "$ref": "#/components/schemas/ClaimToken" },
              "email": { "type": "string", "format": "email", "maxLength": 254, "description": "Trimmed and lowercased before validation and hashing." },
              "consent": { "const": true, "description": "The user explicitly authorized this verification email." }
            }
          } } }
        },
        "responses": {
          "200": { "description": "Verification email sent. Code is never returned to the caller.", "content": { "application/json": { "schema": {
            "type": "object", "additionalProperties": false, "required": ["registration_id", "status", "expires_at"],
            "properties": {
              "registration_id": { "type": "string" }, "status": { "const": "initiated" },
              "expires_at": { "type": "string", "format": "date-time" }
            }
          } } } },
          "default": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/agent/auth/claim/complete": {
      "post": {
        "operationId": "completeAgentOwnershipClaim",
        "summary": "Verify a single-use code with the claim token; preserve catalog:read only",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object", "additionalProperties": false, "required": ["claim_token", "otp"],
            "properties": { "claim_token": { "$ref": "#/components/schemas/ClaimToken" }, "otp": { "type": "string", "pattern": "^[0-9]{8}$" } }
          } } }
        },
        "responses": {
          "200": { "description": "Claim completed; discard the claim token. Original key and expiration are unchanged.", "content": { "application/json": { "schema": {
            "type": "object", "additionalProperties": false, "required": ["registration_id", "status", "scopes"],
            "properties": { "registration_id": { "type": "string" }, "status": { "const": "claimed" }, "scopes": { "$ref": "#/components/schemas/Scopes" } }
          } } } },
          "default": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/agent/auth/revoke": {
      "post": {
        "operationId": "revokeAgentKey",
        "summary": "Immediately delete the presented key, ownership record, and any pending claim",
        "description": "Send an empty JSON object with Content-Type: application/json, required for server-to-server POSTs to pass the site's existing browser-origin protections. Returns 204 for any well-formed key, including already revoked or expired keys. This is not an OAuth revocation endpoint.",
        "security": [{ "AgentKey": [] }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "additionalProperties": false, "maxProperties": 0 } } }
        },
        "responses": { "204": { "description": "Revoked or already absent; no body." }, "default": { "$ref": "#/components/responses/Error" } }
      }
    }
  },
  "components": {
    "securitySchemes": { "AgentKey": { "type": "http", "scheme": "bearer", "bearerFormat": "api_key", "description": "Use the issued credential only in the Authorization header over HTTPS. Never put secrets in URLs, cookies, or logs." } },
    "schemas": {
      "ClaimToken": { "type": "string", "pattern": "^alc_[A-Za-z0-9_-]{43}$", "description": "Secret, returned only once at registration; valid for 24 hours." },
      "Scopes": { "type": "array", "minItems": 1, "maxItems": 1, "items": { "const": "catalog:read" } },
      "Registration": {
        "type": "object", "additionalProperties": false,
        "required": ["registration_id", "registration_type", "credential_type", "credential", "credential_expires", "scopes", "claim_url", "claim_token", "claim_token_expires", "post_claim_scopes"],
        "properties": {
          "registration_id": { "type": "string" },
          "registration_type": { "const": "anonymous" },
          "credential_type": { "const": "api_key" },
          "credential": { "type": "string", "pattern": "^alk_[A-Za-z0-9_-]{43}$" },
          "credential_expires": { "type": "string", "format": "date-time" },
          "scopes": { "$ref": "#/components/schemas/Scopes" },
          "claim_url": { "const": "https://automatalabs.ca/agent/auth/claim" },
          "claim_token": { "$ref": "#/components/schemas/ClaimToken" },
          "claim_token_expires": { "type": "string", "format": "date-time" },
          "post_claim_scopes": { "$ref": "#/components/schemas/Scopes" }
        }
      },
      "Product": {
        "type": "object", "additionalProperties": false,
        "required": ["slug", "name", "status", "description", "platforms", "url"],
        "properties": {
          "slug": { "type": "string" }, "name": { "type": "string" },
          "status": { "enum": ["available", "launching-soon", "in-development"] },
          "description": { "type": "string" }, "platforms": { "type": "array", "items": { "type": "string" } },
          "url": { "type": "string", "format": "uri" }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "JSON error: 400 invalid request/OTP, 401 invalid credential/claim token, 403 untrusted Origin, 405 wrong method, 408 slow body, 409 pending claim, 413 oversized body, 415 wrong format/encoding, 429 rate limited, or 503 unavailable. Framework/proxy errors can have other formats. Responses are private, no-store. See auth.md before retrying side-effecting operations.",
        "headers": {
          "Retry-After": { "description": "Seconds to wait when rate limited.", "schema": { "type": "integer" } },
          "WWW-Authenticate": { "description": "Bearer challenge on 401.", "schema": { "type": "string" } },
          "Allow": { "description": "Allowed methods on 405.", "schema": { "type": "string" } }
        },
        "content": { "application/json": { "schema": { "type": "object", "required": ["error"], "properties": { "error": { "type": "string" } } } } }
      }
    }
  }
}
