<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def api_config(self, stage=None):
 """Create api config based on stage."""

        if stage in self.known_api_configurations:
            return self.known_api_configurations[stage]

        if not stage:
            section = 'stages.live'
            api_url = 'https://api.amaas.com/'
        else:
            section = 'stages.{}'.format(stage)
            try:
                api_url = self.lookup(section, 'api_url')
            except ConfigurationError:
                api_url = 'https://api-{}.dev.amaas.com/'.format(stage)

        return APIConfig(api_url)