{
  "openapi": "3.1.0",
  "info": {
    "title": "CAI Edge API (minimal subset)",
    "version": "1.0.0",
    "description": "Minimal OpenAPI 3.1 for high-frequency CAI Edge Functions. The authoritative contract — all tools, scopes, gap_id — is https://cai.com/skill.md. Machine-readable routing: https://cai.com/specs/cai-tools.manifest.json",
    "contact": {
      "url": "https://cai.com/developers"
    }
  },
  "servers": [
    {
      "url": "https://api.cai.com/functions/v1",
      "description": "Supabase Edge Functions (canonical API base)"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "CAI User API key (cai_...) or OAuth access token"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" }
        }
      },
      "IdentityResponse": {
        "type": "object",
        "description": "See skill.md § identity for full fields"
      },
      "WalletBalancesRequest": {
        "type": "object",
        "additionalProperties": true
      },
      "WalletBalancesResponse": {
        "type": "object",
        "description": "See skill.md § wallet for balance fields"
      },
      "HostedActionRequest": {
        "type": "object",
        "required": ["action_type"],
        "properties": {
          "action_type": {
            "type": "string",
            "enum": ["login", "deposit", "walletconnect", "human_verification", "website_login"]
          }
        }
      },
      "HostedActionResponse": {
        "type": "object",
        "properties": {
          "url": { "type": "string", "format": "uri" }
        }
      }
    }
  },
  "paths": {
    "/get-identity": {
      "get": {
        "operationId": "get_identity",
        "summary": "Get @cai.com identity and custodial addresses",
        "tags": ["identity"],
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Identity payload",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/IdentityResponse" }
              }
            }
          },
          "401": { "description": "Missing or invalid Bearer token" },
          "403": { "description": "Insufficient API key scope" }
        },
        "x-cai-logical-name": "get_identity",
        "x-cai-skill-md": "https://cai.com/skill.md"
      }
    },
    "/get-wallet-balances": {
      "post": {
        "operationId": "wallet_balances",
        "summary": "List custodial wallet token balances",
        "tags": ["wallet"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/WalletBalancesRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Balances",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WalletBalancesResponse" }
              }
            }
          },
          "401": { "description": "Missing or invalid Bearer token" }
        },
        "x-cai-logical-name": "wallet_balances",
        "x-cai-skill-md": "https://cai.com/skill.md"
      }
    },
    "/create-hosted-action": {
      "post": {
        "operationId": "create_login_link",
        "summary": "Mint hosted action URL (login, deposit, etc.)",
        "tags": ["identity"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/HostedActionRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Hosted action URL",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/HostedActionResponse" }
              }
            }
          }
        },
        "x-cai-logical-name": "create_login_link",
        "x-cai-skill-md": "https://cai.com/skill.md"
      }
    },
    "/check-availability": {
      "get": {
        "operationId": "check_alias",
        "summary": "Check @cai.com alias availability (public)",
        "tags": ["identity"],
        "parameters": [
          {
            "name": "alias",
            "in": "query",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "Availability result" }
        },
        "x-cai-logical-name": "check_alias",
        "x-cai-skill-md": "https://cai.com/skill.md"
      }
    },
    "/request-signup-verification": {
      "post": {
        "operationId": "request_signup_verification",
        "summary": "Start @cai.com email signup verification (public)",
        "tags": ["identity"],
        "responses": {
          "200": { "description": "Verification sent" }
        },
        "x-cai-logical-name": "request_signup_verification",
        "x-cai-skill-md": "https://cai.com/skill.md"
      }
    },
    "/wallet-activity-list": {
      "get": {
        "operationId": "wallet_activity_list",
        "summary": "Unified custodial activity feed",
        "tags": ["wallet"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "maximum": 50 } }
        ],
        "responses": {
          "200": { "description": "Activity items" },
          "401": { "description": "Missing or invalid Bearer token" }
        },
        "x-cai-logical-name": "wallet_activity_list",
        "x-cai-skill-md": "https://cai.com/skill.md"
      }
    }
  },
  "externalDocs": {
    "description": "Authoritative CAI agent skill contract",
    "url": "https://cai.com/skill.md"
  }
}
