From dd571b748a62c03bf9e3ace0c009b6dc554ec416 Mon Sep 17 00:00:00 2001 From: Antoine Rouquette Date: Wed, 19 Nov 2025 22:58:02 +0100 Subject: [PATCH 1/7] retrieve openai_api_base from env var OPENAI_API_BASE --- async-openai/README.md | 3 +++ async-openai/src/config.rs | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/async-openai/README.md b/async-openai/README.md index 3a266ba8..c627914a 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -46,15 +46,18 @@ Features that makes `async-openai` unique: ## Usage The library reads [API key](https://platform.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`. +The library reads [API base](https://platform.openai.com/account/api-base) from the environment variable `OPENAI_API_BASE`. ```bash # On macOS/Linux export OPENAI_API_KEY='sk-...' +export OPENAI_API_BASE='https://api.openai.com/v1' ``` ```powershell # On Windows Powershell $Env:OPENAI_API_KEY='sk-...' +$Env:OPENAI_API_BASE='https://api.openai.com/v1' ``` - Visit [examples](https://github.com/64bit/async-openai/tree/main/examples) directory on how to use `async-openai`. diff --git a/async-openai/src/config.rs b/async-openai/src/config.rs index b0703b53..7c2e22a4 100644 --- a/async-openai/src/config.rs +++ b/async-openai/src/config.rs @@ -68,7 +68,8 @@ pub struct OpenAIConfig { impl Default for OpenAIConfig { fn default() -> Self { Self { - api_base: OPENAI_API_BASE.to_string(), + api_base: std::env::var("OPENAI_API_BASE") + .unwrap_or_else(|_| OPENAI_API_BASE.to_string()), api_key: std::env::var("OPENAI_API_KEY") .or_else(|_| { std::env::var("OPENAI_ADMIN_KEY").map(|admin_key| { @@ -86,7 +87,7 @@ impl Default for OpenAIConfig { } impl OpenAIConfig { - /// Create client with default [OPENAI_API_BASE] url and default API key from OPENAI_API_KEY env var + /// Create client with default API BASE from OPENAI_API_BASE env var or [OPENAI_API_BASE] and default API key from OPENAI_API_KEY env var pub fn new() -> Self { Default::default() } @@ -198,7 +199,8 @@ pub struct AzureConfig { impl Default for AzureConfig { fn default() -> Self { Self { - api_base: Default::default(), + api_base: std::env::var("OPENAI_API_BASE") + .unwrap_or_else(|_| Default::default()), api_key: std::env::var("OPENAI_API_KEY") .unwrap_or_else(|_| "".to_string()) .into(), From aaacab1655e8824acd9a474635317dda57f85a66 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Wed, 19 Nov 2025 15:47:09 -0800 Subject: [PATCH 2/7] Update async-openai/src/config.rs --- async-openai/src/config.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/async-openai/src/config.rs b/async-openai/src/config.rs index 7c2e22a4..d4a8e395 100644 --- a/async-openai/src/config.rs +++ b/async-openai/src/config.rs @@ -199,8 +199,7 @@ pub struct AzureConfig { impl Default for AzureConfig { fn default() -> Self { Self { - api_base: std::env::var("OPENAI_API_BASE") - .unwrap_or_else(|_| Default::default()), + api_base: Default::default(), api_key: std::env::var("OPENAI_API_KEY") .unwrap_or_else(|_| "".to_string()) .into(), From cf8e2ce5bdaf142098ae4f16865cf205b662f6b2 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Wed, 19 Nov 2025 15:48:55 -0800 Subject: [PATCH 3/7] Update async-openai/README.md --- async-openai/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/async-openai/README.md b/async-openai/README.md index c627914a..9a715112 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -46,7 +46,6 @@ Features that makes `async-openai` unique: ## Usage The library reads [API key](https://platform.openai.com/account/api-keys) from the environment variable `OPENAI_API_KEY`. -The library reads [API base](https://platform.openai.com/account/api-base) from the environment variable `OPENAI_API_BASE`. ```bash # On macOS/Linux From 7e1d09684f88c7159b443398c1346498fd3c11eb Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Wed, 19 Nov 2025 15:49:10 -0800 Subject: [PATCH 4/7] Update async-openai/README.md --- async-openai/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/async-openai/README.md b/async-openai/README.md index 9a715112..d9297dea 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -50,7 +50,6 @@ The library reads [API key](https://platform.openai.com/account/api-keys) from t ```bash # On macOS/Linux export OPENAI_API_KEY='sk-...' -export OPENAI_API_BASE='https://api.openai.com/v1' ``` ```powershell From 787f220d07e9167ed13bb55af356c38b2ea265fb Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Wed, 19 Nov 2025 15:51:19 -0800 Subject: [PATCH 5/7] Update async-openai/src/config.rs --- async-openai/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async-openai/src/config.rs b/async-openai/src/config.rs index d4a8e395..2c621568 100644 --- a/async-openai/src/config.rs +++ b/async-openai/src/config.rs @@ -68,7 +68,7 @@ pub struct OpenAIConfig { impl Default for OpenAIConfig { fn default() -> Self { Self { - api_base: std::env::var("OPENAI_API_BASE") + api_base: std::env::var("OPENAI_BASE_URL") .unwrap_or_else(|_| OPENAI_API_BASE.to_string()), api_key: std::env::var("OPENAI_API_KEY") .or_else(|_| { From 9597e771eed13d4b18243309d8cee3f4dccbf72a Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Wed, 19 Nov 2025 15:52:43 -0800 Subject: [PATCH 6/7] Update async-openai/README.md --- async-openai/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/async-openai/README.md b/async-openai/README.md index d9297dea..3a266ba8 100644 --- a/async-openai/README.md +++ b/async-openai/README.md @@ -55,7 +55,6 @@ export OPENAI_API_KEY='sk-...' ```powershell # On Windows Powershell $Env:OPENAI_API_KEY='sk-...' -$Env:OPENAI_API_BASE='https://api.openai.com/v1' ``` - Visit [examples](https://github.com/64bit/async-openai/tree/main/examples) directory on how to use `async-openai`. From 3ceb06da66cb0cd6c0c63ec06e514ecec5f969d8 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Wed, 19 Nov 2025 15:55:51 -0800 Subject: [PATCH 7/7] Update async-openai/src/config.rs --- async-openai/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async-openai/src/config.rs b/async-openai/src/config.rs index 2c621568..a197342a 100644 --- a/async-openai/src/config.rs +++ b/async-openai/src/config.rs @@ -87,7 +87,7 @@ impl Default for OpenAIConfig { } impl OpenAIConfig { - /// Create client with default API BASE from OPENAI_API_BASE env var or [OPENAI_API_BASE] and default API key from OPENAI_API_KEY env var + /// Create client with default [OPENAI_API_BASE] url (can also be changed with OPENAI_BASE_URL env var) and default API key from OPENAI_API_KEY env var pub fn new() -> Self { Default::default() }