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

# Wait for API key operation

> Wait for an API key operation to complete.

When you add, update, or delete an API key,
the changes might not be immediately visible.
This helper method lets you wait until the operation is fully processed.

## Usage

<Info>
  The Dart API client has three separate functions,
  one for each operation.
</Info>

Wait until an API key is created:

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.WaitForApiKeyAsync(
    "api-key-add-operation-test-csharp",
    Enum.Parse<ApiKeyOperation>("Add")
  );
  ```

  ```go Go theme={"system"}
  response, err := client.WaitForApiKey(
    "api-key-add-operation-test-go", search.ApiKeyOperation("add"))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  GetApiKeyResponse response = client.waitForApiKey("api-key-add-operation-test-java", ApiKeyOperation.ADD);
  ```

  ```js JavaScript theme={"system"}
  const response = await client.waitForApiKey({ key: 'api-key-add-operation-test-javascript', operation: 'add' });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.waitForApiKey(
      key = "api-key-add-operation-test-kotlin",
      operation = ApiKeyOperation.entries.first { it.value == "add" },
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->waitForApiKey(
      'api-key-add-operation-test-php',
      'add',
  );
  ```

  ```python Python theme={"system"}
  response = client.wait_for_api_key(
      key="api-key-add-operation-test-python",
      operation="add",
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.wait_for_api_key("api-key-add-operation-test-ruby", "add")
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.waitForApiKey(
      key = "api-key-add-operation-test-scala",
      operation = ApiKeyOperation.withName("add")
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.waitForApiKey(
      key: "api-key-add-operation-test-swift",
      operation: ApiKeyOperation.add
  )
  ```
</CodeGroup>

Wait until an API key is updated:

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.WaitForApiKeyAsync(
    "api-key-update-operation-test-csharp",
    Enum.Parse<ApiKeyOperation>("Update"),
    new ApiKey
    {
      Description = "my updated api key",
      Acl = new List<Acl>
      {
        Enum.Parse<Acl>("Search"),
        Enum.Parse<Acl>("AddObject"),
        Enum.Parse<Acl>("DeleteObject"),
      },
      Indexes = new List<string> { "Movies", "Books" },
      Referers = new List<string> { "*google.com", "*algolia.com" },
      Validity = 305,
      MaxQueriesPerIPPerHour = 95,
      MaxHitsPerQuery = 20,
    }
  );
  ```

  ```go Go theme={"system"}
  response, err := client.WaitForApiKey(
    "api-key-update-operation-test-go", search.ApiKeyOperation("update"), search.WithApiKey(
      search.NewEmptyApiKey().SetDescription("my updated api key").SetAcl(
        []search.Acl{search.Acl("search"), search.Acl("addObject"), search.Acl("deleteObject")}).SetIndexes(
        []string{"Movies", "Books"}).SetReferers(
        []string{"*google.com", "*algolia.com"}).SetValidity(305).SetMaxQueriesPerIPPerHour(95).SetMaxHitsPerQuery(20)))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  GetApiKeyResponse response = client.waitForApiKey(
    "api-key-update-operation-test-java",
    ApiKeyOperation.UPDATE,
    new ApiKey()
      .setDescription("my updated api key")
      .setAcl(Arrays.asList(Acl.SEARCH, Acl.ADD_OBJECT, Acl.DELETE_OBJECT))
      .setIndexes(Arrays.asList("Movies", "Books"))
      .setReferers(Arrays.asList("*google.com", "*algolia.com"))
      .setValidity(305)
      .setMaxQueriesPerIPPerHour(95)
      .setMaxHitsPerQuery(20)
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.waitForApiKey({
    key: 'api-key-update-operation-test-javascript',
    operation: 'update',
    apiKey: {
      description: 'my updated api key',
      acl: ['search', 'addObject', 'deleteObject'],
      indexes: ['Movies', 'Books'],
      referers: ['*google.com', '*algolia.com'],
      validity: 305,
      maxQueriesPerIPPerHour: 95,
      maxHitsPerQuery: 20,
    },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.waitForApiKey(
      key = "api-key-update-operation-test-kotlin",
      operation = ApiKeyOperation.entries.first { it.value == "update" },
      apiKey =
        ApiKey(
          description = "my updated api key",
          acl =
            listOf(
              Acl.entries.first { it.value == "search" },
              Acl.entries.first { it.value == "addObject" },
              Acl.entries.first { it.value == "deleteObject" },
            ),
          indexes = listOf("Movies", "Books"),
          referers = listOf("*google.com", "*algolia.com"),
          validity = 305,
          maxQueriesPerIPPerHour = 95,
          maxHitsPerQuery = 20,
        ),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->waitForApiKey(
      'api-key-update-operation-test-php',
      'update',
      ['description' => 'my updated api key',
          'acl' => [
              'search',

              'addObject',

              'deleteObject',
          ],
          'indexes' => [
              'Movies',

              'Books',
          ],
          'referers' => [
              '*google.com',

              '*algolia.com',
          ],
          'validity' => 305,
          'maxQueriesPerIPPerHour' => 95,
          'maxHitsPerQuery' => 20,
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.wait_for_api_key(
      key="api-key-update-operation-test-python",
      operation="update",
      api_key={
          "description": "my updated api key",
          "acl": [
              "search",
              "addObject",
              "deleteObject",
          ],
          "indexes": [
              "Movies",
              "Books",
          ],
          "referers": [
              "*google.com",
              "*algolia.com",
          ],
          "validity": 305,
          "maxQueriesPerIPPerHour": 95,
          "maxHitsPerQuery": 20,
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.wait_for_api_key(
    "api-key-update-operation-test-ruby",
    "update",
    Algolia::Search::ApiKey.new(
      description: "my updated api key",
      acl: ["search", "addObject", "deleteObject"],
      indexes: ["Movies", "Books"],
      referers: ["*google.com", "*algolia.com"],
      validity: 305,
      max_queries_per_ip_per_hour: 95,
      max_hits_per_query: 20
    )
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.waitForApiKey(
      key = "api-key-update-operation-test-scala",
      operation = ApiKeyOperation.withName("update"),
      apiKey = Some(
        ApiKey(
          description = Some("my updated api key"),
          acl = Seq(Acl.withName("search"), Acl.withName("addObject"), Acl.withName("deleteObject")),
          indexes = Some(Seq("Movies", "Books")),
          referers = Some(Seq("*google.com", "*algolia.com")),
          validity = Some(305),
          maxQueriesPerIPPerHour = Some(95),
          maxHitsPerQuery = Some(20)
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.waitForApiKey(
      key: "api-key-update-operation-test-swift",
      operation: ApiKeyOperation.update,
      apiKey: ApiKey(
          acl: [Acl.search, Acl.addObject, Acl.deleteObject],
          description: "my updated api key",
          indexes: ["Movies", "Books"],
          maxHitsPerQuery: 20,
          maxQueriesPerIPPerHour: 95,
          referers: ["*google.com", "*algolia.com"],
          validity: 305
      )
  )
  ```
</CodeGroup>

Wait until an API key is deleted:

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.WaitForApiKeyAsync(
    "api-key-delete-operation-test-csharp",
    Enum.Parse<ApiKeyOperation>("Delete")
  );
  ```

  ```go Go theme={"system"}
  response, err := client.WaitForApiKey(
    "api-key-delete-operation-test-go", search.ApiKeyOperation("delete"))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  GetApiKeyResponse response = client.waitForApiKey("api-key-delete-operation-test-java", ApiKeyOperation.DELETE);
  ```

  ```js JavaScript theme={"system"}
  const response = await client.waitForApiKey({ key: 'api-key-delete-operation-test-javascript', operation: 'delete' });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.waitForApiKey(
      key = "api-key-delete-operation-test-kotlin",
      operation = ApiKeyOperation.entries.first { it.value == "delete" },
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->waitForApiKey(
      'api-key-delete-operation-test-php',
      'delete',
  );
  ```

  ```python Python theme={"system"}
  response = client.wait_for_api_key(
      key="api-key-delete-operation-test-python",
      operation="delete",
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.wait_for_api_key("api-key-delete-operation-test-ruby", "delete")
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.waitForApiKey(
      key = "api-key-delete-operation-test-scala",
      operation = ApiKeyOperation.withName("delete")
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.waitForApiKey(
      key: "api-key-delete-operation-test-swift",
      operation: ApiKeyOperation.delete
  )
  ```
</CodeGroup>

## Parameters

<Tabs>
  <Tab title="C#">
    <ParamField body="key" type="string" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="ApiKeyOperation" required>
      Operation type to wait for.
      One of: `ApiKeyOperation.Add`,
      `ApiKeyOperation.Update`,
      or `ApiKeyOperation.Delete`.
    </ParamField>

    <ParamField body="apiKey" type="ApiKey">
      API key object.
      Required for `Update` operations.
      For details about the API key properties, see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="Func<int,int>">
      Returns a timeout based on the current number of iterations.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>

    <ParamField body="cancellationToken" type="CancellationToken">
      Parameter that can be used as a signal to cancel the request.
    </ParamField>
  </Tab>

  <Tab title="Dart">
    <ParamField body="key" type="string" required>
      API key to wait for.
    </ParamField>

    <ParamField body="apiKey" type="ApiKey">
      API key object with expected properties.
      Required for the `waitKeyUpdate` method.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="params" type="WaitParams">
      <Expandable defaultOpen>
        <ParamField body="maxRetries" type="int" default={50}>
          Maximum number of retries for checking the status.
        </ParamField>

        <ParamField body="timeout" type="Duration">
          Timeout in milliseconds after which an exception is thrown.
        </ParamField>

        <ParamField body="initialDelay" type="Duration" default="200 ms">
          Initial delay after which to check for the status for the first time.
        </ParamField>

        <ParamField body="maxDelay" type="Duration" default="5 s">
          Maximum delay between status checks.
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Go">
    <ParamField body="key" type="string" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="ApiKeyOperation" required>
      Operation type to wait for.
      One of: `search.API_KEY_OPERATION_ADD`,
      `search.API_KEY_OPERATION_UPDATE`,
      or `search.API_KEY_OPERATION_DELETE`.
    </ParamField>

    <ParamField body="opts..." type="WaitForApiKeyOption">
      Functional options to provide extra arguments.

      <Expandable title="available functions">
        <ParamField body="search.WithApiKey" type="function">
          **Signature:** `func(apiKey ApiKey) waitForApiKeyOption`

          API key object.
          Required for `update` operations.
          For details about the API key properties, see [Update API key](/doc/rest-api/search/update-api-key).
        </ParamField>

        <ParamField body="search.WithMaxRetries" type="function">
          **Signature:** `func(maxRetries int) iterableOption`

          Sets the maximum number of retries for this method.
        </ParamField>

        <ParamField body="search.WithTimeout" type="function">
          **Signature:** `func(count int) time.Duration`

          Returns a timeout based on the current number of iterations.
        </ParamField>

        <ParamField body="search.WithHeaderParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra header parameters for this request.
          To learn more, see [request options](/doc/libraries/sdk/request-options).
        </ParamField>

        <ParamField body="search.WithQueryParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra query parameters for this request.
          To learn more, see [request options](/doc/libraries/sdk/request-options).
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>

  <Tab title="Java">
    <ParamField body="key" type="String" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="ApiKeyOperation" required>
      Operation type to wait for.
      One of: `ApiKeyOperation.ADD`,
      `ApiKeyOperation.UPDATE`,
      or `ApiKeyOperation.DELETE`.
    </ParamField>

    <ParamField body="apiKey" type="ApiKey">
      API key object.
      Required for `UPDATE` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="function">
      **Default:** `(int retries) -> Math.min(retries * 200, 5000)`

      Returns the time between status checks based on the current number of iterations.
      By default, the initial delay is 200 milliseconds.
      With every iteration, the delay increases by 200 milliseconds,
      until a maximum of 5 seconds is reached.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="JavaScript">
    <ParamField body="key" type="string" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="string" required>
      Operation type to wait for.
      One of: `add`, `update`, or `delete`.
    </ParamField>

    <ParamField body="apiKey" type="object">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="number" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="function">
      **Default:** `(retryCount: number) -> Math.min(retryCount * 200, 5000)`

      Returns the time between status checks based on the current number of iterations.
      By default, the initial delay is 200 milliseconds.
      With every iteration, the delay increases by 200 milliseconds,
      until a maximum of 5 seconds is reached.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Kotlin">
    <ParamField body="key" type="String" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="ApiKeyOperation" required>
      Operation type to wait for.
      Can be `ApiKeyOperation.Add`,
      `ApiKeyOperation.Update`,
      or `ApiKeyOperation.Delete`.
    </ParamField>

    <ParamField body="apiKey" type="ApiKey">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="initialDelay" type="Duration" default="200 ms">
      Time after which the status is checked for the first time.
      This time is doubled after every check until it reaches the value set by `maxDelay`.
    </ParamField>

    <ParamField body="maxDelay" type="Duration" default="5 seconds">
      Maximum time to wait between status checks.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="PHP">
    <ParamField body="key" type="string" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="string" required>
      Operation type to wait for.
      One of: `add`, `update`, or `delete`.
    </ParamField>

    <ParamField body="apiKey" type="array">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="int" default={5000}>
      Number of milliseconds between status checks.
    </ParamField>

    <ParamField body="requestOptions" type="array">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Python">
    <ParamField body="key" type="str" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="str" required>
      Operation type to wait for.
      One of: `add`, `update`, or `delete`.
    </ParamField>

    <ParamField body="api_key" type="dict | ApiKey">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="max_retries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="Callable[[int], int]">
      **Default:** `min(retry_count*0.2, 5)`

      Returns the time between status checks based on the current number of iterations.
      By default, the initial delay is 200 milliseconds.
      With every iteration, the delay increases by 200 milliseconds,
      until a maximum of 5 seconds is reached.
    </ParamField>

    <ParamField body="request_options" type="dict | RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Ruby">
    <ParamField body="key" type="String" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="String" required>
      Operation type to wait for.
      One of: `add`, `update`, or `delete`.
    </ParamField>

    <ParamField body="api_key" type="ApiKey">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="max_retries" type="Integer" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="function">
      **Default:** `[retry_count * 200, 5000].min`

      Returns the time between status checks based on the current number of iterations.
      By default, the initial delay is 200 milliseconds.
      With every iteration, the delay increases by 200 milliseconds,
      until a maximum of 5 seconds is reached.
    </ParamField>

    <ParamField body="request_options" type="Hash">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Scala">
    <ParamField body="key" type="String" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="ApiKeyOperation" required>
      Operation type to wait for.
      One of: `ApiKeyOperation.Add`,
      `ApiKeyOperation.Update`,
      or `ApiKeyOperation.Delete`.
    </ParamField>

    <ParamField body="apiKey" type="Option[ApiKey]">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="delay" type="Long => Long">
      **Default:** `(retries: Long) => Math.min(retries * 200, 5000)`

      Returns the time between status checks based on the current number of iterations.
      By default, the initial delay is 200 milliseconds.
      With every iteration, the delay increases by 200 milliseconds,
      until a maximum of 5 seconds is reached.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Swift">
    <ParamField body="key" type="String" required>
      API key to wait for.
    </ParamField>

    <ParamField body="operation" type="ApiKeyOperation" required>
      Operation type to wait for.
      One of: `ApiKeyOperation.add`,
      `ApiKeyOperation.update`, or `ApiKeyOperation.delete`.
    </ParamField>

    <ParamField body="apiKey" type="ApiKey">
      API key object.
      Required for `update` operations.
      For details about the API key properties,
      see [Update API key](/doc/rest-api/search/update-api-key).
    </ParamField>

    <ParamField body="maxRetries" type="int" default={50}>
      Maximum number of retries for checking the status.
    </ParamField>

    <ParamField body="timeout" type="(int) -> TimeInterval">
      **Default:** `(retryCount) -> min(TimeInterval(retryCount) * 0.2, 5)`

      Returns the time between status checks based on the current number of iterations.
      By default, the initial delay is 200 milliseconds.
      With every iteration, the delay increases by 200 milliseconds,
      until a maximum of 5 seconds is reached.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>
</Tabs>
