MCPcopy Index your code
hub / github.com/AsyncFuncAI/deepwiki-open / LiteLLMClient

Class LiteLLMClient

api/litellm_client.py:8–67  ·  view source on GitHub ↗

LiteLLM OpenAI-compatible client. LiteLLM exposes an OpenAI-compatible API surface, so we can reuse almost all OpenAIClient behavior while overriding only the client initialization. Expected environment variables: LITELLM_BASE_URL=http://litellm:4000 LITELLM_API_KEY=s

Source from the content-addressed store, hash-verified

6
7
8class LiteLLMClient(OpenAIClient):
9 """
10 LiteLLM OpenAI-compatible client.
11
12 LiteLLM exposes an OpenAI-compatible API surface, so we can
13 reuse almost all OpenAIClient behavior while overriding only
14 the client initialization.
15
16 Expected environment variables:
17
18 LITELLM_BASE_URL=http://litellm:4000
19 LITELLM_API_KEY=sk-1234
20
21 Example model names:
22 openai/gpt-4o
23 anthropic/claude-3-5-sonnet
24 gemini/gemini-2.5-pro
25 ollama/llama3
26 """
27
28 def __init__(
29 self,
30 api_key: Optional[str] = None,
31 chat_completion_parser: Optional[Callable] = None,
32 input_type: str = "text",
33 base_url: Optional[str] = None,
34 env_base_url_name: str = "LITELLM_BASE_URL",
35 env_api_key_name: str = "LITELLM_API_KEY",
36 ):
37 resolved_base_url = base_url or os.getenv(env_base_url_name, "http://localhost:4000")
38 if not resolved_base_url.endswith("/v1"):
39 resolved_base_url = f"{resolved_base_url.rstrip('/')}/v1"
40 super().__init__(
41 api_key=api_key,
42 chat_completion_parser=chat_completion_parser,
43 input_type=input_type,
44 base_url=resolved_base_url,
45 env_base_url_name=env_base_url_name,
46 env_api_key_name=env_api_key_name,
47 )
48
49 def init_sync_client(self):
50 """
51 Initialize synchronous LiteLLM OpenAI-compatible client.
52 """
53 api_key = self._api_key or os.getenv(self._env_api_key_name, "dummy")
54 return OpenAI(
55 api_key=api_key,
56 base_url=self.base_url,
57 )
58
59 def init_async_client(self):
60 """
61 Initialize asynchronous LiteLLM OpenAI-compatible client.
62 """
63 api_key = self._api_key or os.getenv(self._env_api_key_name, "dummy")
64 return AsyncOpenAI(
65 api_key=api_key,

Callers 1

handle_websocket_chatFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected