Skip to content

Commit ae52856

Browse files
committed
feat: added support for OPENAI_API_BASE
1 parent 2096f9c commit ae52856

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# OpenAI
22
OPENAI_API_KEY = ""
3+
OPENAI_API_BASE = ""
34
# Cohere
45
COHERE_API_KEY = ""
56
# OpenRouter
@@ -18,4 +19,4 @@ REPLICATE_API_TOKEN = ""
1819
# Anthropic
1920
ANTHROPIC_API_KEY = ""
2021
# Infisical
21-
INFISICAL_TOKEN = ""
22+
INFISICAL_TOKEN = ""

docs/my-website/docs/completion/supported.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ liteLLM reads key naming, all keys should be named in the following format:
1717
| gpt-3.5-turbo-16k-0613 | `completion('gpt-3.5-turbo-16k-0613', messages)` | `os.environ['OPENAI_API_KEY']` |
1818
| gpt-4 | `completion('gpt-4', messages)` | `os.environ['OPENAI_API_KEY']` |
1919

20+
These also support the `OPENAI_API_BASE` environment variable, which can be used to specify a custom API endpoint.
21+
2022
### Azure OpenAI Chat Completion Models
2123

2224
| Model Name | Function Call | Required OS Variables |

litellm/main.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,11 @@ def completion(
210210
): # allow user to make an openai call with a custom base
211211
openai.api_type = "openai"
212212
# note: if a user sets a custom base - we should ensure this works
213+
# allow for the setting of dynamic and stateful api-bases
213214
api_base = (
214-
custom_api_base if custom_api_base is not None else litellm.api_base
215-
) # allow for the setting of dynamic and stateful api-bases
216-
openai.api_base = (
217-
api_base if api_base is not None else "https://api.openai.com/v1"
215+
custom_api_base or litellm.api_base or get_secret("OPENAI_API_BASE")
218216
)
217+
openai.api_base = api_base or "https://api.openai.com/v1"
219218
openai.api_version = None
220219
if litellm.organization:
221220
openai.organization = litellm.organization

0 commit comments

Comments
 (0)