diff --git a/Cargo.toml b/Cargo.toml index f80ee05..fdee45d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openai-api-rs" -version = "0.1.11" +version = "0.1.12" edition = "2021" authors = ["Dongri Jin "] license = "MIT" diff --git a/README.md b/README.md index 471abbf..70bcd3f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # OpenAI API client library for Rust (unofficial) The OpenAI API client Rust library provides convenient access to the OpenAI API from Rust applications. -Check out the [docs.rs](https://docs.rs/openai-api-rs/0.1.11/openai_api_rs/v1/index.html). +Check out the [docs.rs](https://docs.rs/openai-api-rs/). ## Installation: Cargo.toml ```toml [dependencies] -openai-api-rs = "0.1.11" +openai-api-rs = "0.1" ``` ## Usage @@ -18,6 +18,11 @@ The library needs to be configured with your account's secret key, which is avai $ export OPENAI_API_KEY=sk-xxxxxxx ``` +### Set OPENAI_API_ENDPOINT to environment variable (optional) +```bash +$ export OPENAI_API_ENDPOINT=https://api.openai.com/v1 +``` + ### Create client ```rust use openai_api_rs::v1::api::Client; diff --git a/src/v1/api.rs b/src/v1/api.rs index c04925b..5d35707 100644 --- a/src/v1/api.rs +++ b/src/v1/api.rs @@ -35,7 +35,9 @@ pub struct Client { impl Client { pub fn new(api_key: String) -> Self { - Self::new_with_endpoint(API_URL_V1.to_owned(), api_key) + let endpoint = + std::env::var("OPENAI_API_ENDPOINT").unwrap_or_else(|_| API_URL_V1.to_owned()); + Self::new_with_endpoint(endpoint, api_key) } pub fn new_with_endpoint(api_endpoint: String, api_key: String) -> Self {