Disable post befor thank you page in "gform_after_submission" filter

i am usiing filter “gform_after_submission” to send the form data to some api ,
and according the resulat if the api failed stop the process (dont go to thank you page)
and stay on the form page and display popup with error message.

i dont know how to prevent the thank you page
may be " gform_disable_post_creation" ?
or “gform_pre_submission” is the solution ?

Instead of using gform_after_submission you will need to contact your API before the entry is created, so you can stop the submission and return a validation error. gform_validation is a good time to do that:

Closing because a support ticket was opened.