From ffe46e6a56345edd02b0fb6f85c0b4617fa81149 Mon Sep 17 00:00:00 2001 From: Chris Varenhorst Date: Mon, 26 May 2025 14:52:02 -0700 Subject: [PATCH] Set 10-second timeout when requesting model prices otherwise on a very slow connection, like the in-flight wifi I'm on, the request can hang indefinitely. --- tokencost/constants.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tokencost/constants.py b/tokencost/constants.py index 619ef5a..1ad6a75 100644 --- a/tokencost/constants.py +++ b/tokencost/constants.py @@ -34,7 +34,8 @@ async def fetch_costs(): Raises: Exception: If the request fails. """ - async with aiohttp.ClientSession(trust_env=True) as session: + timeout = aiohttp.ClientTimeout(total=10) # 10 seconds timeout + async with aiohttp.ClientSession(trust_env=True, timeout=timeout) as session: async with session.get(PRICES_URL) as response: if response.status == 200: return await response.json(content_type=None)