The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
added put method in http_handler
Haadi Rakhangic6716673c1bf
diff --cc litellm/llms/custom_httpx/http_handler.pyindex 8f841ca12b8,1828a92d2eb..de517a086ca--- a/litellm/llms/custom_httpx/http_handler.py+++ b/litellm/llms/custom_httpx/http_handler.py@@@ -113,48 -128,50 +128,106 @@@ class AsyncHTTPHandlerraise eexcept Exception as e:raise e-++ async def put(+ self,+ url: str,+ data: Optional[Union[dict, str]] = None, # type: ignore+ json: Optional[dict] = None,+ params: Optional[dict] = None,+ headers: Optional[dict] = None,++ timeout: Optional[Union[float, httpx.Timeout]] = None,+ stream: bool = False,+ ):+ try:++ if timeout is None:++ timeout = self.timeout+ req = self.client.build_request(- "PUT", url, data=data, json=json, params=params, headers=headers # type: ignore++ "PUT", url, data=data, json=json, params=params, headers=headers, timeout=timeout # type: ignore+ )+ response = await self.client.send(req, stream=stream)+ response.raise_for_status()+ return response+ except (httpx.RemoteProtocolError, httpx.ConnectError):+ # Retry the request with a new session if there is a connection error- new_client = self.create_client(timeout=self.timeout, concurrent_limit=1)++ new_client = self.create_client(timeout=timeout, concurrent_limit=1)+ try:+ return await self.single_connection_post_request(+ url=url,+ client=new_client,+ data=data,+ json=json,+ params=params,+ headers=headers,+ stream=stream,+ )+ finally:+ await new_client.aclose()++ except httpx.TimeoutException as e:++ headers = {}++ if hasattr(e, "response") and e.response is not None:++ for key, value in e.response.headers.items():++ headers["response_headers-{}".format(key)] = value++++ raise litellm.Timeout(++ message=f"Connection timed out after {timeout} seconds.",++ model="default-model-name",++ llm_provider="litellm-httpx-handler",++ headers=headers,++ )+ except httpx.HTTPStatusError as e:+ setattr(e, "status_code", e.response.status_code)+ if stream is True:+ setattr(e, "message", await e.response.aread())+ else:+ setattr(e, "message", e.response.text)+ raise e+ except Exception as e:+ raise e++ async def delete(+ self,+ url: str,+ data: Optional[Union[dict, str]] = None, # type: ignore+ json: Optional[dict] = None,+ params: Optional[dict] = None,+ headers: Optional[dict] = None,+ timeout: Optional[Union[float, httpx.Timeout]] = None,+ stream: bool = False,+ ):+ try:+ if timeout is None:+ timeout = self.timeout+ req = self.client.build_request(+ "DELETE", url, data=data, json=json, params=params, headers=headers, timeout=timeout # type: ignore+ )+ response = await self.client.send(req, stream=stream)+ response.raise_for_status()+ return response+ except (httpx.RemoteProtocolError, httpx.ConnectError):+ # Retry the request with a new session if there is a connection error+ new_client = self.create_client(timeout=timeout, concurrent_limit=1)+ try:+ return await self.single_connection_post_request(+ url=url,+ client=new_client,+ data=data,+ json=json,+ params=params,+ headers=headers,+ stream=stream,+ )+ finally:+ await new_client.aclose()+ except httpx.HTTPStatusError as e:+ setattr(e, "status_code", e.response.status_code)+ if stream is True:+ setattr(e, "message", await e.response.aread())+ else:+ setattr(e, "message", e.response.text)+ raise e+ except Exception as e:+ raise easync def single_connection_post_request(self,@@@ -234,30 -251,29 +307,61 @@@ class HTTPHandlerparams: Optional[dict] = None,headers: Optional[dict] = None,stream: bool = False,+ timeout: Optional[Union[float, httpx.Timeout]] = None,):+ try:++ if timeout is not None:+ req = self.client.build_request(+ "POST", url, data=data, json=json, params=params, headers=headers, timeout=timeout # type: ignore+ )+ else:+ req = self.client.build_request(+ "POST", url, data=data, json=json, params=params, headers=headers # type: ignore+ )+ response = self.client.send(req, stream=stream)+ return response+ except httpx.TimeoutException:+ raise litellm.Timeout(+ message=f"Connection timed out after {timeout} seconds.",+ model="default-model-name",+ llm_provider="litellm-httpx-handler",+ )+ except Exception as e:+ raise e- req = self.client.build_request(- "POST", url, data=data, json=json, params=params, headers=headers # type: ignore- )- response = self.client.send(req, stream=stream)- return response-+ def put(+ self,+ url: str,+ data: Optional[Union[dict, str]] = None,- json: Optional[dict] = None,++ json: Optional[Union[dict, str]] = None,+ params: Optional[dict] = None,+ headers: Optional[dict] = None,+ stream: bool = False,++ timeout: Optional[Union[float, httpx.Timeout]] = None,+ ):- req = self.client.build_request(- "PUT", url, data=data, json=json, params=params, headers=headers # type: ignore- )- response = self.client.send(req, stream=stream)- return response++ try:++++ if timeout is not None:++ req = self.client.build_request(++ "PUT", url, data=data, json=json, params=params, headers=headers, timeout=timeout # type: ignore++ )++ else:++ req = self.client.build_request(++ "PUT", url, data=data, json=json, params=params, headers=headers # type: ignore++ )++ response = self.client.send(req, stream=stream)++ return response++ except httpx.TimeoutException:++ raise litellm.Timeout(++ message=f"Connection timed out after {timeout} seconds.",++ model="default-model-name",++ llm_provider="litellm-httpx-handler",++ )++ except Exception as e:++ raise e++def __del__(self) -> None:try:self.close()@@@ -319,4 -335,4 +423,4 @@@ def _get_httpx_client(params: Optional[_new_client = HTTPHandler(timeout=httpx.Timeout(timeout=600.0, connect=5.0))litellm.in_memory_llm_clients_cache[_cache_key_name] = _new_client-- return _new_client++ return _new_client