def next_indexed_name(names: set[str], base: str, index: int = 0):
    """
    >>> next_indexed_name({"key_1", "key_2", "key_3", "key_6"}, "key")
    'key_4'
    """
    for i in range(1_000_000):
        name = f"{base}_{i+1}"
        if name not in names:
            index -= 1
        if index < 0:
            return name
    else:
        raise RuntimeError(f"Couldn't find a unique name. Tried 1mil. Base: {base}.")