Avoid repetitive API calling in form rebuild while submitting I am calling external API in form build function. While submitting form gets rebuild and call external API again.

How can I avoid repetitive API calls in the form's build function? I used form_state-&gt;set() but it's doesn't seem to be working.
You can test whether the form is currently rebuilding using the FormStateInterface::isRebuilding method:

if (!$form_state-&gt;isRebuilding()) {
  // Contact the API
}