> ## Documentation Index
> Fetch the complete documentation index at: https://docs.naturalead.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Update A/B Test

> Updates an existing A/B test. Only tests in draft status can have their
variants modified. Name and description can be updated in any status.
Requires `ab_testing:manage` permission.




## OpenAPI

````yaml PUT /api/ab-tests/{id}
openapi: 3.1.0
info:
  title: Naturalead A/B Testing API
  version: 1.0.0
  description: >
    API for managing A/B tests in the Naturalead platform. A/B tests allow you

    to compare multiple AI agent configurations by splitting lead traffic across

    variants with configurable weights. All endpoints require API key
    authentication

    and are scoped to the caller's account.
servers:
  - url: '{baseUrl}'
    description: API server
    variables:
      baseUrl:
        default: http://localhost:3001
security:
  - BearerAuth: []
tags:
  - name: A/B Testing
    description: A/B test CRUD, status management, and results
paths:
  /api/ab-tests/{id}:
    put:
      tags:
        - A/B Testing
      summary: Update A/B test
      description: |
        Updates an existing A/B test. Only tests in draft status can have their
        variants modified. Name and description can be updated in any status.
        Requires `ab_testing:manage` permission.
      operationId: updateAbTest
      parameters:
        - $ref: '#/components/parameters/AbTestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateAbTestRequest'
      responses:
        '200':
          description: A/B test updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AbTest'
        '400':
          $ref: '#/components/responses/ValidationError'
        '404':
          description: A/B test not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: A/B test not found
        '500':
          $ref: '#/components/responses/InternalError'
components:
  parameters:
    AbTestId:
      name: id
      in: path
      required: true
      description: A/B test ID (MongoDB ObjectId)
      schema:
        type: string
        example: 665a1b2c3d4e5f6a7b8c9d0e
  schemas:
    UpdateAbTestRequest:
      type: object
      description: |
        Request body for updating an A/B test. All fields are optional;
        only provided fields will be updated. Variants can only be modified
        while the test is in draft status.
      properties:
        name:
          type: string
          description: A/B test display name
        description:
          type: string
          description: Optional description of the test hypothesis
        variants:
          type: array
          items:
            $ref: '#/components/schemas/Variant'
          minItems: 2
          description: Updated variant configuration (draft status only)
    AbTest:
      type: object
      description: An A/B test comparing multiple agent configurations.
      properties:
        _id:
          type: string
          description: Unique A/B test identifier
        accountId:
          type: string
          description: Account that owns this A/B test
        name:
          type: string
          description: A/B test display name
        description:
          type: string
          description: Optional description of the test hypothesis
        status:
          type: string
          enum:
            - draft
            - running
            - paused
            - completed
          description: Current test lifecycle status
        variants:
          type: array
          items:
            $ref: '#/components/schemas/Variant'
          minItems: 2
          description: Agent configuration variants being compared
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required:
        - _id
        - accountId
        - name
        - status
        - variants
        - createdAt
        - updatedAt
    Error:
      type: object
      properties:
        error:
          type: string
      required:
        - error
    Variant:
      type: object
      description: A single variant in an A/B test, referencing an agent configuration.
      properties:
        agentConfigId:
          type: string
          description: Reference to the agent configuration for this variant
        weight:
          type: number
          description: Traffic weight for this variant (e.g., 50 for 50%)
          minimum: 1
          maximum: 100
      required:
        - agentConfigId
        - weight
  responses:
    ValidationError:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: At least two variants are required
    InternalError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Failed to process request
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        Bearer token using an API key (format: nl_live_* or nl_test_*).

````