Civix reports "Failed to locate civicrm.settings.php"
The generate:api subcommand (and a few others) require access to a working copy of CiviCRM.

To locate this, it uses a process reminiscent of drush or wp-cli. For example, if the command-line is running inside /var/www/sites/default/files/civicrm/ext/org.example.foo/, then it will perform an upward search to find the CMS root:

/var/www/sites/default/files/civicrm/ext/org.example.foo
/var/www/sites/default/files/civicrm/ext
/var/www/sites/default/files/civicrm
/var/www/sites/default/files
/var/www/sites/default
/var/www/sites
/var/www
/var


In each case, it is looking for a tell-tale sign of a CMS+Civi system. For example, in a typical Drupal installation, you'd expect to see the file sites/default/civicrm.settings.php.

There are some cases where the default search may not work correctly, e.g.


Using a new or custom CMS.
Using a multisite configuration.
Using symlinks.


The quickest way to resolve this? Don't rely on a search. Instead, tell civix specifically where to find your copy of CiviCRM by setting the variable CIVICRM_SETTINGS, e.g.

export CIVICRM_SETTINGS=/var/www/sites/default/civicrm.settings.php
civix generate:api ...


More aggressive ways to resolve this would be:


Arrange your directory structure so that it looks like a normal build (e.g. replace symlinks with real folders).
Use civibuild for your dev sites. It always produces standard builds.
Submit a patch for Civi/Cv/Bootstrap to add support for your directory structure.