import asyncio import requests CAT_API_URL = "https://api.thecatapi.com/v1/images/search" _session = requests.Session() async def fetch_cat() -> str | None: """Получить URL случайного котика. Вернуть None при ошибке.""" try: response = await asyncio.to_thread(_session.get, CAT_API_URL, timeout=10) response.raise_for_status() data = response.json() return data[0]["url"] except requests.exceptions.RequestException: return None