Skip to content

Commit 70ab6c2

Browse files
author
Dongri Jin
authored
Merge pull request #22 from dongri/endpoint-from-env
Endpoint from env
2 parents e34bde5 + 1011c12 commit 70ab6c2

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openai-api-rs"
3-
version = "0.1.11"
3+
version = "0.1.12"
44
edition = "2021"
55
authors = ["Dongri Jin <[email protected]>"]
66
license = "MIT"

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# OpenAI API client library for Rust (unofficial)
22
The OpenAI API client Rust library provides convenient access to the OpenAI API from Rust applications.
33

4-
Check out the [docs.rs](https://docs.rs/openai-api-rs/0.1.11/openai_api_rs/v1/index.html).
4+
Check out the [docs.rs](https://docs.rs/openai-api-rs/).
55

66
## Installation:
77
Cargo.toml
88
```toml
99
[dependencies]
10-
openai-api-rs = "0.1.11"
10+
openai-api-rs = "0.1"
1111
```
1212

1313
## Usage
@@ -18,6 +18,11 @@ The library needs to be configured with your account's secret key, which is avai
1818
$ export OPENAI_API_KEY=sk-xxxxxxx
1919
```
2020

21+
### Set OPENAI_API_ENDPOINT to environment variable (optional)
22+
```bash
23+
$ export OPENAI_API_ENDPOINT=https://api.openai.com/v1
24+
```
25+
2126
### Create client
2227
```rust
2328
use openai_api_rs::v1::api::Client;

src/v1/api.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ pub struct Client {
3535

3636
impl Client {
3737
pub fn new(api_key: String) -> Self {
38-
Self::new_with_endpoint(API_URL_V1.to_owned(), api_key)
38+
let endpoint =
39+
std::env::var("OPENAI_API_ENDPOINT").unwrap_or_else(|_| API_URL_V1.to_owned());
40+
Self::new_with_endpoint(endpoint, api_key)
3941
}
4042

4143
pub fn new_with_endpoint(api_endpoint: String, api_key: String) -> Self {

0 commit comments

Comments
 (0)