from typing import Any
from typing import Optional
from typing import cast


def _grouvee_img(res: dict[str, Any]) -> Optional[str]:
    """traverse API resp and grab the thumbnail/medium iamge"""
    if img := res.get("image"):
        assert isinstance(img, dict)
        for key in ("medium_url", "thumb_url"):
            if img_url := img.get(key):
                return cast(str, img_url)
    return None