{
  "openapi": "3.0.3",
  "info": {
    "title": "AICMOHQ API",
    "version": "1.0.0",
    "description": "The implemented HTTP API used by the AICMOHQ CLI. Account and content operations require a bearer token with the appropriate scope. Device authorization approval is completed in the browser and requires an active subscription."
  },
  "servers": [
    {
      "url": "https://app.aicmohq.com",
      "description": "Application API for authenticated CLI and MCP operations"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "servers": [
          {
            "url": "https://aicmohq.com",
            "description": "Public health endpoint"
          }
        ],
        "summary": "Check API health",
        "security": [],
        "responses": {
          "200": {
            "description": "API is responding",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        },
        "operationId": "get_api_health",
        "description": "Check API health"
      }
    },
    "/api/waitlist": {
      "post": {
        "summary": "Join the waitlist",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WaitlistRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted or already joined"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "operationId": "post_api_waitlist",
        "description": "Join the waitlist"
      }
    },
    "/api/v1/auth/device": {
      "post": {
        "tags": [
          "Device authorization"
        ],
        "summary": "Start CLI device authorization",
        "security": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeviceStartRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Device request created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeviceStartResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        },
        "operationId": "post_api_v1_auth_device",
        "description": "Start CLI device authorization"
      }
    },
    "/api/v1/auth/device/token": {
      "post": {
        "tags": [
          "Device authorization"
        ],
        "summary": "Poll for the CLI access token",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeviceTokenRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token issued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenResponse"
                }
              }
            }
          },
          "400": {
            "description": "Pending, denied, expired, or invalid device request"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "operationId": "post_api_v1_auth_device_token",
        "description": "Poll for the CLI access token"
      }
    },
    "/api/v1/me": {
      "get": {
        "tags": [
          "Account"
        ],
        "summary": "Get account and token scopes",
        "responses": {
          "200": {
            "description": "Account details"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "operationId": "get_api_v1_me",
        "description": "Get account and token scopes"
      }
    },
    "/api/v1/connections": {
      "get": {
        "tags": [
          "Account"
        ],
        "summary": "List connected platforms",
        "description": "Requires connections:read. Access and refresh tokens are not returned.",
        "responses": {
          "200": {
            "description": "Connections"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        },
        "operationId": "get_api_v1_connections"
      }
    },
    "/api/v1/queue": {
      "get": {
        "tags": [
          "Queue"
        ],
        "summary": "List queued content",
        "description": "Requires queue:read.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Queue items"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        },
        "operationId": "get_api_v1_queue"
      },
      "post": {
        "tags": [
          "Queue"
        ],
        "summary": "Create a draft queue item",
        "description": "Requires queue:write. New items are created as drafts.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QueueCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Draft created"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        },
        "operationId": "post_api_v1_queue"
      }
    },
    "/api/v1/queue/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/QueueId"
        }
      ],
      "patch": {
        "tags": [
          "Queue"
        ],
        "summary": "Edit a queue item",
        "description": "Requires queue:write.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QueuePatchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated item"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "operationId": "patch_api_v1_queue_by_id"
      },
      "delete": {
        "tags": [
          "Queue"
        ],
        "summary": "Delete a queue item",
        "description": "Requires queue:write.",
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "operationId": "delete_api_v1_queue_by_id"
      }
    },
    "/api/v1/queue/{id}/approve": {
      "post": {
        "tags": [
          "Queue"
        ],
        "summary": "Approve a draft",
        "description": "Requires queue:write. Approval does not publish the item.",
        "parameters": [
          {
            "$ref": "#/components/parameters/QueueId"
          }
        ],
        "responses": {
          "200": {
            "description": "Approved item"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "Item cannot be approved in its current state"
          }
        },
        "operationId": "post_api_v1_queue_by_id_approve"
      }
    },
    "/api/v1/queue/{id}/publish": {
      "post": {
        "tags": [
          "Queue"
        ],
        "summary": "Publish an approved queue item",
        "description": "Requires publish. Human approval, connected platform, credit, and provider requirements still apply.",
        "parameters": [
          {
            "$ref": "#/components/parameters/QueueId"
          }
        ],
        "responses": {
          "200": {
            "description": "Provider result"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "description": "Approval or platform state prevents publishing"
          }
        },
        "operationId": "post_api_v1_queue_by_id_publish"
      }
    },
    "/api/v1/queue/{id}/proof": {
      "post": {
        "tags": [
          "Queue"
        ],
        "summary": "Attach proof for assisted publishing",
        "description": "Requires queue:write. Proof URLs are supported for Hacker News and Product Hunt items.",
        "parameters": [
          {
            "$ref": "#/components/parameters/QueueId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "proofUrl"
                ],
                "properties": {
                  "proofUrl": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Proof attached"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "operationId": "post_api_v1_queue_by_id_proof"
      }
    },
    "/api/v1/scout": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "Run Scout",
        "description": "Requires strategy:run. Credits, rate limits, and canonical product context apply.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "keywords": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scout result"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Credits or subscription required"
          },
          "409": {
            "description": "Product context incomplete"
          }
        },
        "operationId": "post_api_v1_scout"
      }
    },
    "/api/v1/write": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "Generate a content draft",
        "description": "Requires strategy:run. The platform field is required.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WriteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated draft"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Credits or subscription required"
          }
        },
        "operationId": "post_api_v1_write"
      }
    },
    "/api/v1/strategy/run": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "Run Strategy",
        "description": "Requires strategy:run. Credits and canonical product context apply.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Strategy result"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Credits or subscription required"
          },
          "409": {
            "description": "Product context incomplete"
          }
        },
        "operationId": "post_api_v1_strategy_run"
      }
    },
    "/api/v1/tokens": {
      "get": {
        "tags": [
          "Account"
        ],
        "summary": "List active tokens",
        "description": "User-token operation. Plaintext is never returned.",
        "responses": {
          "200": {
            "description": "Token metadata"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "operationId": "get_api_v1_tokens"
      },
      "post": {
        "tags": [
          "Account"
        ],
        "summary": "Create a scoped agent token",
        "description": "User-token operation. The plaintext token is returned exactly once. Supported scopes: queue:read, queue:write, publish, connections:read, strategy:run.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTokenRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Token created once"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "description": "Subscription required"
          }
        },
        "operationId": "post_api_v1_tokens"
      }
    },
    "/api/v1/tokens/{id}": {
      "delete": {
        "tags": [
          "Account"
        ],
        "summary": "Revoke a token",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "operationId": "delete_api_v1_tokens_by_id",
        "description": "Revoke a token"
      }
    },
    "/api/v1/command/chat": {
      "post": {
        "tags": [
          "Command"
        ],
        "summary": "Create a command-chat plan",
        "description": "Requires strategy:run. Interprets messages into an approval-first plan without publishing side effects.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CommandChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommandChatResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "description": "Canonical product context is incomplete"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "Command execution is disabled"
          }
        },
        "operationId": "post_api_v1_command_chat"
      }
    },
    "/api/v1/command/run": {
      "post": {
        "tags": [
          "Command"
        ],
        "summary": "Run an approved command plan",
        "description": "Requires strategy:run. Approval-first execution; publishing remains subject to human approval and platform/credit requirements. Returns NDJSON command-run events.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CommandRunRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "NDJSON command-run events",
            "content": {
              "application/x-ndjson": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "description": "Plan is not runnable or requires approval"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "description": "Command execution is disabled"
          }
        },
        "operationId": "post_api_v1_command_run"
      }
    },
    "/api/v1/command/sessions": {
      "get": {
        "tags": [
          "Command"
        ],
        "summary": "List command-chat sessions",
        "description": "Requires strategy:run. Returns sessions belonging to the authenticated user.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Command sessions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommandSessionsResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "operationId": "get_api_v1_command_sessions"
      }
    },
    "/api/v1/command/session/{sessionId}": {
      "parameters": [
        {
          "name": "SessionId",
          "in": "path",
          "required": true,
          "description": "Session UUID, or `latest` for the newest session.",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "tags": [
          "Command"
        ],
        "summary": "Read a command-chat session",
        "description": "Requires strategy:run. Session data is scoped to the authenticated user.",
        "responses": {
          "200": {
            "description": "Session transcript and run state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommandSessionResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "operationId": "get_api_v1_command_session"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "AICMOHQ token"
      }
    },
    "parameters": {
      "QueueId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid bearer token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Token lacks the required scope or operation is not permitted",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many requests",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Health": {
        "type": "object",
        "required": [
          "status",
          "service",
          "timestamp",
          "docs"
        ],
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "service": {
            "type": "string",
            "example": "aicmohq-public-site"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "docs": {
            "type": "string",
            "format": "uri",
            "example": "https://aicmohq.com/developers"
          }
        }
      },
      "WaitlistRequest": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "email": {
            "type": "string",
            "description": "Email address or website URL"
          },
          "source": {
            "type": "string"
          }
        }
      },
      "DeviceStartRequest": {
        "type": "object",
        "properties": {
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "queue:read",
                "queue:write",
                "publish",
                "connections:read",
                "strategy:run"
              ]
            }
          }
        }
      },
      "DeviceStartResponse": {
        "type": "object",
        "required": [
          "device_code",
          "user_code",
          "verification_uri",
          "interval",
          "expires_in"
        ],
        "properties": {
          "device_code": {
            "type": "string"
          },
          "user_code": {
            "type": "string"
          },
          "verification_uri": {
            "type": "string",
            "format": "uri"
          },
          "verification_uri_complete": {
            "type": "string",
            "format": "uri"
          },
          "interval": {
            "type": "integer"
          },
          "expires_in": {
            "type": "integer"
          }
        }
      },
      "DeviceTokenRequest": {
        "type": "object",
        "required": [
          "device_code"
        ],
        "properties": {
          "device_code": {
            "type": "string"
          }
        }
      },
      "TokenResponse": {
        "type": "object",
        "required": [
          "access_token",
          "token_type"
        ],
        "properties": {
          "access_token": {
            "type": "string"
          },
          "token_type": {
            "type": "string",
            "example": "bearer"
          }
        }
      },
      "QueueCreateRequest": {
        "type": "object",
        "required": [
          "platform",
          "content"
        ],
        "properties": {
          "platform": {
            "type": "string"
          },
          "content": {
            "type": "string"
          },
          "scheduled_for": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "QueuePatchRequest": {
        "type": "object",
        "minProperties": 1,
        "properties": {
          "content": {
            "type": "string"
          },
          "platform": {
            "type": "string"
          },
          "media_urls": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "scheduled_for": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "status": {
            "type": "string"
          }
        }
      },
      "WriteRequest": {
        "type": "object",
        "required": [
          "platform"
        ],
        "properties": {
          "platform": {
            "type": "string"
          },
          "fromGit": {
            "type": "boolean"
          },
          "topic": {
            "type": "string"
          },
          "gitContext": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "enqueue": {
            "type": "boolean"
          }
        }
      },
      "CreateTokenRequest": {
        "type": "object",
        "required": [
          "scopes"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "queue:read",
                "queue:write",
                "publish",
                "connections:read",
                "strategy:run"
              ]
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable machine-readable error code"
              },
              "message": {
                "type": "string",
                "description": "Actionable explanation"
              },
              "retryable": {
                "type": "boolean"
              },
              "status": {
                "type": "integer"
              }
            }
          }
        }
      },
      "CommandChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "sessionId": {
            "type": "string"
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "user",
                    "assistant"
                  ]
                },
                "content": {
                  "type": "string"
                }
              }
            }
          },
          "timezone": {
            "type": "string"
          },
          "modifyOfMessageId": {
            "type": "string"
          },
          "agentId": {
            "type": "string"
          },
          "page": {
            "type": "object",
            "nullable": true,
            "properties": {
              "path": {
                "type": "string"
              },
              "title": {
                "type": "string"
              }
            }
          }
        }
      },
      "CommandChatResponse": {
        "type": "object",
        "required": [
          "sessionId",
          "message",
          "insufficientCredits",
          "runId",
          "executionPolicy",
          "blockingAgents"
        ],
        "properties": {
          "sessionId": {
            "type": "string"
          },
          "message": {
            "type": "object",
            "required": [
              "id",
              "content",
              "planState"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "content": {
                "type": "string"
              },
              "plan": {
                "type": "object",
                "nullable": true,
                "additionalProperties": true
              },
              "planState": {
                "type": "string",
                "nullable": true,
                "enum": [
                  "proposed"
                ]
              }
            }
          },
          "insufficientCredits": {
            "type": "boolean"
          },
          "runId": {
            "type": "string",
            "nullable": true
          },
          "executionPolicy": {
            "type": "string",
            "enum": [
              "approval_required",
              "auto_run_eligible"
            ]
          },
          "blockingAgents": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "CommandRunRequest": {
        "type": "object",
        "required": [
          "messageId"
        ],
        "properties": {
          "messageId": {
            "type": "string"
          },
          "auto": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "CommandSessionsResponse": {
        "type": "object",
        "required": [
          "sessions"
        ],
        "properties": {
          "sessions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "title",
                "createdAt",
                "preview"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "createdAt": {
                  "type": "string",
                  "format": "date-time"
                },
                "preview": {
                  "type": "string",
                  "nullable": true
                }
              }
            }
          }
        }
      },
      "CommandSessionResponse": {
        "type": "object",
        "required": [
          "session",
          "messages",
          "runs",
          "items"
        ],
        "properties": {
          "session": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "runs": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      }
    }
  }
}
