{
  "openapi": "3.1.0",
  "info": {
    "title": "ForLoop API",
    "version": "0.2.0",
    "description": "Public subset of the documented ForLoop /api/opencode/* endpoints. Resource schemas are intentionally generic until the API owner verifies the full response contract. See /en/docs/api for examples and the current API surface.",
    "license": {
      "name": "Proprietary",
      "identifier": "LicenseRef-ForLoop-Proprietary"
    },
    "x-environments": {
      "prd": "https://api.forloop.cc",
      "dev": "https://api.dev.forloop.cc"
    },
    "x-schema-completeness": "partial"
  },
  "servers": [
    {
      "url": "https://api.forloop.cc",
      "description": "Documented base URL; confirm with the API owner before publishing."
    }
  ],
  "tags": [
    {
      "name": "Sprints",
      "description": "Create, inspect, update, and delete sprints."
    },
    {
      "name": "Stories",
      "description": "Manage stories and comments inside a sprint."
    },
    {
      "name": "AI agents",
      "description": "Inspect agents and invoke agent chat, suggestions, tasks, and summaries."
    },
    {
      "name": "Profile",
      "description": "Read and update the current user profile and quotas."
    },
    {
      "name": "Organizations",
      "description": "Manage organizations and organization quotas."
    },
    {
      "name": "Files",
      "description": "Upload, download, position, and delete canvas files."
    },
    {
      "name": "Templates",
      "description": "List and create story templates."
    },
    {
      "name": "Tokens",
      "description": "Create and revoke scoped API tokens using a Clerk session."
    }
  ],
  "security": [
    {
      "ApiToken": []
    }
  ],
  "paths": {
    "/api/opencode/sprints": {
      "get": {
        "tags": [
          "Sprints"
        ],
        "summary": "List sprints",
        "operationId": "listSprints",
        "x-required-scopes": [
          "sprint:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/SprintList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "post": {
        "tags": [
          "Sprints"
        ],
        "summary": "Create a sprint",
        "operationId": "createSprint",
        "x-required-scopes": [
          "sprint:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/Sprint"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/sprints/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Sprints"
        ],
        "summary": "Get a sprint",
        "operationId": "getSprint",
        "x-required-scopes": [
          "sprint:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Sprint"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "put": {
        "tags": [
          "Sprints"
        ],
        "summary": "Update a sprint",
        "operationId": "updateSprint",
        "x-required-scopes": [
          "sprint:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Sprint"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "delete": {
        "tags": [
          "Sprints"
        ],
        "summary": "Delete a sprint",
        "operationId": "deleteSprint",
        "x-required-scopes": [
          "sprint:write"
        ],
        "responses": {
          "204": {
            "$ref": "#/components/responses/NoContent"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/sprints/{id}/ai-agents": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "put": {
        "tags": [
          "Sprints",
          "AI agents"
        ],
        "summary": "Update the AI agents assigned to a sprint",
        "operationId": "updateSprintAiAgents",
        "x-required-scopes": [
          "sprint:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/stories": {
      "post": {
        "tags": [
          "Stories"
        ],
        "summary": "Create a story",
        "operationId": "createStory",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/Story"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/stories/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Stories"
        ],
        "summary": "Get a story",
        "operationId": "getStory",
        "x-required-scopes": [
          "story:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Story"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "put": {
        "tags": [
          "Stories"
        ],
        "summary": "Update a story",
        "operationId": "updateStory",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Story"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "delete": {
        "tags": [
          "Stories"
        ],
        "summary": "Delete a story",
        "operationId": "deleteStory",
        "x-required-scopes": [
          "story:delete"
        ],
        "responses": {
          "204": {
            "$ref": "#/components/responses/NoContent"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/stories/{id}/comments": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Stories"
        ],
        "summary": "List story comments",
        "operationId": "listStoryComments",
        "x-required-scopes": [
          "story:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/StoryCommentList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "post": {
        "tags": [
          "Stories"
        ],
        "summary": "Create a story comment",
        "operationId": "createStoryComment",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/StoryComment"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/ai/agents": {
      "get": {
        "tags": [
          "AI agents"
        ],
        "summary": "List available AI agents",
        "operationId": "listAiAgents",
        "x-required-scopes": [
          "agent:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/AiAgents"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/agents/chat": {
      "post": {
        "tags": [
          "AI agents"
        ],
        "summary": "Chat with an AI agent",
        "operationId": "chatWithAgent",
        "x-required-scopes": [
          "agent:query"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/agents/suggestions": {
      "post": {
        "tags": [
          "AI agents"
        ],
        "summary": "Get story suggestions",
        "operationId": "createAgentSuggestions",
        "x-required-scopes": [
          "agent:query"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonArray"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/agents/tasks": {
      "get": {
        "tags": [
          "AI agents"
        ],
        "summary": "List AI tasks",
        "operationId": "listAgentTasks",
        "x-required-scopes": [
          "agent:query"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/AITaskList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/agents/summary": {
      "get": {
        "tags": [
          "AI agents"
        ],
        "summary": "Get a sprint summary",
        "operationId": "getAgentSummary",
        "x-required-scopes": [
          "sprint:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/user/profile": {
      "get": {
        "tags": [
          "Profile"
        ],
        "summary": "Get the current profile",
        "operationId": "getProfile",
        "x-required-scopes": [
          "profile:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/UserProfile"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "put": {
        "tags": [
          "Profile"
        ],
        "summary": "Update the current profile",
        "operationId": "updateProfile",
        "x-required-scopes": [
          "profile:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/UserProfile"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/user/quotas": {
      "get": {
        "tags": [
          "Profile"
        ],
        "summary": "Get user quotas",
        "operationId": "getUserQuotas",
        "x-required-scopes": [
          "profile:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Quotas"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/organizations": {
      "get": {
        "tags": [
          "Organizations"
        ],
        "summary": "List organizations for the current user",
        "operationId": "listOrganizations",
        "x-required-scopes": [
          "organization:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/OrganizationList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "post": {
        "tags": [
          "Organizations"
        ],
        "summary": "Create an organization",
        "operationId": "createOrganization",
        "x-required-scopes": [
          "organization:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/Organization"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/organizations/owned": {
      "get": {
        "tags": [
          "Organizations"
        ],
        "summary": "List owned organizations",
        "operationId": "listOwnedOrganizations",
        "x-required-scopes": [
          "organization:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/OrganizationList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/organizations/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "put": {
        "tags": [
          "Organizations"
        ],
        "summary": "Update an organization",
        "operationId": "updateOrganization",
        "x-required-scopes": [
          "organization:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Organization"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "delete": {
        "tags": [
          "Organizations"
        ],
        "summary": "Delete an organization",
        "operationId": "deleteOrganization",
        "x-required-scopes": [
          "organization:delete"
        ],
        "responses": {
          "204": {
            "$ref": "#/components/responses/NoContent"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/organization/{id}/quotas": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Organizations"
        ],
        "summary": "Get organization quotas",
        "operationId": "getOrganizationQuotas",
        "x-required-scopes": [
          "organization:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/upload": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Upload a canvas file",
        "operationId": "uploadFile",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/presign": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Get a presigned upload URL",
        "operationId": "presignFileUpload",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/complete": {
      "post": {
        "tags": [
          "Files"
        ],
        "summary": "Complete an upload",
        "operationId": "completeFileUpload",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/download/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "Download a file",
        "operationId": "downloadFile",
        "x-required-scopes": [
          "story:read"
        ],
        "responses": {
          "200": {
            "description": "File content.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/open-url/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "Get a file open URL",
        "operationId": "getFileOpenUrl",
        "x-required-scopes": [
          "story:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/sprint/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "get": {
        "tags": [
          "Files"
        ],
        "summary": "List sprint files",
        "operationId": "listSprintFiles",
        "x-required-scopes": [
          "story:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonArray"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/{id}/position": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "put": {
        "tags": [
          "Files"
        ],
        "summary": "Update a file position",
        "operationId": "updateFilePosition",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/files/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "delete": {
        "tags": [
          "Files"
        ],
        "summary": "Delete a file",
        "operationId": "deleteFile",
        "x-required-scopes": [
          "story:write"
        ],
        "responses": {
          "204": {
            "$ref": "#/components/responses/NoContent"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/templates": {
      "get": {
        "tags": [
          "Templates"
        ],
        "summary": "List templates",
        "operationId": "listTemplates",
        "x-required-scopes": [
          "story:read"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/TemplateList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "post": {
        "tags": [
          "Templates"
        ],
        "summary": "Create a template",
        "operationId": "createTemplate",
        "x-required-scopes": [
          "story:write"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/JsonBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/JsonObject"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/auth/tokens": {
      "get": {
        "tags": [
          "Tokens"
        ],
        "summary": "List API tokens",
        "operationId": "listApiTokens",
        "security": [
          {
            "ClerkBearer": []
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/ApiTokenList"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      },
      "post": {
        "tags": [
          "Tokens"
        ],
        "summary": "Create an API token",
        "operationId": "createApiToken",
        "security": [
          {
            "ClerkBearer": []
          }
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/TokenCreateBody"
        },
        "responses": {
          "201": {
            "$ref": "#/components/responses/TokenCreated"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/opencode/auth/tokens/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/Id"
        }
      ],
      "delete": {
        "tags": [
          "Tokens"
        ],
        "summary": "Revoke an API token",
        "operationId": "revokeApiToken",
        "security": [
          {
            "ClerkBearer": []
          }
        ],
        "responses": {
          "204": {
            "$ref": "#/components/responses/NoContent"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiToken": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-token",
        "description": "Scoped ForLoop API token. Tokens are shown once and stored as SHA-256 hashes."
      },
      "ClerkBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Clerk session token used only to create or manage API tokens."
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Resource identifier.",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "JsonObject": {
        "type": "object",
        "description": "Draft response placeholder. The API owner must replace this with the verified resource schema.",
        "additionalProperties": true
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "TokenCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Descriptive token name."
          },
          "expiresIn": {
            "type": "string",
            "enum": [
              "7d",
              "30d",
              "90d",
              "1y"
            ]
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "sprint:read",
                "sprint:write",
                "story:read",
                "story:write",
                "story:delete",
                "agent:read",
                "agent:query",
                "profile:read",
                "profile:write",
                "organization:read",
                "organization:write",
                "organization:delete",
                "secrets:read",
                "secrets:write",
                "catalog:admin",
                "admin:panel",
                "a2a:read",
                "a2a:write"
              ]
            }
          }
        },
        "additionalProperties": false
      },
      "TokenCreated": {
        "type": "object",
        "required": [
          "token",
          "tokenId",
          "name",
          "expiresAt",
          "scopes"
        ],
        "properties": {
          "token": {
            "type": "string",
            "description": "Plaintext token; shown only once."
          },
          "tokenId": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "additionalProperties": true
      },
      "Sprint": {
        "type": "object",
        "required": [
          "id",
          "title",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "startDate": {
            "type": "string",
            "format": "date-time"
          },
          "endDate": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "description": "app, personal_agent, or system"
          },
          "isPrivate": {
            "type": "boolean"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownerId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "organizationId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "deletedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "publicId": {
            "type": "string",
            "format": "uuid"
          },
          "stories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Story"
            }
          },
          "deployUrls": {
            "type": "object",
            "additionalProperties": true
          },
          "_count": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "Story": {
        "type": "object",
        "required": [
          "id",
          "title",
          "status",
          "sprintId",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "points": {
            "type": [
              "integer",
              "null"
            ]
          },
          "priority": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "sprintId": {
            "type": "integer"
          },
          "subSprintId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "assigneeId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "userId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "assigneeType": {
            "type": "string",
            "description": "user or agent"
          },
          "assigneeAgentKey": {
            "type": [
              "string",
              "null"
            ]
          },
          "isAutopilot": {
            "type": "boolean"
          },
          "metadata": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "deletedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "additionalProperties": true
      },
      "StoryComment": {
        "type": "object",
        "required": [
          "id",
          "storyId",
          "authorType",
          "body",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "storyId": {
            "type": "integer"
          },
          "authorType": {
            "type": "string"
          },
          "authorAgentKey": {
            "type": [
              "string",
              "null"
            ]
          },
          "authorUserId": {
            "type": [
              "integer",
              "null"
            ]
          },
          "body": {
            "type": "string"
          },
          "metadata": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "processedByAI": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "aiClassification": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "additionalProperties": true
      },
      "AiAgent": {
        "type": "object",
        "required": [
          "key",
          "name",
          "description",
          "category"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "icon": {
            "type": [
              "string",
              "null"
            ]
          },
          "category": {
            "type": "string"
          },
          "capabilities": {
            "type": "string",
            "description": "JSON-encoded capability object"
          },
          "defaultEnabled": {
            "type": "boolean"
          }
        },
        "additionalProperties": true
      },
      "AiAgentsResponse": {
        "type": "object",
        "required": [
          "agents"
        ],
        "properties": {
          "agents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AiAgent"
            }
          }
        },
        "additionalProperties": true
      },
      "AITask": {
        "type": "object",
        "required": [
          "id",
          "sprintId",
          "status",
          "taskType",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "sprintId": {
            "type": "integer"
          },
          "userId": {
            "type": "integer"
          },
          "requestContent": {
            "type": "string"
          },
          "responseContent": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string"
          },
          "processingTime": {
            "type": [
              "integer",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "branchName": {
            "type": [
              "string",
              "null"
            ]
          },
          "commitSha": {
            "type": [
              "string",
              "null"
            ]
          },
          "mergeRequestNumber": {
            "type": [
              "integer",
              "null"
            ]
          },
          "mergeRequestUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "taskType": {
            "type": "string"
          },
          "errorMessage": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "additionalProperties": true
      },
      "AITaskList": {
        "type": "object",
        "required": [
          "data",
          "pagination"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AITask"
            }
          },
          "pagination": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer"
              },
              "limit": {
                "type": "integer"
              },
              "total": {
                "type": "integer"
              },
              "totalPages": {
                "type": "integer"
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "UserProfile": {
        "type": "object",
        "required": [
          "id",
          "name",
          "email",
          "tier"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "bio": {
            "type": [
              "string",
              "null"
            ]
          },
          "avatarUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "tier": {
            "type": "string"
          },
          "credits": {
            "type": "object",
            "properties": {
              "accountId": {
                "type": "string"
              },
              "available": {
                "type": "integer"
              },
              "reserved": {
                "type": "integer"
              },
              "spent": {
                "type": "integer"
              },
              "spendCap": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "Quotas": {
        "type": "object",
        "required": [
          "tier",
          "limits",
          "usage",
          "remaining"
        ],
        "properties": {
          "tier": {
            "type": "string"
          },
          "limits": {
            "type": "object",
            "additionalProperties": true
          },
          "usage": {
            "type": "object",
            "additionalProperties": true
          },
          "remaining": {
            "type": "object",
            "additionalProperties": true
          },
          "ownedOrgsUsage": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "systemOrgId": {
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "additionalProperties": true
      },
      "Organization": {
        "type": "object",
        "required": [
          "id",
          "name",
          "type",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "deletedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "members": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "role": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      },
      "Template": {
        "type": "object",
        "required": [
          "id",
          "name",
          "description",
          "fields",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": "string"
          },
          "fields": {
            "type": "string",
            "description": "JSON-encoded field definitions"
          },
          "storyType": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "deletedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "additionalProperties": true
      },
      "ApiToken": {
        "type": "object",
        "required": [
          "id",
          "name",
          "scopes",
          "expiresAt",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "additionalProperties": true
      },
      "SprintList": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Sprint"
        }
      },
      "StoryCommentList": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/StoryComment"
        }
      },
      "OrganizationList": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Organization"
        }
      },
      "TemplateList": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Template"
        }
      },
      "ApiTokenList": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/ApiToken"
        }
      }
    },
    "requestBodies": {
      "JsonBody": {
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/JsonObject"
            }
          }
        }
      },
      "TokenCreateBody": {
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TokenCreate"
            }
          }
        }
      }
    },
    "responses": {
      "JsonObject": {
        "description": "Successful response. Draft placeholder schema; verify against the implementation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/JsonObject"
            }
          }
        }
      },
      "JsonArray": {
        "description": "Successful response. Draft placeholder schema; verify against the implementation.",
        "content": {
          "application/json": {
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/JsonObject"
              }
            }
          }
        }
      },
      "TokenCreated": {
        "description": "Token created. The plaintext token is returned once.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TokenCreated"
            }
          }
        }
      },
      "NoContent": {
        "description": "Resource deleted or revoked."
      },
      "BadRequest": {
        "description": "Invalid request parameters.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid authentication.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The token lacks the required scope.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ServerError": {
        "description": "Internal server error.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Sprint": {
        "description": "Sprint resource.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Sprint"
            }
          }
        }
      },
      "SprintList": {
        "description": "Sprint list.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/SprintList"
            }
          }
        }
      },
      "Story": {
        "description": "Story resource.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Story"
            }
          }
        }
      },
      "StoryComment": {
        "description": "Story comment.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/StoryComment"
            }
          }
        }
      },
      "StoryCommentList": {
        "description": "Story comments.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/StoryCommentList"
            }
          }
        }
      },
      "AiAgents": {
        "description": "Available AI agents.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AiAgentsResponse"
            }
          }
        }
      },
      "AITaskList": {
        "description": "AI tasks.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/AITaskList"
            }
          }
        }
      },
      "UserProfile": {
        "description": "Current user profile.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/UserProfile"
            }
          }
        }
      },
      "Quotas": {
        "description": "Quota limits and usage.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Quotas"
            }
          }
        }
      },
      "Organization": {
        "description": "Organization resource.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Organization"
            }
          }
        }
      },
      "OrganizationList": {
        "description": "Organization list.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/OrganizationList"
            }
          }
        }
      },
      "TemplateList": {
        "description": "Template list.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TemplateList"
            }
          }
        }
      },
      "ApiTokenList": {
        "description": "API tokens.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ApiTokenList"
            }
          }
        }
      }
    }
  }
}
