Jenkins tests fail before API container is ready

When I run the test job, one time the job works and the other time it fails, because the API is not available at the time the tests start. I’m trying to use a script to check it but I’m still getting this error.