Skip to content

Commit f4a1a3a

Browse files
feat(client): enable setting base URL from environment variable
1 parent 797348a commit f4a1a3a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/openai/client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class Client < OpenAI::Internal::Transport::BaseClient
8686
#
8787
# @param project [String, nil] Defaults to `ENV["OPENAI_PROJECT_ID"]`
8888
#
89-
# @param base_url [String, nil] Override the default base URL for the API, e.g., `"https://api.example.com/v2/"`
89+
# @param base_url [String, nil] Override the default base URL for the API, e.g.,
90+
# `"https://api.example.com/v2/"`. Defaults to `ENV["OPENAI_BASE_URL"]`
9091
#
9192
# @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
9293
#
@@ -99,7 +100,7 @@ def initialize(
99100
api_key: ENV["OPENAI_API_KEY"],
100101
organization: ENV["OPENAI_ORG_ID"],
101102
project: ENV["OPENAI_PROJECT_ID"],
102-
base_url: nil,
103+
base_url: ENV["OPENAI_BASE_URL"],
103104
max_retries: DEFAULT_MAX_RETRIES,
104105
timeout: DEFAULT_TIMEOUT_IN_SECONDS,
105106
initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY,

rbi/lib/openai/client.rbi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ module OpenAI
8989
organization: ENV["OPENAI_ORG_ID"],
9090
# Defaults to `ENV["OPENAI_PROJECT_ID"]`
9191
project: ENV["OPENAI_PROJECT_ID"],
92-
# Override the default base URL for the API, e.g., `"https://api.example.com/v2/"`
93-
base_url: nil,
92+
# Override the default base URL for the API, e.g.,
93+
# `"https://api.example.com/v2/"`. Defaults to `ENV["OPENAI_BASE_URL"]`
94+
base_url: ENV["OPENAI_BASE_URL"],
9495
# Max number of retries to attempt after a failed retryable request.
9596
max_retries: DEFAULT_MAX_RETRIES,
9697
timeout: DEFAULT_TIMEOUT_IN_SECONDS,

0 commit comments

Comments
 (0)