<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collect_api_results(input_data, url, headers, api, batch_size, kwargs):
 """ Optionally split up a single request into a series of requests to ensure timely HTTP responses. Could eventually speed up the time required to receive a response by sending batches to the indico API concurrently """

    if batch_size:
        results = []
        for batch in batched(input_data, size=batch_size):
            try:
                result = send_request(batch, api, url, headers, kwargs)
                if isinstance(result, list):
                    results.extend(result)
                else:
                    results.append(result)
            except IndicoError as e:
                # Log results so far to file
                timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
                filename = "indico-{api}-{timestamp}.json".format(
                    api=api,
                    timestamp=timestamp
                )
                if sys.version_info > (3, 0):
                    json.dump(results, open(filename, mode='w', encoding='utf-8'), cls=NumpyEncoder)
                else:
                    json.dump(results, open(filename, mode='w'), cls=NumpyEncoder)
                raise BatchProcessingError(
                    "The following error occurred while processing your data: `{err}` "
                    "Partial results have been saved to {filename}".format(
                        err=e,
                        filename=os.path.abspath(filename)
                    )
                )
        return results
    else:
        return send_request(input_data, api, url, headers, kwargs)