We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 17b3c5e commit d882d66Copy full SHA for d882d66
tokencost/constants.py
@@ -62,8 +62,13 @@ def refresh_prices(write_file=True):
62
"""Synchronous wrapper for update_token_costs that optionally writes to model_prices.json."""
63
import asyncio
64
try:
65
- # Run the async function in a new event loop
66
- updated_costs = asyncio.run(update_token_costs())
+ # Check if an event loop is already running
+ try:
67
+ loop = asyncio.get_running_loop()
68
+ updated_costs = loop.run_until_complete(update_token_costs())
69
+ except RuntimeError:
70
+ # No running loop, safe to use asyncio.run
71
+ updated_costs = asyncio.run(update_token_costs())
72
73
# Write to file if requested
74
if write_file:
0 commit comments