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

# Capture a variant's settings and stop the A/B test

> Captures the settings of the given variant and of the control, then stops the A/B test.

The captured settings can later be applied to the control index with the `applyVariantSettings` operation, and read back with the `getABTestSettings` operation.

The A/B test must have reached 80% of its planned duration. Earlier requests return `400`.

Settings can only be captured once per A/B test. A second request returns `409`.

`synonyms` and `enableRules` are not captured, so applying the captured settings never changes them on the control index.

**Required ACL:** `analytics`, `editSettings`


## OpenAPI

````yaml specs/abtesting-v3.yml post /3/abtests/{id}/settings/{variantId}
openapi: 3.1.0
info:
  title: A/B Testing API
  summary: >-
    The Algolia A/B Testing API lets you manage your Algolia A/B tests to
    optimize your search experience
  description: >
    ## Base URLs


    Base URLs for the A/B testing API:


    - `https://analytics.us.algolia.com`

    - `https://analytics.de.algolia.com`

    - `https://analytics.algolia.com` (routes requests to the closest of the
    above servers, based on your geographical location)


    Use the URL that matches your [analytics
    region](https://dashboard.algolia.com/account/infrastructure/analytics).


    **All requests must use HTTPS.**


    ## Availability and authentication


    Access to the A/B testing API is available as part of the [Premium or
    Elevate plans](https://www.algolia.com/pricing).


    Add these headers to authenticate requests:


    - `x-algolia-application-id`. Your Algolia application ID.

    - `x-algolia-api-key`. An API key with the necessary permissions to make the
    request.
      The required access control list (ACL) to make a request is listed in each endpoint's reference.

    You can find your application ID and API key in the [Algolia
    dashboard](https://dashboard.algolia.com/account/api-keys).


    ## Rate limits


    You can make up to **100 requests per minute per app** to the A/B testing
    API.

    The response includes headers with information about the limits.


    ## Parameters


    Query parameters must be
    [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding).

    Non-ASCII characters must be UTF-8 encoded.

    Plus characters (`+`) are interpreted as spaces.


    ## Response status and errors


    The A/B testing API returns JSON responses.

    Since JSON doesn't guarantee any specific ordering, don't rely on the order
    of attributes in the API response.


    Successful responses return `2xx` statuses. Client errors return `4xx`
    statuses. Server errors return `5xx` statuses.

    Error responses have a `message` property with more information.


    ## Version


    The current version of the A/B Testing API is version 3, indicated by the
    `/3/` in each endpoint's URL.
  version: 3.0.0
servers:
  - url: https://analytics.{region}.algolia.com
    variables:
      region:
        enum:
          - us
          - de
        default: us
  - url: https://analytics.algolia.com
security:
  - appId: []
    apiKey: []
tags:
  - name: abtest
    x-displayName: A/B testing
    description: >
      Manage A/B tests.


      A/B tests are configurations one or more indices, usually your production
      index and an index with different settings that you want to test.
externalDocs:
  url: https://www.algolia.com/doc/guides/ab-testing/what-is-ab-testing
  description: A/B testing.
paths:
  /3/abtests/{id}/settings/{variantId}:
    post:
      tags:
        - abtest
      summary: Capture a variant's settings and stop the A/B test
      description: >
        Captures the settings of the given variant and of the control, then
        stops the A/B test.


        The captured settings can later be applied to the control index with the
        `applyVariantSettings` operation, and read back with the
        `getABTestSettings` operation.


        The A/B test must have reached 80% of its planned duration. Earlier
        requests return `400`.


        Settings can only be captured once per A/B test. A second request
        returns `409`.


        `synonyms` and `enableRules` are not captured, so applying the captured
        settings never changes them on the control index.
      operationId: saveVariantSettings
      parameters:
        - $ref: '#/components/parameters/ID'
        - $ref: '#/components/parameters/VariantID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaveSettingsRequest'
      responses:
        '200':
          description: OK
          headers:
            x-ratelimit-limit:
              $ref: '#/components/headers/x-ratelimit-limit'
            x-ratelimit-remaining:
              $ref: '#/components/headers/x-ratelimit-remaining'
            x-ratelimit-reset:
              $ref: '#/components/headers/x-ratelimit-reset'
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          $ref: '#/components/responses/FeatureNotEnabled'
        '403':
          $ref: '#/components/responses/MethodNotAllowed'
        '404':
          description: A/B test, variant, or index not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBase'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
      x-codeSamples:
        - lang: csharp
          label: C#
          source: |-
            // Initialize the client
            var client = new AbtestingV3Client(
              new AbtestingV3Config(
                "ALGOLIA_APPLICATION_ID",
                "ALGOLIA_API_KEY",
                "ALGOLIA_APPLICATION_REGION"
              )
            );

            // Call the API
            await client.SaveVariantSettingsAsync(
              42,
              2,
              new SaveSettingsRequest { SaveFeaturesSettings = true }
            );
        - lang: dart
          label: Dart
          source: |-
            // Initialize the client
            final client = AbtestingV3Client(
                appId: 'ALGOLIA_APPLICATION_ID',
                apiKey: 'ALGOLIA_API_KEY',
                region: 'ALGOLIA_APPLICATION_REGION');

            // Call the API
            await client.saveVariantSettings(
              id: 42,
              variantId: 2,
              saveSettingsRequest: SaveSettingsRequest(
                saveFeaturesSettings: true,
              ),
            );
        - lang: go
          label: Go
          source: >-
            // Initialize the client with your application region, eg.
            abtestingV3.ALGOLIA_APPLICATION_REGION

            client, err := abtestingV3.NewClient("ALGOLIA_APPLICATION_ID",
            "ALGOLIA_API_KEY", abtestingV3.US)

            if err != nil {
              // The client can fail to initialize if you pass an invalid parameter.
              panic(err)
            }


            // Call the API

            err =
            client.SaveVariantSettings(client.NewApiSaveVariantSettingsRequest(
              42, 2,
              abtestingV3.NewEmptySaveSettingsRequest().SetSaveFeaturesSettings(true)))
            if err != nil {
              // handle the eventual error
              panic(err)
            }
        - lang: java
          label: Java
          source: >-
            // Initialize the client

            AbtestingV3Client client = new
            AbtestingV3Client("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY",
            "ALGOLIA_APPLICATION_REGION");


            // Call the API

            client.saveVariantSettings(42, 2, new
            SaveSettingsRequest().setSaveFeaturesSettings(true));
        - lang: javascript
          label: JavaScript
          source: >-
            // Initialize the client

            // Replace 'us' with your Algolia Application Region

            const client = algoliasearch('ALGOLIA_APPLICATION_ID',
            'ALGOLIA_API_KEY').initAbtestingV3({ region: 'us' });


            // Call the API

            await client.saveVariantSettings({ id: 42, variantId: 2,
            saveSettingsRequest: { saveFeaturesSettings: true } });
        - lang: kotlin
          label: Kotlin
          source: |-
            // Initialize the client
            val client =
              AbtestingV3Client(
                appId = "ALGOLIA_APPLICATION_ID",
                apiKey = "ALGOLIA_API_KEY",
                region = "ALGOLIA_APPLICATION_REGION",
              )

            // Call the API
            client.saveVariantSettings(
              id = 42,
              variantId = 2,
              saveSettingsRequest = SaveSettingsRequest(saveFeaturesSettings = true),
            )
        - lang: php
          label: PHP
          source: >-
            // Initialize the client

            $client = AbtestingV3Client::create('ALGOLIA_APPLICATION_ID',
            'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');


            // Call the API

            $client->saveVariantSettings(
                42,
                2,
                ['saveFeaturesSettings' => true,
                ],
            );
        - lang: python
          label: Python
          source: >-
            # Initialize the client

            # In an asynchronous context, you can use AbtestingV3Client instead,
            which exposes the exact same methods.

            client = AbtestingV3ClientSync(
                "ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
            )


            # Call the API

            client.save_variant_settings(
                id=42,
                variant_id=2,
                save_settings_request={
                    "saveFeaturesSettings": True,
                },
            )
        - lang: ruby
          label: Ruby
          source: >-
            # Initialize the client

            client = Algolia::AbtestingV3Client.create("ALGOLIA_APPLICATION_ID",
            "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")


            # Call the API

            client.save_variant_settings(42, 2,
            Algolia::AbtestingV3::SaveSettingsRequest.new(save_features_settings:
            true))
        - lang: scala
          label: Scala
          source: |-
            // Initialize the client
            val client = AbtestingV3Client(
              appId = "ALGOLIA_APPLICATION_ID",
              apiKey = "ALGOLIA_API_KEY",
              region = Option("ALGOLIA_APPLICATION_REGION")
            )

            // Call the API
            Await.result(
              client.saveVariantSettings(
                id = 42,
                variantId = 2,
                saveSettingsRequest = SaveSettingsRequest(
                  saveFeaturesSettings = Some(true)
                )
              ),
              Duration(100, "sec")
            )
        - lang: swift
          label: Swift
          source: >-
            // Initialize the client

            let client = try AbtestingV3Client(appID: "ALGOLIA_APPLICATION_ID",
            apiKey: "ALGOLIA_API_KEY", region: .us)


            // Call the API

            try await client.saveVariantSettings(
                id: 42,
                variantId: 2,
                saveSettingsRequest: SaveSettingsRequest(saveFeaturesSettings: true)
            )
        - lang: cURL
          label: curl
          source: |-
            curl --request POST \
              --url https://analytics.us.algolia.com/3/abtests/224/settings/2 \
              --header 'content-type: application/json' \
              --header 'x-algolia-api-key: ALGOLIA_API_KEY' \
              --header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
              --data '
            {
              "saveFeaturesSettings": false
            }
            '
components:
  parameters:
    ID:
      in: path
      name: id
      description: Unique A/B test identifier.
      required: true
      schema:
        $ref: '#/components/schemas/abTestID'
    VariantID:
      in: path
      name: variantId
      description: One-based index of the A/B test variant. The control is variant 1.
      required: true
      schema:
        type: integer
        minimum: 1
        example: 2
  schemas:
    SaveSettingsRequest:
      type: object
      description: Options for capturing a variant's settings.
      additionalProperties: false
      properties:
        saveFeaturesSettings:
          type: boolean
          description: >-
            Whether to also capture the variant's index settings and
            feature-specific settings. This must be true for A/B tests whose
            variants use different indices so that the captured variant settings
            can later be applied.
          default: false
    ErrorBase:
      description: Error.
      type: object
      x-keep-model: true
      additionalProperties: true
      properties:
        message:
          type: string
          example: Invalid Application-Id or API-Key
    abTestID:
      type: integer
      description: Unique A/B test identifier.
      example: 224
  headers:
    x-ratelimit-limit:
      description: Number of allowed requests per one minute.
      example: 100
      schema:
        type: integer
    x-ratelimit-remaining:
      description: Number of remaining requests in the current period.
      example: 99
      schema:
        type: integer
    x-ratelimit-reset:
      description: >-
        Timestamp when the rate limit will reset, measured in seconds since the
        Unix epoch.
      example: 1710682486
      schema:
        type: integer
  responses:
    BadRequest:
      description: Bad request or request arguments.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    FeatureNotEnabled:
      description: This feature is not enabled on your Algolia account.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    MethodNotAllowed:
      description: Method not allowed with this API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    Conflict:
      description: Conflict.
      content:
        application/json:
          schema:
            title: conflictResponse
            type: object
            additionalProperties: false
            required:
              - status
              - message
            properties:
              message:
                type: string
                example: Conflict
                description: Response message.
              status:
                type: integer
                example: 409
                description: Status code.
    UnprocessableEntity:
      description: Unprocessable Entity.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
  securitySchemes:
    appId:
      type: apiKey
      in: header
      name: x-algolia-application-id
      description: Your Algolia application ID.
    apiKey:
      type: apiKey
      in: header
      name: x-algolia-api-key
      description: >
        Your Algolia API key with the necessary permissions to make the request.

        Permissions are controlled through access control lists (ACL) and access
        restrictions.

        The required ACL to make a request is listed in each endpoint's
        reference.

````