From ae52856a622e9044031c90324fddf2c30e6039d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Mon, 28 Aug 2023 14:52:53 +0200 Subject: [PATCH] feat: added support for OPENAI_API_BASE --- .env.example | 3 ++- docs/my-website/docs/completion/supported.md | 2 ++ litellm/main.py | 7 +++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 36eff8a43..c87c2ef8f 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ # OpenAI OPENAI_API_KEY = "" +OPENAI_API_BASE = "" # Cohere COHERE_API_KEY = "" # OpenRouter @@ -18,4 +19,4 @@ REPLICATE_API_TOKEN = "" # Anthropic ANTHROPIC_API_KEY = "" # Infisical -INFISICAL_TOKEN = "" \ No newline at end of file +INFISICAL_TOKEN = "" diff --git a/docs/my-website/docs/completion/supported.md b/docs/my-website/docs/completion/supported.md index e3719938c..9988b08e7 100644 --- a/docs/my-website/docs/completion/supported.md +++ b/docs/my-website/docs/completion/supported.md @@ -17,6 +17,8 @@ liteLLM reads key naming, all keys should be named in the following format: | gpt-3.5-turbo-16k-0613 | `completion('gpt-3.5-turbo-16k-0613', messages)` | `os.environ['OPENAI_API_KEY']` | | gpt-4 | `completion('gpt-4', messages)` | `os.environ['OPENAI_API_KEY']` | +These also support the `OPENAI_API_BASE` environment variable, which can be used to specify a custom API endpoint. + ### Azure OpenAI Chat Completion Models | Model Name | Function Call | Required OS Variables | diff --git a/litellm/main.py b/litellm/main.py index 6a48c7f57..81e22fa7b 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -210,12 +210,11 @@ def completion( ): # allow user to make an openai call with a custom base openai.api_type = "openai" # note: if a user sets a custom base - we should ensure this works + # allow for the setting of dynamic and stateful api-bases api_base = ( - custom_api_base if custom_api_base is not None else litellm.api_base - ) # allow for the setting of dynamic and stateful api-bases - openai.api_base = ( - api_base if api_base is not None else "https://api.openai.com/v1" + custom_api_base or litellm.api_base or get_secret("OPENAI_API_BASE") ) + openai.api_base = api_base or "https://api.openai.com/v1" openai.api_version = None if litellm.organization: openai.organization = litellm.organization