{
  "openapi": "3.0.3",
  "info": {
    "title": "Borsch API",
    "description": "AI-powered test case generation for Azure DevOps. Uses a multi-stage AI review to produce structured, categorized, automation-ready test cases from user story descriptions.",
    "version": "1.0.0",
    "contact": {
      "name": "Borsch Support",
      "email": "support@iklab.dev"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://api.iklab.dev",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/api/v1/generate": {
      "post": {
        "operationId": "generateTestCases",
        "summary": "Generate test cases",
        "description": "Generate structured test cases from a user story description using a multi-stage AI review. Each generated test case counts against your monthly usage quota.",
        "tags": [
          "Generation"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test cases generated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit, per-org usage limit, or aggregate free-tier capacity exceeded. The `title` field distinguishes them: \"Rate Limit Exceeded\", \"Usage Limit Reached\", or \"Free Tier Capacity Reached\" (retry next month, or upgrade to remove the ceiling).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "AI service temporarily unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/bug-enhance": {
      "post": {
        "summary": "Enhance a bug report",
        "description": "Turns a rough bug report into a structured one: reproduction steps, expected vs actual behaviour, environment, a suggested severity and missing-information detection. Consumes bug-enhancement credits from the organization's monthly pool.",
        "operationId": "enhanceBug",
        "tags": [
          "Bugs"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "description"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "description": "Bug title",
                    "example": "Login fails"
                  },
                  "description": {
                    "type": "string",
                    "description": "Free-text bug description",
                    "example": "Users cannot log in with a valid password since the last release."
                  },
                  "comments": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Discussion comments providing extra context"
                  },
                  "existingReproSteps": {
                    "type": "string",
                    "description": "Repro steps already written, if any"
                  },
                  "currentSeverity": {
                    "type": "string",
                    "description": "Severity currently set on the bug"
                  },
                  "systemInfo": {
                    "type": "string",
                    "description": "Environment / system details"
                  },
                  "projectKnowledge": {
                    "type": "object",
                    "description": "Project context injected into the prompt",
                    "properties": {
                      "techStack": {
                        "type": "string"
                      },
                      "uiComponents": {
                        "type": "string"
                      },
                      "businessRules": {
                        "type": "string"
                      },
                      "testingConventions": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bug report enhanced successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BugEnhanceResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit, per-org usage limit, or aggregate free-tier capacity exceeded. The `title` field distinguishes them: \"Rate Limit Exceeded\", \"Usage Limit Reached\", or \"Free Tier Capacity Reached\" (retry next month, or upgrade to remove the ceiling).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/usage": {
      "get": {
        "operationId": "getUsage",
        "summary": "Get usage and credits",
        "description": "Returns current credit usage for your organization in the current billing period.",
        "tags": [
          "Usage"
        ],
        "responses": {
          "200": {
            "description": "Usage information",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/create": {
      "post": {
        "operationId": "createApiKey",
        "summary": "Create an API key",
        "description": "Create a new API key for your organization. The full key value is returned only once — store it securely.",
        "tags": [
          "API Keys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateKeyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API key created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateKeyResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/list": {
      "get": {
        "operationId": "listApiKeys",
        "summary": "List API keys",
        "description": "List all active API keys for your organization. Key values are masked — only the last 4 characters are shown.",
        "tags": [
          "API Keys"
        ],
        "responses": {
          "200": {
            "description": "List of API keys",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKeyInfo"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/keys/revoke": {
      "post": {
        "operationId": "revokeApiKey",
        "summary": "Revoke an API key",
        "description": "Revoke an API key. The key will immediately stop working for all requests.",
        "tags": [
          "API Keys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RevokeKeyRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Key revoked successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Key revoked successfully"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Key not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/enrich-story": {
      "post": {
        "operationId": "enrichStory",
        "summary": "Enrich a User Story",
        "description": "Enriches a User Story title into a fully detailed story with description, acceptance criteria, priority, story points, risks, and definition of done. Uses a multi-stage AI review. Consumes 1 Borsch credit per enrichment.",
        "tags": [
          "Story Enrichment"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EnrichStoryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Story enriched successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrichStoryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit, per-org usage limit, or aggregate free-tier capacity exceeded. The `errorCode` field distinguishes them: `RATE_LIMITED`, `USAGE_LIMIT_REACHED`, or `FREE_TIER_CAPACITY_REACHED` (retryable next month).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/coverage-matrix": {
      "post": {
        "operationId": "buildCoverageMatrix",
        "summary": "Cross-story coverage matrix",
        "description": "Build a 4-dimension coverage heatmap across multiple stories. Detects gap clusters, cross-story dependencies, and risk areas. Free — does not consume credits.",
        "tags": [
          "Coverage"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CoverageMatrixRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Coverage matrix result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CoverageMatrixResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/sprint-coverage": {
      "post": {
        "operationId": "analyzeSprintCoverage",
        "summary": "Analyze sprint test coverage",
        "description": "Analyzes all User Stories in a sprint for test coverage gaps and risks. Returns coverage percentage, risk levels, and per-story analysis. Free — does not consume credits.",
        "tags": [
          "Coverage"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SprintCoverageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Coverage analysis result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SprintCoverageResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/validate-invest": {
      "post": {
        "operationId": "validateInvest",
        "summary": "Validate a User Story against INVEST criteria",
        "description": "Scores a User Story against the INVEST criteria (Independent, Negotiable, Valuable, Estimable, Small, Testable) with per-criterion feedback and improvement suggestions. Local heuristic — free, does not consume credits.",
        "tags": [
          "Story Quality"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ValidateInvestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "INVEST validation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidateInvestResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/split-story": {
      "post": {
        "operationId": "splitStory",
        "summary": "Detect oversized stories and suggest split strategies",
        "description": "Analyzes a User Story for complexity signals and, when it is too large, suggests split strategies (by CRUD operation, user role, UI component, AC groups, or workflow step). Local heuristic — free, does not consume credits.",
        "tags": [
          "Story Quality"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SplitStoryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Story split analysis result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SplitStoryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/score-story": {
      "post": {
        "operationId": "scoreStoryQuality",
        "summary": "Score User Story quality across multiple dimensions",
        "description": "Scores a User Story across multiple quality dimensions using a mix of local heuristics and AI analysis. Returns a 0-100 total score with per-dimension breakdown, prioritized improvement suggestions (some with one-click apply text), and a recommendation whether a holistic AI rewrite is worthwhile. AI dimension failures degrade gracefully (isPartial). Free — does not consume credits.",
        "tags": [
          "Story Quality"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScoreStoryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Story quality result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScoreStoryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/fix-story": {
      "post": {
        "operationId": "fixStory",
        "summary": "Rewrite a weak User Story with AI",
        "description": "Holistic one-click rewrite: turns a weak User Story into a well-formed one with an improved title, description, Given/When/Then acceptance criteria, and a story point estimate. Pass failingDimensions from the score-story response to target the actual problems. Consumes 1 Borsch credit per rewrite.",
        "tags": [
          "Story Quality"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FixStoryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rewritten story",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FixStoryResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit, per-org usage limit, or aggregate free-tier capacity exceeded. The `errorCode` field distinguishes them: `RATE_LIMITED`, `USAGE_LIMIT_REACHED`, or `FREE_TIER_CAPACITY_REACHED` (retryable next month).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/incident-bridge": {
      "post": {
        "operationId": "generateIncidentTests",
        "summary": "Generate regression tests from incident report",
        "description": "Converts an incident or postmortem report into targeted regression test cases using a multi-stage AI review. Consumes Borsch credits.",
        "tags": [
          "Generation"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IncidentBridgeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated regression test cases",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IncidentBridgeResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit, per-org usage limit, or aggregate free-tier capacity exceeded. The `errorCode` field distinguishes them: `RATE_LIMITED`, `USAGE_LIMIT_REACHED`, or `FREE_TIER_CAPACITY_REACHED` (retryable next month).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": []
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key prefixed with cp_. Created from the Borsch extension settings."
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "The same cp_ API key sent as `Authorization: Bearer cp_...`. Equivalent to X-API-Key — supply either one, not both."
      }
    },
    "schemas": {
      "GenerateRequest": {
        "type": "object",
        "required": [
          "title"
        ],
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 500,
            "description": "User story title",
            "example": "User can reset password via email"
          },
          "description": {
            "type": "string",
            "maxLength": 5000,
            "description": "User story description",
            "example": "As a user, I want to reset my password so I can regain access to my account."
          },
          "acceptanceCriteria": {
            "type": "string",
            "maxLength": 5000,
            "description": "Acceptance criteria text",
            "example": "- User receives reset email within 2 minutes\n- Reset link expires after 24 hours"
          },
          "comments": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string",
              "maxLength": 2000
            },
            "description": "Discussion comments for additional context"
          },
          "projectKnowledge": {
            "$ref": "#/components/schemas/ProjectKnowledge"
          },
          "settings": {
            "$ref": "#/components/schemas/GenerationSettings"
          }
        }
      },
      "ProjectKnowledge": {
        "type": "object",
        "description": "Project-specific context to improve generation quality",
        "properties": {
          "techStack": {
            "type": "string",
            "maxLength": 2000,
            "description": "Technology stack description",
            "example": "React + Node.js + PostgreSQL"
          },
          "uiComponents": {
            "type": "string",
            "maxLength": 2000,
            "description": "UI component library or patterns used",
            "example": "Material UI v5 with custom theme"
          },
          "businessRules": {
            "type": "string",
            "maxLength": 2000,
            "description": "Domain-specific business rules or constraints",
            "example": "Passwords require 8+ chars, 1 uppercase, 1 number, 1 special"
          },
          "testingConventions": {
            "type": "string",
            "maxLength": 2000,
            "description": "Testing conventions, naming patterns, or frameworks",
            "example": "Playwright + NUnit, Page Object Model pattern"
          }
        }
      },
      "GenerationSettings": {
        "type": "object",
        "description": "Generation configuration",
        "properties": {
          "maxTestCases": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "default": 5,
            "description": "Number of test cases to generate"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "positive",
                "negative",
                "edge"
              ]
            },
            "default": [
              "positive",
              "negative",
              "edge"
            ],
            "description": "Test case categories to include"
          },
          "includeAutomationHints": {
            "type": "boolean",
            "default": true,
            "description": "Include automation hints (selectors, API calls) in output"
          },
          "automationFramework": {
            "type": "string",
            "enum": [
              "playwright",
              "selenium",
              "cypress",
              "other"
            ],
            "description": "Target automation framework for framework-specific hints (Playwright Locator API, Selenium WebDriver, Cypress commands)"
          }
        }
      },
      "GenerationResponse": {
        "type": "object",
        "properties": {
          "testCases": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TestCase"
            }
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          },
          "usage": {
            "$ref": "#/components/schemas/UsageInfo"
          }
        }
      },
      "TestCase": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "description": "Test case title"
          },
          "description": {
            "type": "string",
            "description": "Brief test case description"
          },
          "category": {
            "type": "string",
            "enum": [
              "positive",
              "negative",
              "edge"
            ],
            "description": "Test case category"
          },
          "priority": {
            "type": "integer",
            "minimum": 1,
            "maximum": 4,
            "description": "Priority level: 1 (critical) to 4 (low)"
          },
          "preconditions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Required preconditions before executing"
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TestStep"
            },
            "description": "Ordered test steps"
          },
          "automationHints": {
            "type": "string",
            "nullable": true,
            "description": "Automation guidance (selectors, API calls). Null if includeAutomationHints is false."
          }
        }
      },
      "TestStep": {
        "type": "object",
        "properties": {
          "stepNumber": {
            "type": "integer",
            "description": "Step sequence number"
          },
          "action": {
            "type": "string",
            "description": "Action to perform"
          },
          "expectedResult": {
            "type": "string",
            "description": "Expected outcome of the action"
          },
          "testData": {
            "type": "string",
            "nullable": true,
            "description": "Test data to use for this step"
          }
        }
      },
      "GenerationMetadata": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "description": "AI model used for generation",
            "example": "borsch-standard"
          },
          "tokensUsed": {
            "type": "integer",
            "description": "Total tokens consumed during generation"
          },
          "generationTimeMs": {
            "type": "integer",
            "description": "Total generation time in milliseconds"
          },
          "qualityScore": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "description": "AI-assigned quality score"
          },
          "coverageGaps": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Any identified coverage gaps"
          },
          "reviewNotes": {
            "type": "string",
            "description": "AI review commentary"
          }
        }
      },
      "UsageInfo": {
        "type": "object",
        "properties": {
          "used": {
            "type": "integer",
            "description": "Test cases generated this period"
          },
          "limit": {
            "type": "integer",
            "description": "Monthly test case limit for your plan"
          },
          "remaining": {
            "type": "integer",
            "description": "Credits remaining this period"
          },
          "planId": {
            "type": "string",
            "description": "Current plan identifier",
            "example": "starter"
          }
        }
      },
      "UsageResponse": {
        "type": "object",
        "properties": {
          "used": {
            "type": "integer",
            "description": "Test cases generated this period",
            "example": 42
          },
          "limit": {
            "type": "integer",
            "description": "Monthly test case limit for your plan",
            "example": 200
          },
          "remaining": {
            "type": "integer",
            "description": "Credits remaining this period",
            "example": 158
          },
          "planId": {
            "type": "string",
            "description": "Current plan identifier",
            "example": "starter"
          },
          "periodStart": {
            "type": "string",
            "format": "date-time",
            "description": "Start of the current billing period",
            "example": "2026-04-01T00:00:00Z"
          },
          "periodEnd": {
            "type": "string",
            "format": "date-time",
            "description": "End of the current billing period",
            "example": "2026-04-30T23:59:59Z"
          }
        }
      },
      "CreateKeyRequest": {
        "type": "object",
        "required": [
          "name",
          "orgId"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Descriptive name for the API key",
            "example": "CI Pipeline Key"
          },
          "orgId": {
            "type": "string",
            "description": "Azure DevOps organization ID",
            "example": "my-organization"
          }
        }
      },
      "CreateKeyResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique key identifier",
            "example": "key_abc123"
          },
          "name": {
            "type": "string",
            "description": "Key name",
            "example": "CI Pipeline Key"
          },
          "key": {
            "type": "string",
            "description": "Full API key value. Only returned once at creation time — store securely.",
            "example": "cp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Key creation timestamp",
            "example": "2026-04-03T10:00:00Z"
          }
        }
      },
      "ApiKeyInfo": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique key identifier",
            "example": "key_abc123"
          },
          "name": {
            "type": "string",
            "description": "Key name",
            "example": "CI Pipeline Key"
          },
          "maskedKey": {
            "type": "string",
            "description": "Masked key showing only last 4 characters",
            "example": "cp_live_****************************3def"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Key creation timestamp"
          },
          "lastUsedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Last time this key was used"
          }
        }
      },
      "RevokeKeyRequest": {
        "type": "object",
        "required": [
          "keyId"
        ],
        "properties": {
          "keyId": {
            "type": "string",
            "description": "ID of the key to revoke",
            "example": "key_abc123"
          }
        }
      },
      "SprintCoverageRequest": {
        "type": "object",
        "required": [
          "orgId",
          "sprintName",
          "stories"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "sprintName": {
            "type": "string",
            "description": "Sprint/iteration path",
            "example": "MyProject\\\\Sprint 5"
          },
          "stories": {
            "type": "array",
            "description": "User Stories to analyze (with test case count from relations)",
            "items": {
              "type": "object",
              "required": [
                "id",
                "title",
                "state",
                "testCaseCount",
                "testCaseIds"
              ],
              "properties": {
                "id": {
                  "type": "integer"
                },
                "title": {
                  "type": "string"
                },
                "state": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "acceptanceCriteria": {
                  "type": "string"
                },
                "priority": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4
                },
                "storyPoints": {
                  "type": "number"
                },
                "testCaseCount": {
                  "type": "integer"
                },
                "testCaseIds": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        }
      },
      "SprintCoverageResponse": {
        "type": "object",
        "properties": {
          "sprintName": {
            "type": "string"
          },
          "totalStories": {
            "type": "integer"
          },
          "coveredStories": {
            "type": "integer"
          },
          "uncoveredStories": {
            "type": "integer"
          },
          "coveragePercentage": {
            "type": "integer",
            "description": "0-100"
          },
          "riskSummary": {
            "type": "object",
            "properties": {
              "critical": {
                "type": "integer"
              },
              "high": {
                "type": "integer"
              },
              "medium": {
                "type": "integer"
              },
              "low": {
                "type": "integer"
              }
            }
          },
          "topRisks": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "analysisTimeMs": {
            "type": "integer"
          }
        }
      },
      "IncidentBridgeRequest": {
        "type": "object",
        "required": [
          "orgId",
          "incident"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "example": "myorg"
          },
          "incident": {
            "type": "object",
            "required": [
              "title",
              "description"
            ],
            "properties": {
              "title": {
                "type": "string",
                "example": "Payment processing outage — 45min downtime"
              },
              "description": {
                "type": "string",
                "example": "Stripe webhooks stopped processing due to expired TLS certificate"
              },
              "rootCause": {
                "type": "string"
              },
              "impact": {
                "type": "string"
              },
              "affectedSystems": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "timeline": {
                "type": "string"
              },
              "resolution": {
                "type": "string"
              }
            }
          },
          "maxTestCases": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "default": 5
          }
        }
      },
      "IncidentBridgeResponse": {
        "type": "object",
        "properties": {
          "testCases": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "category": {
                  "type": "string",
                  "enum": [
                    "regression",
                    "smoke",
                    "edge"
                  ]
                },
                "priority": {
                  "type": "integer"
                },
                "incidentCoverage": {
                  "type": "string",
                  "description": "Which aspect of the incident this test covers"
                },
                "steps": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/TestStep"
                  }
                }
              }
            }
          },
          "incidentSummary": {
            "type": "string"
          },
          "preventionInsights": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          }
        }
      },
      "EnrichStoryRequest": {
        "type": "object",
        "required": [
          "orgId",
          "title"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "title": {
            "type": "string",
            "maxLength": 1000,
            "description": "Story title — the seed for enrichment",
            "example": "User can reset password via email"
          },
          "context": {
            "type": "string",
            "maxLength": 10000,
            "description": "Brief context or notes"
          },
          "existingDescription": {
            "type": "string",
            "maxLength": 50000,
            "description": "Existing description to improve (AI enhances rather than generates)"
          },
          "existingAcceptanceCriteria": {
            "type": "string",
            "maxLength": 30000,
            "description": "Existing AC to improve"
          }
        }
      },
      "EnrichStoryResponse": {
        "type": "object",
        "properties": {
          "enrichedStory": {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "description": "Full user story description"
              },
              "acceptanceCriteria": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "text": {
                      "type": "string"
                    },
                    "category": {
                      "type": "string",
                      "enum": [
                        "functional",
                        "non-functional",
                        "edge"
                      ]
                    }
                  }
                }
              },
              "priority": {
                "type": "object",
                "properties": {
                  "level": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 4
                  },
                  "justification": {
                    "type": "string"
                  }
                }
              },
              "storyPoints": {
                "type": "number",
                "description": "Fibonacci estimate (1, 2, 3, 5, 8, 13)"
              },
              "suggestedTags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "risks": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "definitionOfDone": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          },
          "usage": {
            "$ref": "#/components/schemas/UsageInfo"
          }
        }
      },
      "CoverageMatrixRequest": {
        "type": "object",
        "required": [
          "orgId",
          "stories"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "stories": {
            "type": "array",
            "maxItems": 500,
            "description": "Stories to analyze",
            "items": {
              "type": "object",
              "required": [
                "id",
                "title",
                "state",
                "testCaseCount",
                "testCaseIds"
              ],
              "properties": {
                "id": {
                  "type": "integer"
                },
                "title": {
                  "type": "string"
                },
                "state": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "acceptanceCriteria": {
                  "type": "string"
                },
                "priority": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 4
                },
                "storyPoints": {
                  "type": "number"
                },
                "testCaseCount": {
                  "type": "integer"
                },
                "testCaseIds": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        }
      },
      "CoverageMatrixResponse": {
        "type": "object",
        "properties": {
          "totalStories": {
            "type": "integer"
          },
          "overallCoverage": {
            "type": "integer",
            "description": "0-100 percentage"
          },
          "testCoverage": {
            "type": "integer"
          },
          "acCoverage": {
            "type": "integer"
          },
          "gapClusters": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "stories": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                },
                "description": {
                  "type": "string"
                }
              }
            }
          },
          "dependencies": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "storyIds": {
                  "type": "array",
                  "items": {
                    "type": "integer"
                  }
                },
                "sharedKeywords": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "analysisTimeMs": {
            "type": "integer"
          }
        }
      },
      "ValidateInvestRequest": {
        "type": "object",
        "required": [
          "orgId",
          "title"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier"
          },
          "title": {
            "type": "string",
            "maxLength": 500,
            "description": "User Story title"
          },
          "description": {
            "type": "string",
            "description": "User Story description"
          },
          "acceptanceCriteria": {
            "oneOf": [
              {
                "type": "string",
                "description": "Newline-separated acceptance criteria"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ],
            "description": "Acceptance criteria as a string or an array of strings"
          },
          "storyPoints": {
            "type": "number",
            "description": "Story point estimate (optional)"
          },
          "dependsOn": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "IDs of stories this one depends on (optional)"
          }
        }
      },
      "ValidateInvestResponse": {
        "type": "object",
        "properties": {
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "Overall INVEST score"
          },
          "pass": {
            "type": "boolean",
            "description": "Whether the story passes all criteria"
          },
          "criteria": {
            "type": "array",
            "description": "Per-criterion breakdown",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Criterion name (e.g., Independent)"
                },
                "letter": {
                  "type": "string",
                  "description": "Criterion letter (I, N, V, E, S, T)"
                },
                "score": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100
                },
                "pass": {
                  "type": "boolean"
                },
                "feedback": {
                  "type": "string"
                }
              }
            }
          },
          "summary": {
            "type": "string",
            "description": "Summary verdict"
          },
          "suggestions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Improvement suggestions"
          }
        }
      },
      "SplitStoryRequest": {
        "type": "object",
        "required": [
          "orgId",
          "title"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier"
          },
          "title": {
            "type": "string",
            "maxLength": 500,
            "description": "User Story title"
          },
          "description": {
            "type": "string",
            "description": "User Story description"
          },
          "acceptanceCriteria": {
            "oneOf": [
              {
                "type": "string",
                "description": "Newline-separated acceptance criteria"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ],
            "description": "Acceptance criteria as a string or an array of strings"
          },
          "storyPoints": {
            "type": "number",
            "description": "Story point estimate (optional)"
          },
          "maxStories": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "description": "Optional cap on suggested sub-story titles per strategy"
          }
        }
      },
      "SplitStoryResponse": {
        "type": "object",
        "properties": {
          "shouldSplit": {
            "type": "boolean",
            "description": "Whether the story should be split"
          },
          "reason": {
            "type": "string",
            "description": "Why it should/shouldn't be split"
          },
          "signals": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Complexity signals detected"
          },
          "suggestions": {
            "type": "array",
            "description": "Split strategy suggestions",
            "items": {
              "type": "object",
              "properties": {
                "strategy": {
                  "type": "string",
                  "description": "Split strategy name"
                },
                "description": {
                  "type": "string",
                  "description": "How to split"
                },
                "suggestedStories": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "Suggested sub-story titles"
                }
              }
            }
          }
        }
      },
      "ScoreStoryRequest": {
        "type": "object",
        "required": [
          "orgId",
          "story"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "story": {
            "type": "object",
            "description": "The User Story to score. At least one field must be non-empty.",
            "properties": {
              "title": {
                "type": "string",
                "maxLength": 500
              },
              "description": {
                "type": "string",
                "maxLength": 20000
              },
              "acceptanceCriteria": {
                "type": "string",
                "maxLength": 20000
              }
            }
          },
          "requiredFields": {
            "type": "object",
            "description": "Planning-field presence signals (absent fields count as not set)",
            "properties": {
              "storyPoints": {
                "type": "number",
                "description": "Story point estimate; 0 or absent counts as not set"
              },
              "priority": {
                "description": "Priority value — a text label or a numeric level (Azure DevOps sends a number); coerced to text",
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  }
                ]
              },
              "hasAreaOrSprint": {
                "type": "boolean",
                "description": "True when assigned to an area / team / board"
              },
              "hasIteration": {
                "type": "boolean",
                "description": "True when assigned to an iteration / sprint"
              }
            }
          },
          "epicContext": {
            "type": "object",
            "description": "Parent epic context. The epic alignment dimension runs only when wikiContent is non-empty.",
            "properties": {
              "title": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "wikiContent": {
                "type": "string",
                "maxLength": 20000,
                "description": "Epic wiki/documentation content"
              }
            }
          },
          "siblings": {
            "type": "array",
            "maxItems": 8,
            "description": "Sibling stories under the same feature/epic (conflict detection). Truncated to 8.",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "acceptanceCriteria": {
                  "type": "string"
                }
              }
            }
          },
          "recentStories": {
            "type": "array",
            "maxItems": 20,
            "description": "Recently created stories for duplicate detection (must not include the story being scored). Truncated to 20.",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ScoreStoryResponse": {
        "type": "object",
        "properties": {
          "totalScore": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "Weight-normalized total across the dimensions that ran"
          },
          "color": {
            "type": "string",
            "enum": [
              "red",
              "yellow",
              "green"
            ]
          },
          "label": {
            "type": "string",
            "description": "Verdict label matching the color band"
          },
          "dimensions": {
            "type": "array",
            "description": "Per-dimension breakdown",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "Stable identifier, e.g. AcceptanceCriteria"
                },
                "displayName": {
                  "type": "string"
                },
                "score": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100
                },
                "weight": {
                  "type": "number",
                  "description": "0.0-1.0; weight 0 means the dimension did not participate"
                },
                "weightedScore": {
                  "type": "number"
                },
                "hints": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "isAiPowered": {
                  "type": "boolean"
                }
              }
            }
          },
          "suggestions": {
            "type": "array",
            "description": "Prioritized improvement suggestions",
            "items": {
              "type": "object",
              "properties": {
                "priority": {
                  "type": "string",
                  "enum": [
                    "high",
                    "medium",
                    "low"
                  ]
                },
                "text": {
                  "type": "string"
                },
                "dimension": {
                  "type": "string"
                },
                "applyField": {
                  "type": "string",
                  "enum": [
                    "title",
                    "description",
                    "acceptanceCriteria"
                  ],
                  "description": "Target field for a one-click apply (absent = informational)"
                },
                "applyText": {
                  "type": "string",
                  "description": "Concrete replacement/append text"
                },
                "applyMode": {
                  "type": "string",
                  "enum": [
                    "replace",
                    "append"
                  ]
                }
              }
            }
          },
          "isPartial": {
            "type": "boolean",
            "description": "True when at least one AI dimension was skipped"
          },
          "skippedDimensions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "recommendFixAi": {
            "type": "boolean",
            "description": "True when a holistic rewrite (fix-story) is the recommended fix"
          },
          "failingDimensions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Low-scoring dimensions formatted '<DisplayName> (<score>/100)' — pass to fix-story"
          }
        }
      },
      "FixStoryRequest": {
        "type": "object",
        "required": [
          "orgId",
          "story"
        ],
        "properties": {
          "orgId": {
            "type": "string",
            "description": "Organization identifier",
            "example": "myorg"
          },
          "story": {
            "type": "object",
            "description": "The User Story to rewrite. At least one field must be non-empty.",
            "properties": {
              "title": {
                "type": "string",
                "maxLength": 500
              },
              "description": {
                "type": "string",
                "maxLength": 20000
              },
              "acceptanceCriteria": {
                "type": "string",
                "maxLength": 20000
              }
            }
          },
          "failingDimensions": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "string"
            },
            "description": "Low-scoring dimensions from the score-story response — focuses the rewrite on the actual problems"
          }
        }
      },
      "FixStoryResponse": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "description": "Rewritten story title"
          },
          "description": {
            "type": "string",
            "description": "Rewritten story description"
          },
          "acceptanceCriteria": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Rewritten acceptance criteria in Given/When/Then format"
          },
          "storyPoints": {
            "type": "number",
            "description": "Fibonacci estimate (1, 2, 3, 5, 8, 13)"
          },
          "reasoning": {
            "type": "string",
            "description": "What was changed and why"
          },
          "usage": {
            "type": "object",
            "description": "Credit usage after this rewrite (absent when usage tracking is temporarily unavailable)",
            "properties": {
              "used": {
                "type": "integer",
                "description": "Credits used this period"
              },
              "limit": {
                "type": "integer",
                "description": "Monthly credit limit for your plan"
              },
              "remaining": {
                "type": "integer",
                "description": "Credits remaining this period"
              }
            }
          }
        }
      },
      "BugEnhanceResponse": {
        "type": "object",
        "properties": {
          "enhancedTitle": {
            "type": "string",
            "description": "Rewritten, specific bug title"
          },
          "summary": {
            "type": "string",
            "description": "One-paragraph summary of the defect"
          },
          "reproSteps": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Ordered reproduction steps"
          },
          "expectedBehavior": {
            "type": "string"
          },
          "actualBehavior": {
            "type": "string"
          },
          "environment": {
            "type": "string",
            "description": "Environment details inferred from the report"
          },
          "suggestedSeverity": {
            "type": "string",
            "description": "Severity suggested by the AI",
            "example": "High"
          },
          "missingInformation": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Details the reporter still needs to supply"
          },
          "metadata": {
            "$ref": "#/components/schemas/GenerationMetadata"
          },
          "usage": {
            "$ref": "#/components/schemas/UsageInfo"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code",
                "example": "VALIDATION_ERROR"
              },
              "message": {
                "type": "string",
                "description": "Human-readable error message",
                "example": "Field 'title' is required and must not be empty."
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Generation",
      "description": "AI test case generation endpoints"
    },
    {
      "name": "Story Enrichment",
      "description": "AI-powered User Story enrichment"
    },
    {
      "name": "Coverage",
      "description": "Sprint test coverage and cross-story matrix analysis"
    },
    {
      "name": "Story Quality",
      "description": "Local heuristics for User Story quality (INVEST validation, story splitting)"
    },
    {
      "name": "Bugs",
      "description": "AI bug report enhancement"
    },
    {
      "name": "Usage",
      "description": "Credit usage and billing information"
    },
    {
      "name": "API Keys",
      "description": "API key management"
    }
  ]
}