tokencost icon indicating copy to clipboard operation
tokencost copied to clipboard

Add support for proxy servers

Open caramdache opened this issue 1 year ago • 2 comments

Add trust_env=True so that AIOHTTP will use the proxy server defined in the environment, if any.

If this is not done, the following import will result in a (long) timeout:

from tokencost import calculate_prompt_cost, calculate_completion_cost

caramdache avatar Aug 26 '24 14:08 caramdache

@caramdache Just saw this--- can you clarify what you mean and/or raise a PR? Seems like a simple fix?

areibman avatar Sep 22 '24 18:09 areibman

It's not such a good idea to have imports that make HTTP calls, as it may be slow or even timeout. Or you could even be behind a proxy server. You need to at least let the http library access the environnement to get the address of the proxy server. Hence the patch. Without it the import will stall for a few minutes before timing out and failing.

caramdache avatar Sep 22 '24 20:09 caramdache

Sorry for sitting on this for a while-- merged. Thanks @caramdache !

areibman avatar Oct 17 '24 06:10 areibman