def _check_key(
    k: str, v: Optional[str] = None, silent: bool = False, warn: bool = False
) -> bool:
    """
    Check that the given `k` is an env var with a value that indicates a valid
    api key or secret.  If `v` is provided, checks that instead. If value
    indicates the key is not set, raises an informative error telling the user
    options on how to set that key. If `silent` is set, nothing will be printed.
    If `warn` is set, will log warning to logger and not throw an exception.
    Returns True if key is set. Silent disable warning logging.
    """

    v = v or os.environ.get(k)

    if not v or not _value_is_set(v):
        msg = f"""Key {k} needs to be set; please provide it in one of these ways:

  - in a variable {k} prior to this check,
  - in your variable environment,
  - in a .env file in {Path.cwd()} or its parents,
  - explicitly passed to function `check_or_set_keys` of `trulens.core.utils.keys`,
  - passed to the endpoint or feedback collection constructor that needs it (`trulens.providers.openai.endpoint.OpenAIEndpoint`, etc.), or
  - set in api utility class that expects it (i.e. `OpenAI(api_key=)`, etc.).

For the last two options, the name of the argument may differ from {k} (i.e. `OpenAI(api_key=)` for `OPENAI_API_KEY`).
"""
        if not silent:
            print(f"{text_utils.UNICODE_STOP} {msg}")
            if warn:
                logger.warning(msg)
        else:
            if warn:
                return False
            else:
                raise ApiKeyError(msg, key=k)

    return True

    Check that the given `k` is an env var with a value that indicates a valid
    api key or secret.  If `v` is provided, checks that instead. If value
    indicates the key is not set, raises an informative error telling the user
    options on how to set that key. If `silent` is set, nothing will be printed.
    If `warn` is set, will log warning to logger and not throw an exception.
    Returns True if key is set. Silent disable warning logging.
    
src/core/trulens/core/utils/keys.py