@@ -52,7 +52,8 @@ def __init__(
52
52
model_name : str = "gpt-3.5-turbo" ,
53
53
default_options : LiteLLMOptions | None = None ,
54
54
* ,
55
- base_url : str | None = None ,
55
+ api_base : str | None = None ,
56
+ base_url : str | None = None , # Alias for api_base
56
57
api_key : str | None = None ,
57
58
api_version : str | None = None ,
58
59
use_structured_output : bool = False ,
@@ -66,7 +67,8 @@ def __init__(
66
67
model_name: Name of the [LiteLLM supported model](https://docs.litellm.ai/docs/providers) to be used.\
67
68
Default is "gpt-3.5-turbo".
68
69
default_options: Default options to be used.
69
- base_url: Base URL of the LLM API.
70
+ api_base: Base URL of the LLM API.
71
+ base_url: Alias for api_base. If both are provided, api_base takes precedence.
70
72
api_key: API key to be used. API key to be used. If not specified, an environment variable will be used,
71
73
for more information, follow the instructions for your specific vendor in the\
72
74
[LiteLLM documentation](https://docs.litellm.ai/docs/providers).
@@ -81,7 +83,7 @@ def __init__(
81
83
for more information.
82
84
"""
83
85
super ().__init__ (model_name , default_options )
84
- self .base_url = base_url
86
+ self .api_base = api_base or base_url
85
87
self .api_key = api_key
86
88
self .api_version = api_version
87
89
self .use_structured_output = use_structured_output
@@ -187,7 +189,7 @@ async def _call_streaming(
187
189
with trace (
188
190
messages = prompt .chat ,
189
191
model = self .model_name ,
190
- base_url = self .base_url ,
192
+ base_url = self .api_base ,
191
193
api_version = self .api_version ,
192
194
response_format = response_format ,
193
195
options = options .dict (),
@@ -222,7 +224,7 @@ async def _get_litellm_response(
222
224
response = await entrypoint .acompletion (
223
225
messages = conversation ,
224
226
model = self .model_name ,
225
- base_url = self .base_url ,
227
+ base_url = self .api_base ,
226
228
api_key = self .api_key ,
227
229
api_version = self .api_version ,
228
230
response_format = response_format ,
@@ -250,6 +252,13 @@ def _get_response_format(
250
252
response_format = {"type" : "json_object" }
251
253
return response_format
252
254
255
+ @property
256
+ def base_url (self ) -> str | None :
257
+ """
258
+ Returns the base URL of the LLM API. Alias for `api_base`.
259
+ """
260
+ return self .api_base
261
+
253
262
@classmethod
254
263
def from_config (cls , config : dict [str , Any ]) -> Self :
255
264
"""
@@ -264,13 +273,18 @@ def from_config(cls, config: dict[str, Any]) -> Self:
264
273
if "router" in config :
265
274
router = litellm .router .Router (model_list = config ["router" ])
266
275
config ["router" ] = router
276
+
277
+ # Map base_url to api_base if present
278
+ if "base_url" in config and "api_base" not in config :
279
+ config ["api_base" ] = config .pop ("base_url" )
280
+
267
281
return super ().from_config (config )
268
282
269
283
def __reduce__ (self ) -> tuple [Callable , tuple ]:
270
284
config = {
271
285
"model_name" : self .model_name ,
272
286
"default_options" : self .default_options .dict (),
273
- "base_url " : self .base_url ,
287
+ "api_base " : self .api_base ,
274
288
"api_key" : self .api_key ,
275
289
"api_version" : self .api_version ,
276
290
"use_structured_output" : self .use_structured_output ,
0 commit comments