55from typing import Any , Callable , Optional , TypeVar , cast
66
77import backoff
8- import requests
8+ import httpx
99from typing_extensions import ParamSpec
1010
1111from langfuse ._client .environment_variables import LANGFUSE_MEDIA_UPLOAD_ENABLED
@@ -29,10 +29,12 @@ def __init__(
2929 self ,
3030 * ,
3131 api_client : FernLangfuse ,
32+ httpx_client : httpx .Client ,
3233 media_upload_queue : Queue ,
3334 max_retries : Optional [int ] = 3 ,
3435 ):
3536 self ._api_client = api_client
37+ self ._httpx_client = httpx_client
3638 self ._queue = media_upload_queue
3739 self ._max_retries = max_retries
3840 self ._enabled = os .environ .get (
@@ -256,10 +258,10 @@ def _process_upload_media_job(
256258
257259 upload_start_time = time .time ()
258260 upload_response = self ._request_with_backoff (
259- requests .put ,
261+ self . _httpx_client .put ,
260262 upload_url ,
261263 headers = headers ,
262- data = data ["content_bytes" ],
264+ content = data ["content_bytes" ],
263265 )
264266 upload_time_ms = int ((time .time () - upload_start_time ) * 1000 )
265267
@@ -288,7 +290,7 @@ def _should_give_up(e: Exception) -> bool:
288290 and 400 <= e .status_code < 500
289291 and e .status_code != 429
290292 )
291- if isinstance (e , requests . exceptions . RequestException ):
293+ if isinstance (e , httpx . HTTPStatusError ):
292294 return (
293295 e .response is not None
294296 and e .response .status_code < 500
0 commit comments