from typing import Union
from typing import Dict
from typing import List


def build_credentials_fetch(credentials: Union[Dict, List]) -> Union[Dict, List]:
    """Formats the API response to Demisto context.

    Args:
        credentials: The raw response from the API call. Can be a List or Dict.

    Returns:
        The formatted Dict or List.

    Examples:
        >>> build_credentials_fetch([{'username': 'user1', 'name': 'name1', 'password': 'password'}])
        [{'user': 'user1', 'name': 'name1', 'password': 'password'}]
    """
    if isinstance(credentials, list):
        return [build_credentials_fetch(credential) for credential in credentials]
    return {
        'user': credentials.get('username'),
        'name': credentials.get('name'),
        'password': credentials.get('password')
    }