async def acompletion_with_retry(
    is_chat_model: bool, max_retries: int, **kwargs: Any
) -> Any:
    """Use tenacity to retry the async completion call."""
    retry_decorator = _create_retry_decorator(max_retries=max_retries)

    @retry_decorator
    async def _completion_with_retry(**kwargs: Any) -> Any:
        if is_chat_model:
            if is_openai_v1():
                return await konko.AsyncKonko().chat.completions.create(**kwargs)
            else:
                return await konko.ChatCompletion.acreate(**kwargs)
        else:
            if is_openai_v1():
                return await konko.AsyncKonko().completions.create(**kwargs)
            else:
                return await konko.Completion.acreate(**kwargs)

    return await _completion_with_retry(**kwargs)
Use tenacity to retry the async completion call.
llama-index-integrations/llms/llama-index-llms-konko/llama_index/llms/konko/utils.py