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

# Estimate the sample size and duration of an A/B test

> Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of an A/B test based on historical traffic.

**Required ACL:** `analytics`

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  // Initialize the client
  var client = new AbtestingV3Client(
    new AbtestingV3Config(
      "ALGOLIA_APPLICATION_ID",
      "ALGOLIA_API_KEY",
      "ALGOLIA_APPLICATION_REGION"
    )
  );

  // Call the API
  var response = await client.EstimateABTestAsync(
    new EstimateABTestRequest
    {
      Configuration = new EstimateConfiguration
      {
        MinimumDetectableEffect = new MinimumDetectableEffect
        {
          Size = 0.03,
          Metric = Enum.Parse<EffectMetric>("ConversionRate"),
        },
      },
      Variants = new List<AddABTestsVariant>
      {
        new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 50 }),
        new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50 }),
      },
    }
  );

  // print the response
  Console.WriteLine(response);
  ```

  ```dart Dart theme={"system"}
  // Initialize the client
  final client = AbtestingV3Client(
      appId: 'ALGOLIA_APPLICATION_ID',
      apiKey: 'ALGOLIA_API_KEY',
      region: 'ALGOLIA_APPLICATION_REGION');

  // Call the API
  final response = await client.estimateABTest(
    estimateABTestRequest: EstimateABTestRequest(
      configuration: EstimateConfiguration(
        minimumDetectableEffect: MinimumDetectableEffect(
          size: 0.03,
          metric: EffectMetric.fromJson("conversionRate"),
        ),
      ),
      variants: [
        AbTestsVariant(
          index: "AB_TEST_1",
          trafficPercentage: 50,
        ),
        AbTestsVariant(
          index: "AB_TEST_2",
          trafficPercentage: 50,
        ),
      ],
    ),
  );

  // print the response
  print(response);
  ```

  ```go Go theme={"system"}
  // 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
  response, err := client.EstimateABTest(client.NewApiEstimateABTestRequest(

    abtestingV3.NewEmptyEstimateABTestRequest().SetConfiguration(
      abtestingV3.NewEmptyEstimateConfiguration().SetMinimumDetectableEffect(
        abtestingV3.NewEmptyMinimumDetectableEffect().SetSize(0.03).SetMetric(abtestingV3.EffectMetric("conversionRate")))).SetVariants(
      []abtestingV3.AddABTestsVariant{*abtestingV3.AbTestsVariantAsAddABTestsVariant(
        abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(50)), *abtestingV3.AbTestsVariantAsAddABTestsVariant(
        abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))})))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


  // print the response
  print(response)
  ```

  ```java Java theme={"system"}
  // Initialize the client
  AbtestingV3Client client = new AbtestingV3Client("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");

  // Call the API
  EstimateABTestResponse response = client.estimateABTest(
    new EstimateABTestRequest()
      .setConfiguration(
        new EstimateConfiguration().setMinimumDetectableEffect(
          new MinimumDetectableEffect().setSize(0.03).setMetric(EffectMetric.CONVERSION_RATE)
        )
      )
      .setVariants(
        Arrays.asList(
          new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(50),
          new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50)
        )
      )
  );

  // print the response
  System.out.println(response);
  ```

  ```js JavaScript theme={"system"}
  // 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
  const response = await client.estimateABTest({
    configuration: { minimumDetectableEffect: { size: 0.03, metric: 'conversionRate' } },
    variants: [
      { index: 'AB_TEST_1', trafficPercentage: 50 },
      { index: 'AB_TEST_2', trafficPercentage: 50 },
    ],
  });


  // print the response
  console.log(response);
  ```

  ```kotlin Kotlin theme={"system"}
  // Initialize the client
  val client =
    AbtestingV3Client(
      appId = "ALGOLIA_APPLICATION_ID",
      apiKey = "ALGOLIA_API_KEY",
      region = "ALGOLIA_APPLICATION_REGION",
    )

  // Call the API
  var response =
    client.estimateABTest(
      estimateABTestRequest =
        EstimateABTestRequest(
          configuration =
            EstimateConfiguration(
              minimumDetectableEffect =
                MinimumDetectableEffect(
                  size = 0.03,
                  metric = EffectMetric.entries.first { it.value == "conversionRate" },
                )
            ),
          variants =
            listOf(
              AbTestsVariant(index = "AB_TEST_1", trafficPercentage = 50),
              AbTestsVariant(index = "AB_TEST_2", trafficPercentage = 50),
            ),
        )
    )


  // print the response
  println(response)
  ```

  ```php PHP theme={"system"}
  // Initialize the client
  $client = AbtestingV3Client::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');

  // Call the API
  $response = $client->estimateABTest(
      ['configuration' => ['minimumDetectableEffect' => ['size' => 0.03,
          'metric' => 'conversionRate',
      ],
      ],
          'variants' => [
              ['index' => 'AB_TEST_1',
                  'trafficPercentage' => 50,
              ],

              ['index' => 'AB_TEST_2',
                  'trafficPercentage' => 50,
              ],
          ],
      ],
  );


  // print the response
  var_dump($response);
  ```

  ```python Python theme={"system"}
  # 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
  response = client.estimate_ab_test(
      estimate_ab_test_request={
          "configuration": {
              "minimumDetectableEffect": {
                  "size": 0.03,
                  "metric": "conversionRate",
              },
          },
          "variants": [
              {
                  "index": "AB_TEST_1",
                  "trafficPercentage": 50,
              },
              {
                  "index": "AB_TEST_2",
                  "trafficPercentage": 50,
              },
          ],
      },
  )


  # print the response
  print(response)
  ```

  ```ruby Ruby theme={"system"}
  # Initialize the client
  client = Algolia::AbtestingV3Client.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")

  # Call the API
  response = client.estimate_ab_test(
    Algolia::AbtestingV3::EstimateABTestRequest.new(
      configuration: Algolia::AbtestingV3::EstimateConfiguration.new(
        minimum_detectable_effect: Algolia::AbtestingV3::MinimumDetectableEffect.new(
          size: 0.03,
          metric: "conversionRate"
        )
      ),
      variants: [
        Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 50),
        Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50)
      ]
    )
  )


  # print the response
  puts(response)
  ```

  ```scala Scala theme={"system"}
  // Initialize the client
  val client = AbtestingV3Client(
    appId = "ALGOLIA_APPLICATION_ID",
    apiKey = "ALGOLIA_API_KEY",
    region = Option("ALGOLIA_APPLICATION_REGION")
  )

  // Call the API
  val response = Await.result(
    client.estimateABTest(
      estimateABTestRequest = EstimateABTestRequest(
        configuration = EstimateConfiguration(
          minimumDetectableEffect = MinimumDetectableEffect(
            size = 0.03,
            metric = EffectMetric.withName("conversionRate")
          )
        ),
        variants = Seq(
          AbTestsVariant(
            index = "AB_TEST_1",
            trafficPercentage = 50
          ),
          AbTestsVariant(
            index = "AB_TEST_2",
            trafficPercentage = 50
          )
        )
      )
    ),
    Duration(100, "sec")
  )

  // print the response
  println(response)
  ```

  ```swift Swift theme={"system"}
  // Initialize the client
  let client = try AbtestingV3Client(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY", region: .us)

  // Call the API
  let response = try await client.estimateABTest(estimateABTestRequest: AbtestingV3EstimateABTestRequest(
      configuration: AbtestingV3EstimateConfiguration(minimumDetectableEffect: AbtestingV3MinimumDetectableEffect(
          size: 0.03,
          metric: AbtestingV3EffectMetric.conversionRate
      )),
      variants: [
          AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
              index: "AB_TEST_1",
              trafficPercentage: 50
          )),
          AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
              index: "AB_TEST_2",
              trafficPercentage: 50
          )),
      ]
  ))

  // print the response
  print(response)
  ```
</CodeGroup>

<Card icon="folder-code" horizontal="true" title="See the full API reference" arrow="true" href="/doc/rest-api/abtesting-v3/estimate-ab-test">
  For more details about input parameters
  and response fields.
</Card>
