{
  "openapi": "3.1.0",
  "info": {
    "title": "Mailagents Test API — foundation",
    "version": "0.3.0",
    "description": "Test identities, scoped API key lifecycle, inbox metadata, drafts, policies, messages and threads persist in Supabase. Email transport and mandatory provider screening are not established by database readiness. SES/DNS, payments, AI, external event delivery and upload/download are unavailable. The console and A2A demo use demonstration data. Read /api-foundation.md."
  },
  "servers": [
    {
      "url": "/",
      "description": "This deployment; Test only"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "paths": {
    "/v1/capabilities": {
      "get": {
        "operationId": "getCapabilities",
        "summary": "Discover implementation and current database availability via read-only probes",
        "responses": {
          "200": {
            "description": "Capabilities",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "api_version": {
                          "type": "string"
                        },
                        "environment": {
                          "type": "string",
                          "const": "test"
                        },
                        "release_stage": {
                          "type": "string",
                          "const": "foundation"
                        },
                        "database_configured": {
                          "type": "boolean"
                        },
                        "api_enabled": {
                          "type": "boolean",
                          "description": "False when the deployment blocks all agent operations before database access. Billing is not implemented; the public Test deployment keeps this false."
                        },
                        "registration_enabled": {
                          "type": "boolean"
                        },
                        "readiness_url": {
                          "type": "string"
                        },
                        "openapi_url": {
                          "type": "string"
                        },
                        "implemented": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "unavailable": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "limits": {
                          "type": "object",
                          "properties": {
                            "request_body_bytes": {
                              "type": "integer",
                              "const": 8192
                            },
                            "registration_recovery_hours": {
                              "type": "integer",
                              "const": 24
                            },
                            "key_recovery_hours": {
                              "type": "integer",
                              "const": 24
                            },
                            "api_key_lifetime_days": {
                              "type": "integer",
                              "const": 30
                            },
                            "active_api_keys_per_agent": {
                              "type": "integer",
                              "const": 20
                            },
                            "max_page_size": {
                              "type": "integer",
                              "const": 100
                            },
                            "mail_request_body_bytes": {
                              "type": "integer",
                              "const": 1048576
                            }
                          },
                          "required": [
                            "request_body_bytes",
                            "registration_recovery_hours",
                            "key_recovery_hours",
                            "api_key_lifetime_days",
                            "active_api_keys_per_agent",
                            "max_page_size",
                            "mail_request_body_bytes"
                          ],
                          "additionalProperties": false
                        },
                        "plan_catalog": {
                          "type": "object"
                        },
                        "database_ready": {
                          "type": "boolean"
                        },
                        "readiness": {
                          "type": "object",
                          "properties": {
                            "foundation": {
                              "type": "boolean"
                            },
                            "keys": {
                              "type": "boolean"
                            },
                            "mail": {
                              "type": "boolean"
                            }
                          },
                          "required": [
                            "foundation",
                            "keys",
                            "mail"
                          ],
                          "additionalProperties": false
                        },
                        "available": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Implemented features whose database probes succeeded and whose operator switch is enabled."
                        },
                        "api_key_scopes": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "identity:read",
                              "inboxes:read",
                              "inboxes:write",
                              "keys:revoke",
                              "keys:manage",
                              "messages:read",
                              "messages:send",
                              "drafts:write",
                              "drafts:approve",
                              "policies:read",
                              "policies:write"
                            ]
                          },
                          "description": "The catalog confirmed by the key database migration; empty when unavailable."
                        }
                      },
                      "required": [
                        "api_version",
                        "environment",
                        "release_stage",
                        "database_configured",
                        "registration_enabled",
                        "readiness_url",
                        "openapi_url",
                        "implemented",
                        "unavailable",
                        "limits",
                        "plan_catalog",
                        "database_ready",
                        "readiness",
                        "available",
                        "api_key_scopes"
                      ]
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": []
      },
      "head": {
        "operationId": "getCapabilitiesHead",
        "summary": "Headers only: Discover implementation and current database availability via read-only probes",
        "responses": {
          "200": {
            "description": "Capabilities",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        },
        "security": []
      }
    },
    "/v1/health": {
      "get": {
        "operationId": "getReadiness",
        "summary": "Check the database RPC and migration version, not email or payment readiness",
        "responses": {
          "200": {
            "description": "Database reachable",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "const": "ready"
                        },
                        "environment": {
                          "type": "string",
                          "const": "test"
                        },
                        "scope": {
                          "type": "string",
                          "const": "database_only"
                        },
                        "schema_versions": {
                          "type": "object",
                          "properties": {
                            "foundation": {
                              "type": "string",
                              "const": "202610130001"
                            },
                            "keys": {
                              "type": "string",
                              "const": "202610130003"
                            },
                            "mail": {
                              "type": "string",
                              "const": "202610130004"
                            }
                          },
                          "required": [
                            "foundation",
                            "keys",
                            "mail"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "required": [
                        "status",
                        "environment",
                        "scope",
                        "schema_versions"
                      ]
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": [],
        "description": "Foundation 001, keys 003 and mail core 004 probes must match. Errors identify the unavailable or incompatible migration. Capabilities still reports each independently. This does not probe provider workers or establish delivery readiness."
      },
      "head": {
        "operationId": "getReadinessHead",
        "summary": "Headers only: Check the database RPC and migration version, not email or payment readiness",
        "responses": {
          "200": {
            "description": "Database reachable",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        },
        "security": [],
        "description": "Foundation 001, keys 003 and mail core 004 probes must match. Errors identify the unavailable or incompatible migration. Capabilities still reports each independently. This does not probe provider workers or establish delivery readiness."
      }
    },
    "/v1/agents/register": {
      "post": {
        "operationId": "registerAgent",
        "summary": "Create an organization, workspace, agent and first provisioning inbox",
        "responses": {
          "200": {
            "description": "Recovered original registration using the bootstrap proof",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Registration"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "201": {
            "description": "Created; credential returned",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Registration"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "security": [
          {
            "Bootstrap": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterInput"
              }
            }
          }
        },
        "description": "Generate 32 cryptographically random bytes as 64 hex characters and persist in a secret store before sending Authorization: Bootstrap <secret>. Persist the payload and Idempotency-Key too. Retry the identical request for up to 24 hours. The idempotency key alone never recovers credentials. Revocation, expiry and narrowed access prevent recovery. New keys expire after 30 days; bootstrap rotation renews that lifetime. New registrations receive keys:manage. Migration 003 upgrades only proven original, active, unrestricted registration keys with intact original grants. Initial credentials expire after 30 days; bootstrap rotation renews expiry to 30 days; delegated rotation preserves absolute expiry. Migration 004 extends scopes for NEW signups only with messages:read/messages:send/drafts:write/policies:read/policies:write. Existing keys do not gain mail scopes."
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "getIdentity",
        "summary": "Read the current scoped identity (identity:read)",
        "responses": {
          "200": {
            "description": "Current identity; no secret",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Identity"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "operationId": "getIdentityHead",
        "summary": "Headers only: Read the current scoped identity (identity:read)",
        "responses": {
          "200": {
            "description": "Current identity; no secret",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes": {
      "get": {
        "operationId": "listInboxes",
        "summary": "List accessible inbox metadata (inboxes:read)",
        "responses": {
          "200": {
            "description": "Page of accessible inboxes",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/InboxPage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ]
      },
      "post": {
        "operationId": "createInbox",
        "summary": "Reserve an inbox under the organization plan (inboxes:write)",
        "responses": {
          "201": {
            "description": "Created or original idempotent result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Inbox"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InboxInput"
              }
            }
          }
        },
        "description": "Requires a workspace-scoped credential. Inbox-scoped keys cannot expand their grant. Capacity is aggregated across workspaces and includes provisioning inboxes; archived inboxes free capacity while their addresses remain reserved. Duplicate results include Idempotency-Replayed: true; authorization is checked again."
      },
      "head": {
        "operationId": "listInboxesHead",
        "summary": "Headers only: List accessible inbox metadata (inboxes:read)",
        "responses": {
          "200": {
            "description": "Page of accessible inboxes",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ]
      }
    },
    "/v1/inboxes/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getInbox",
        "summary": "Read accessible inbox metadata (inboxes:read)",
        "responses": {
          "200": {
            "description": "Inbox metadata",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Inbox"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "operationId": "getInboxHead",
        "summary": "Headers only: Read accessible inbox metadata (inboxes:read)",
        "responses": {
          "200": {
            "description": "Inbox metadata",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{id}/archive": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "archiveInbox",
        "summary": "Archive an accessible inbox (inboxes:write)",
        "responses": {
          "200": {
            "description": "Archived; address and quota slot remain reserved",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Inbox"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "description": "Archival does not delete data, reclaim addresses, or free capacity. Use GET for the current state after an idempotent replay."
      }
    },
    "/v1/api-keys/current": {
      "delete": {
        "operationId": "revokeCurrentKey",
        "summary": "Revoke this credential immediately (keys:revoke)",
        "responses": {
          "200": {
            "description": "Credential revoked",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "revoked": {
                          "type": "boolean",
                          "const": true
                        }
                      },
                      "required": [
                        "id",
                        "revoked"
                      ]
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "The next use, including a retry of this DELETE, returns 401. Any unconfirmed replacement is also revoked. Bootstrap cannot restore revoked access. Revoking an issuer does not revoke already-issued independent delegates; manage those by ID."
      },
      "get": {
        "operationId": "getCurrentApiKey",
        "summary": "Read this active credential metadata (any authenticated key)",
        "responses": {
          "200": {
            "description": "Read this active credential metadata (any authenticated key)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ApiKey"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "operationId": "getCurrentApiKeyHead",
        "summary": "Headers only: Read this active credential metadata (any authenticated key)",
        "responses": {
          "200": {
            "description": "Read this active credential metadata (any authenticated key)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/api-keys": {
      "get": {
        "operationId": "listApiKeys",
        "summary": "List metadata within this agent and credential grant (keys:manage)",
        "responses": {
          "200": {
            "description": "List metadata within this agent and credential grant (keys:manage)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/KeyPage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ],
        "description": "Only same-agent keys with scopes, inbox access and expiry covered by the caller are visible. Includes expired/revoked metadata, never secrets or hashes. Cursors outside this grant are rejected."
      },
      "post": {
        "operationId": "createApiKey",
        "summary": "Issue a delegated API key (keys:manage)",
        "responses": {
          "201": {
            "description": "Issue a delegated API key (keys:manage)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "description": "Present and true on a recovered result.",
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/KeyIssued"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          },
          {
            "name": "Key-Bootstrap",
            "in": "header",
            "required": true,
            "description": "32 random bytes as 64 hex characters, saved securely before issuance/rotation. Reuse only for retrying this operation, with the original body and Idempotency-Key. Never log this header.",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/KeyInput"
              }
            }
          }
        },
        "description": "Persists only a hash. The credential is disclosed only here or by a matching authenticated recovery within 24 hours. Scopes, inbox access and absolute expiry cannot exceed the issuer. Every replay rechecks caller and issued key. Same idempotency identity with a different payload or bootstrap is 409; reuse of a bootstrap for another issuance is 409. Unconfirmed replacements cannot delegate. At most 20 active keys per agent, counting pending replacements."
      },
      "head": {
        "operationId": "listApiKeysHead",
        "summary": "Headers only: List metadata within this agent and credential grant (keys:manage)",
        "responses": {
          "200": {
            "description": "List metadata within this agent and credential grant (keys:manage)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        },
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ],
        "description": "Only same-agent keys with scopes, inbox access and expiry covered by the caller are visible. Includes expired/revoked metadata, never secrets or hashes. Cursors outside this grant are rejected."
      }
    },
    "/v1/api-keys/current/rotate": {
      "post": {
        "operationId": "prepareApiKeyRotation",
        "summary": "Prepare a replacement with unchanged grants (bootstrap renews 30 days; delegated expiry is preserved) (keys:revoke)",
        "responses": {
          "201": {
            "description": "Prepare a replacement with unchanged grants (bootstrap renews 30 days; delegated expiry is preserved) (keys:revoke)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "description": "Present and true on a recovered result.",
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/KeyIssued"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          },
          {
            "name": "Key-Bootstrap",
            "in": "header",
            "required": true,
            "description": "32 random bytes as 64 hex characters, saved securely before issuance/rotation. Reuse only for retrying this operation, with the original body and Idempotency-Key. Never log this header.",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "required": [],
                "additionalProperties": false
              }
            }
          }
        },
        "description": "The old key remains valid until confirmation. Save the returned replacement, then confirm with it. A lost response is recovered with the old Bearer key plus the same Key-Bootstrap and Idempotency-Key for 24 hours. One pending replacement per source; unconfirmed replacements cannot rotate/delegate. Revoking the old key before confirmation revokes its pending replacement. Rotation never renews the 30-day Test lifetime. After 24 hours a NEW authenticated prepare request can atomically revoke an abandoned unconfirmed replacement and prepare another. The original replay stays 410. If confirmation already succeeded, the revoked source cannot cancel the replacement."
      }
    },
    "/v1/api-keys/current/confirm-rotation": {
      "post": {
        "operationId": "confirmApiKeyRotation",
        "summary": "Confirm with the replacement key and revoke its source atomically (keys:revoke)",
        "responses": {
          "200": {
            "description": "Confirm with the replacement key and revoke its source atomically (keys:revoke)",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/RotationConfirmed"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "required": [],
                "additionalProperties": false
              }
            }
          }
        },
        "description": "Bearer must be the active replacement. Empty JSON body, no Idempotency-Key or bootstrap needed. Retrying with that same active key returns the same confirmation without duplicate audit effects. Invalid, revoked, expired or newly restricted sources cannot be confirmed. After a lost confirmation response, keep using the replacement; the old key may already be revoked. A confirmed key may rotate again."
      }
    },
    "/v1/api-keys/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "delete": {
        "operationId": "revokeApiKey",
        "summary": "Revoke a key within this agent and caller grant (keys:manage)",
        "responses": {
          "200": {
            "description": "Credential revoked",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "revoked": {
                          "type": "boolean",
                          "const": true
                        }
                      },
                      "required": [
                        "id",
                        "revoked"
                      ]
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Requires the target scopes, inbox grant and expiry to be covered by the caller. Out-of-scope IDs return 404. Repeating with another still-active authorized management key returns 200. Revokes an unconfirmed replacement too. Does not revoke already-issued independent delegates."
      }
    },
    "/v1/inboxes/{inbox_id}/messages": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listMessages",
        "summary": "List readable message metadata (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200,
              "description": "Simple full-text search over readable subject/text; not semantic search."
            }
          },
          {
            "name": "thread_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "delivery_status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "accepted",
                "sending",
                "sent",
                "delivered",
                "rejected",
                "bounced",
                "delivery_unknown",
                "received"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailPage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "sendMessage",
        "summary": "Accept a message for mandatory screening (messages:send)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MailInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Persist Idempotency-Key before sending. Retry the original request after timeout; different normalized input with the same agent/operation identity is 409. Scope, inbox access and resource restrictions are rechecked before replay. Replay returns cached metadata, never message bodies or Bcc. Mail JSON body limit is 1 MiB."
      },
      "head": {
        "operationId": "listMessagesHead",
        "summary": "Headers only: List readable message metadata (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200,
              "description": "Simple full-text search over readable subject/text; not semantic search."
            }
          },
          {
            "name": "thread_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "delivery_status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "accepted",
                "sending",
                "sent",
                "delivered",
                "rejected",
                "bounced",
                "delivery_unknown",
                "received"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/messages/{id}": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getMessage",
        "summary": "Read authorized message content and current state (messages:read)",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "operationId": "getMessageHead",
        "summary": "Headers only: Read authorized message content and current state (messages:read)",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/messages/{id}/reply": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "replyMessage",
        "summary": "Accept a reply in an authorized conversation (messages:send)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MailInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Persist Idempotency-Key before sending. Retry the original request after timeout; different normalized input with the same agent/operation identity is 409. Scope, inbox access and resource restrictions are rechecked before replay. Replay returns cached metadata, never message bodies or Bcc. Mail JSON body limit is 1 MiB."
      }
    },
    "/v1/inboxes/{inbox_id}/drafts": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listDrafts",
        "summary": "List only drafts (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200,
              "description": "Simple full-text search over readable subject/text; not semantic search."
            }
          },
          {
            "name": "thread_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailPage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "createDraft",
        "summary": "Create an editable draft (drafts:write)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DraftInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Persist Idempotency-Key before sending. Retry the original request after timeout; different normalized input with the same agent/operation identity is 409. Scope, inbox access and resource restrictions are rechecked before replay. Replay returns cached metadata, never message bodies or Bcc. Mail JSON body limit is 1 MiB."
      },
      "head": {
        "operationId": "listDraftsHead",
        "summary": "Headers only: List only drafts (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200,
              "description": "Simple full-text search over readable subject/text; not semantic search."
            }
          },
          {
            "name": "thread_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/drafts/{id}": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getDraft",
        "summary": "Read an editable draft, final preview and hash (messages:read)",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "put": {
        "operationId": "updateDraft",
        "summary": "Replace draft content at an expected version (drafts:write)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DraftUpdate"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Persist Idempotency-Key before sending. Retry the original request after timeout; different normalized input with the same agent/operation identity is 409. Scope, inbox access and resource restrictions are rechecked before replay. Replay returns cached metadata, never message bodies or Bcc. Mail JSON body limit is 1 MiB."
      },
      "head": {
        "operationId": "getDraftHead",
        "summary": "Headers only: Read an editable draft, final preview and hash (messages:read)",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/drafts/{id}/approve": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "approveDraft",
        "summary": "Approve exact final content for a draft or held accepted message (drafts:approve)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DraftApproval"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "403": {
            "description": "Human workspace-owner approval required. Not retryable."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Legacy agent endpoint. Always rejected with human_approval_required after migration 008. Human approval requires a verified authenticated workspace owner through the dedicated review boundary; an agent API key cannot approve.",
        "deprecated": true
      }
    },
    "/v1/inboxes/{inbox_id}/drafts/{id}/send": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "sendDraft",
        "summary": "Accept an approved draft for screening (messages:send)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DraftSend"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailMessage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Persist Idempotency-Key before sending. Retry the original request after timeout; different normalized input with the same agent/operation identity is 409. Scope, inbox access and resource restrictions are rechecked before replay. Replay returns cached metadata, never message bodies or Bcc. Mail JSON body limit is 1 MiB."
      }
    },
    "/v1/inboxes/{inbox_id}/threads": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listThreads",
        "summary": "List inbox-scoped conversations (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ThreadPage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "operationId": "listThreadsHead",
        "summary": "Headers only: List inbox-scoped conversations (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/threads/{id}": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        },
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getThread",
        "summary": "Page through conversation message metadata (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailPage"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "operationId": "getThreadHead",
        "summary": "Headers only: Page through conversation message metadata (messages:read)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Opaque next_cursor from the preceding page. Unauthorized cursors are rejected. Ordering is by immutable ID; pagination is not a snapshot during writes."
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/policy": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getMailPolicy",
        "summary": "Read the workspace mail policy via an authorized inbox (policies:read)",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailPolicy"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "put": {
        "operationId": "putMailPolicy",
        "summary": "Replace the workspace mail policy (policies:write, workspace grant)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PolicyInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Persist before the first request; reuse for retries. Scoped to agent + operation. Never a credential.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              },
              "Idempotency-Replayed": {
                "schema": {
                  "type": "string",
                  "const": "true"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/MailPolicy"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Persist Idempotency-Key before sending. Retry the original request after timeout; different normalized input with the same agent/operation identity is 409. Scope, inbox access and resource restrictions are rechecked before replay. Replay returns cached metadata, never message bodies or Bcc. Mail JSON body limit is 1 MiB."
      },
      "head": {
        "operationId": "getMailPolicyHead",
        "summary": "Headers only: Read the workspace mail policy via an authorized inbox (policies:read)",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            }
          },
          "default": {
            "description": "Same status and headers as GET without a response body."
          }
        }
      }
    },
    "/v1/inboxes/{inbox_id}/policy/simulate": {
      "parameters": [
        {
          "name": "inbox_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "simulateMailPolicy",
        "summary": "Evaluate one address without sending or changing policy (policies:read)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "receive",
                      "send",
                      "reply"
                    ]
                  },
                  "address": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  }
                },
                "required": [
                  "action",
                  "address"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "parameters": [],
        "responses": {
          "200": {
            "description": "Authorized result",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "private, no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PolicySimulation"
                    },
                    "request_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "required": [
                    "data",
                    "request_id"
                  ],
                  "additionalProperties": false
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ma_test_<43 base64url characters>"
      },
      "Bootstrap": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Bootstrap <64 hexadecimal characters representing 32 random bytes>, persisted before signup."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "next_action": {
                "type": "string"
              },
              "request_id": {
                "type": "string",
                "format": "uuid"
              }
            },
            "required": [
              "code",
              "message",
              "retryable",
              "next_action",
              "request_id"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "Inbox": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "organization_id": {
            "type": "string",
            "format": "uuid"
          },
          "workspace_id": {
            "type": "string",
            "format": "uuid"
          },
          "agent_id": {
            "type": "string",
            "format": "uuid"
          },
          "local_part": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,31}$"
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "Trimmed; control characters are rejected."
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "provisioning",
              "active",
              "archived"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "organization_id",
          "workspace_id",
          "agent_id",
          "local_part",
          "display_name",
          "address",
          "status",
          "created_at"
        ]
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "identity:read",
                "inboxes:read",
                "inboxes:write",
                "keys:revoke",
                "keys:manage",
                "messages:read",
                "messages:send",
                "drafts:write",
                "drafts:approve",
                "policies:read",
                "policies:write"
              ]
            },
            "uniqueItems": true
          },
          "inbox_ids": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "null means workspace access; [] means no inbox access."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "revoked_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "issued_by_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "rotated_from_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "rotation_confirmed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "rotation_pending",
              "expired",
              "revoked"
            ]
          },
          "rotation_renews_expiry": {
            "type": "boolean",
            "description": "True for bootstrap authority; delegated rotations preserve their original expiry."
          }
        },
        "required": [
          "id",
          "name",
          "scopes",
          "inbox_ids",
          "expires_at",
          "revoked_at",
          "created_at",
          "issued_by_id",
          "rotated_from_id",
          "rotation_confirmed_at",
          "status"
        ],
        "additionalProperties": false
      },
      "Identity": {
        "type": "object",
        "properties": {
          "organization": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "plan_id": {
                "type": "string",
                "enum": [
                  "free",
                  "developer"
                ]
              },
              "catalog_version": {
                "type": "string"
              },
              "environment": {
                "type": "string",
                "const": "test"
              }
            },
            "required": [
              "id",
              "plan_id",
              "catalog_version",
              "environment"
            ]
          },
          "workspace": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80,
                "description": "Trimmed; control characters are rejected."
              },
              "status": {
                "type": "string",
                "enum": [
                  "provisioning",
                  "active",
                  "paused"
                ]
              },
              "mail_subdomain": {
                "type": "string"
              },
              "email_domain": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "name",
              "status",
              "mail_subdomain",
              "email_domain"
            ]
          },
          "agent": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80,
                "description": "Trimmed; control characters are rejected."
              },
              "status": {
                "type": "string",
                "enum": [
                  "active",
                  "disabled"
                ]
              }
            },
            "required": [
              "id",
              "name",
              "status"
            ]
          },
          "api_key": {
            "$ref": "#/components/schemas/ApiKey"
          }
        },
        "required": [
          "organization",
          "workspace",
          "agent",
          "api_key"
        ]
      },
      "RegisterInput": {
        "type": "object",
        "properties": {
          "agent_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "Trimmed; control characters are rejected."
          },
          "workspace_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "Trimmed; control characters are rejected."
          },
          "local_part": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,31}$"
          }
        },
        "required": [
          "agent_name"
        ],
        "additionalProperties": false
      },
      "InboxInput": {
        "type": "object",
        "properties": {
          "local_part": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,31}$"
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "Defaults to local_part when omitted. If provided, trimmed; blank values and control characters are rejected."
          }
        },
        "required": [
          "local_part"
        ],
        "additionalProperties": false
      },
      "InboxPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Inbox"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "items",
          "next_cursor"
        ]
      },
      "Registration": {
        "type": "object",
        "properties": {
          "organization": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "plan_id": {
                "type": "string",
                "enum": [
                  "free",
                  "developer"
                ]
              },
              "catalog_version": {
                "type": "string"
              },
              "environment": {
                "type": "string",
                "const": "test"
              }
            },
            "required": [
              "id",
              "plan_id",
              "catalog_version",
              "environment"
            ]
          },
          "workspace": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80,
                "description": "Trimmed; control characters are rejected."
              },
              "status": {
                "type": "string",
                "enum": [
                  "provisioning",
                  "active",
                  "paused"
                ]
              },
              "mail_subdomain": {
                "type": "string"
              },
              "email_domain": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "name",
              "status",
              "mail_subdomain",
              "email_domain"
            ]
          },
          "agent": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 80,
                "description": "Trimmed; control characters are rejected."
              },
              "status": {
                "type": "string",
                "enum": [
                  "active",
                  "disabled"
                ]
              }
            },
            "required": [
              "id",
              "name",
              "status"
            ]
          },
          "api_key": {
            "$ref": "#/components/schemas/ApiKey"
          },
          "inbox": {
            "$ref": "#/components/schemas/Inbox"
          },
          "replayed": {
            "type": "boolean"
          },
          "credential": {
            "$ref": "#/components/schemas/Credential"
          }
        },
        "required": [
          "organization",
          "workspace",
          "agent",
          "api_key",
          "inbox",
          "replayed",
          "credential"
        ]
      },
      "Credential": {
        "type": "object",
        "properties": {
          "secret": {
            "type": "string",
            "pattern": "^ma_test_[A-Za-z0-9_-]{43}$",
            "readOnly": true,
            "description": "Store in the agent secret store; never put it in model context or logs."
          },
          "token_type": {
            "type": "string",
            "const": "Bearer"
          },
          "recovery_window_hours": {
            "type": "integer",
            "const": 24
          }
        },
        "required": [
          "secret",
          "token_type",
          "recovery_window_hours"
        ]
      },
      "KeyInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "scopes": {
            "type": "array",
            "minItems": 1,
            "maxItems": 11,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "enum": [
                "identity:read",
                "inboxes:read",
                "inboxes:write",
                "keys:revoke",
                "keys:manage",
                "messages:read",
                "messages:send",
                "drafts:write",
                "drafts:approve",
                "policies:read",
                "policies:write"
              ]
            }
          },
          "inbox_ids": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 100,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?Z$",
            "description": "A real UTC calendar timestamp, strictly in the future and no later than the issuing key expiry. Offsets, leap seconds, 24:00 and normalized invalid dates are rejected."
          }
        },
        "required": [
          "name",
          "scopes",
          "inbox_ids",
          "expires_at"
        ],
        "additionalProperties": false
      },
      "KeyPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiKey"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "items",
          "next_cursor"
        ],
        "additionalProperties": false
      },
      "KeyIssued": {
        "type": "object",
        "properties": {
          "api_key": {
            "$ref": "#/components/schemas/ApiKey"
          },
          "credential": {
            "$ref": "#/components/schemas/Credential"
          }
        },
        "required": [
          "api_key",
          "credential"
        ],
        "additionalProperties": false
      },
      "RotationConfirmed": {
        "type": "object",
        "properties": {
          "api_key": {
            "$ref": "#/components/schemas/ApiKey"
          },
          "revoked_key_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [
          "api_key",
          "revoked_key_id"
        ],
        "additionalProperties": false
      },
      "AttachmentRef": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          }
        },
        "required": [
          "id",
          "version"
        ],
        "additionalProperties": false
      },
      "MailInput": {
        "type": "object",
        "properties": {
          "to": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "cc": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "bcc": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "subject": {
            "type": "string",
            "maxLength": 500,
            "default": ""
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "description": "At most 256 KiB UTF-8; line endings normalized to LF."
          },
          "html": {
            "type": [
              "string",
              "null"
            ],
            "description": "At most 256 KiB UTF-8, sanitized to a conservative HTML subset. Active content, styles and remote images are removed before branding."
          },
          "attachments": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/AttachmentRef"
            }
          }
        },
        "required": [],
        "additionalProperties": false,
        "description": "At least one unique recipient across To/Cc/Bcc and one nonblank text/html body are required. At most 20 distinct recipients total; duplicates are removed preserving To then Cc then Bcc priority. Fields are full content, not a patch. Subject limit is 500 UTF-8 bytes and disallows control characters. No custom headers or provider credentials. Attachments refer only to existing authorized exact versions; this API does not upload files."
      },
      "DraftInput": {
        "type": "object",
        "properties": {
          "to": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "cc": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "bcc": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "subject": {
            "type": "string",
            "maxLength": 500,
            "default": ""
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "description": "At most 256 KiB UTF-8; line endings normalized to LF."
          },
          "html": {
            "type": [
              "string",
              "null"
            ],
            "description": "At most 256 KiB UTF-8, sanitized to a conservative HTML subset. Active content, styles and remote images are removed before branding."
          },
          "attachments": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/AttachmentRef"
            }
          },
          "reply_to_message_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": [],
        "additionalProperties": false,
        "description": "At least one unique recipient across To/Cc/Bcc and one nonblank text/html body are required. At most 20 distinct recipients total; duplicates are removed preserving To then Cc then Bcc priority. Fields are full content, not a patch. Subject limit is 500 UTF-8 bytes and disallows control characters. No custom headers or provider credentials. Attachments refer only to existing authorized exact versions; this API does not upload files. Optional reply_to_message_id refers to an accessible, readable nondraft message in this inbox."
      },
      "DraftUpdate": {
        "type": "object",
        "properties": {
          "to": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "cc": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "bcc": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "format": "email",
              "maxLength": 254
            }
          },
          "subject": {
            "type": "string",
            "maxLength": 500,
            "default": ""
          },
          "text": {
            "type": [
              "string",
              "null"
            ],
            "description": "At most 256 KiB UTF-8; line endings normalized to LF."
          },
          "html": {
            "type": [
              "string",
              "null"
            ],
            "description": "At most 256 KiB UTF-8, sanitized to a conservative HTML subset. Active content, styles and remote images are removed before branding."
          },
          "attachments": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/AttachmentRef"
            }
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "expected_version"
        ],
        "additionalProperties": false,
        "description": "At least one unique recipient across To/Cc/Bcc and one nonblank text/html body are required. At most 20 distinct recipients total; duplicates are removed preserving To then Cc then Bcc priority. Fields are full content, not a patch. Subject limit is 500 UTF-8 bytes and disallows control characters. No custom headers or provider credentials. Attachments refer only to existing authorized exact versions; this API does not upload files. Requires current version; any content change invalidates approval."
      },
      "DraftApproval": {
        "type": "object",
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "expected_hash": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        },
        "required": [
          "expected_version",
          "expected_hash"
        ],
        "additionalProperties": false
      },
      "DraftSend": {
        "type": "object",
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "required": [
          "expected_version"
        ],
        "additionalProperties": false
      },
      "MailMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "operation_id": {
            "type": "string",
            "format": "uuid"
          },
          "inbox_id": {
            "type": "string",
            "format": "uuid"
          },
          "thread_id": {
            "type": "string",
            "format": "uuid"
          },
          "direction": {
            "type": "string",
            "enum": [
              "inbound",
              "outbound"
            ]
          },
          "action": {
            "type": "string",
            "enum": [
              "receive",
              "send",
              "reply"
            ]
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "message_id": {
            "type": "string"
          },
          "in_reply_to": {
            "type": [
              "string",
              "null"
            ]
          },
          "references": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "subject": {
            "type": "string"
          },
          "from": {
            "type": [
              "string",
              "null"
            ]
          },
          "to": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "cc": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "delivery_status": {
            "type": "string",
            "enum": [
              "draft",
              "accepted",
              "sending",
              "sent",
              "delivered",
              "rejected",
              "bounced",
              "delivery_unknown",
              "received"
            ]
          },
          "screening_status": {
            "type": "string",
            "enum": [
              "pending",
              "running",
              "approved",
              "held",
              "blocked"
            ]
          },
          "reason_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "approved_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "final_hash": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "policy_version": {
            "type": "integer",
            "minimum": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "content_available": {
            "type": "boolean"
          },
          "content": {
            "type": "object",
            "properties": {
              "to": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "string",
                  "format": "email",
                  "maxLength": 254
                }
              },
              "cc": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "string",
                  "format": "email",
                  "maxLength": 254
                }
              },
              "bcc": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "string",
                  "format": "email",
                  "maxLength": 254
                }
              },
              "subject": {
                "type": "string",
                "maxLength": 500,
                "default": ""
              },
              "text": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "At most 256 KiB UTF-8; line endings normalized to LF."
              },
              "html": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "At most 256 KiB UTF-8, sanitized to a conservative HTML subset. Active content, styles and remote images are removed before branding."
              },
              "attachments": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "version": {
                      "type": "string"
                    },
                    "sha256": {
                      "type": "string",
                      "pattern": "^[a-f0-9]{64}$"
                    },
                    "bytes": {
                      "type": "integer",
                      "minimum": 0
                    }
                  },
                  "required": [
                    "id",
                    "version",
                    "sha256",
                    "bytes"
                  ],
                  "additionalProperties": false
                }
              },
              "from": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "message_id": {
                "type": "string"
              },
              "in_reply_to": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "references": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "to",
              "cc",
              "subject",
              "text",
              "html",
              "attachments",
              "from",
              "message_id",
              "in_reply_to",
              "references"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "operation_id",
          "inbox_id",
          "thread_id",
          "direction",
          "action",
          "version",
          "message_id",
          "in_reply_to",
          "references",
          "subject",
          "from",
          "to",
          "cc",
          "delivery_status",
          "screening_status",
          "reason_code",
          "approved_version",
          "final_hash",
          "policy_version",
          "created_at",
          "updated_at",
          "content_available"
        ],
        "additionalProperties": false,
        "description": "Metadata from writes/lists; authorized single-message GET may include final content. Quarantined inbound bodies are omitted. Bcc is never in list/thread/replay metadata and is returned on eligible outbound detail only to its creator with sending/draft authority, or a drafts:approve credential. A 202 response is acceptance for screening, not delivery."
      },
      "MailPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MailMessage"
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "items",
          "next_cursor"
        ],
        "additionalProperties": false
      },
      "ThreadPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "inbox_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "message_count": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "id",
                "inbox_id",
                "created_at",
                "message_count"
              ],
              "additionalProperties": false
            }
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        },
        "required": [
          "items",
          "next_cursor"
        ],
        "additionalProperties": false
      },
      "MailRule": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80
          },
          "direction": {
            "type": "string",
            "enum": [
              "receive",
              "send",
              "reply"
            ]
          },
          "action": {
            "type": "string",
            "enum": [
              "allow",
              "block"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "email",
              "domain"
            ]
          },
          "value": {
            "type": "string",
            "maxLength": 254
          },
          "note": {
            "type": "string",
            "maxLength": 500
          }
        },
        "required": [
          "id",
          "direction",
          "action",
          "kind",
          "value",
          "note"
        ],
        "additionalProperties": false
      },
      "MailPolicy": {
        "type": "object",
        "properties": {
          "workspace_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "rules": {
            "type": "array",
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/MailRule"
            }
          },
          "allow_only": {
            "type": "object",
            "properties": {
              "receive": {
                "type": "boolean"
              },
              "send": {
                "type": "boolean"
              },
              "reply": {
                "type": "boolean"
              }
            },
            "required": [
              "receive",
              "send",
              "reply"
            ],
            "additionalProperties": false
          },
          "require_approval": {
            "type": "boolean"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Null for the implicit default policy before the first write."
          }
        },
        "required": [
          "workspace_id",
          "version",
          "rules",
          "allow_only",
          "require_approval",
          "updated_at"
        ],
        "additionalProperties": false
      },
      "PolicyInput": {
        "type": "object",
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "rules": {
            "type": "array",
            "maxItems": 500,
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 80
                },
                "direction": {
                  "type": "string",
                  "enum": [
                    "receive",
                    "send",
                    "reply"
                  ]
                },
                "action": {
                  "type": "string",
                  "enum": [
                    "allow",
                    "block"
                  ]
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "email",
                    "domain"
                  ]
                },
                "value": {
                  "type": "string",
                  "maxLength": 254
                },
                "note": {
                  "type": "string",
                  "maxLength": 500
                }
              },
              "required": [
                "id",
                "direction",
                "action",
                "kind",
                "value"
              ],
              "additionalProperties": false
            }
          },
          "allow_only": {
            "type": "object",
            "properties": {
              "receive": {
                "type": "boolean"
              },
              "send": {
                "type": "boolean"
              },
              "reply": {
                "type": "boolean"
              }
            },
            "required": [
              "receive",
              "send",
              "reply"
            ],
            "additionalProperties": false
          },
          "require_approval": {
            "type": "boolean"
          }
        },
        "required": [
          "expected_version",
          "rules",
          "allow_only",
          "require_approval"
        ],
        "additionalProperties": false,
        "description": "Replaces the workspace policy. Requires a workspace-wide credential (inbox_ids null), policies:write and the current version. Rule IDs and normalized direction/action/kind/value combinations must be unique. Bare domains match exactly. Explicit *.example.com matches that domain and its subdomains. Block takes priority. Reply must satisfy both Send and Reply policies."
      },
      "PolicySimulation": {
        "type": "object",
        "properties": {
          "allowed": {
            "type": "boolean"
          },
          "reason": {
            "type": "string",
            "enum": [
              "invalid",
              "block",
              "allow",
              "restricted",
              "open"
            ]
          },
          "rule": {
            "$ref": "#/components/schemas/MailRule"
          },
          "policy_version": {
            "type": "integer",
            "minimum": 1
          },
          "evaluator_version": {
            "type": "string",
            "const": "mail-lists-v1"
          },
          "required_action": {
            "type": "string",
            "const": "send"
          }
        },
        "required": [
          "allowed",
          "reason",
          "policy_version",
          "evaluator_version"
        ],
        "additionalProperties": false
      }
    },
    "responses": {
      "Error": {
        "description": "Stable error code with recovery action. Known errors use 400/401/403/404/405/409/410/413/415/429/503; dependency failures never expose upstream details. Retry mutations with their original Idempotency-Key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
