Skip to content

Commit 8b1145d

Browse files
authored
Support organization header (tjardoo#52)
1 parent 85f67d8 commit 8b1145d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/v1/api.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Client {
2121
pub http_client: reqwest::Client,
2222
pub base_url: String,
2323
pub api_key: String,
24+
pub organization: Option<String>,
2425
}
2526

2627
impl Client {
@@ -29,6 +30,16 @@ impl Client {
2930
http_client: reqwest::Client::new(),
3031
base_url: OPENAI_API_V1_ENDPOINT.to_string(),
3132
api_key,
33+
organization: None,
34+
}
35+
}
36+
37+
pub fn new_with_organization(api_key: String, organization: String) -> Self {
38+
Self {
39+
http_client: reqwest::Client::new(),
40+
base_url: OPENAI_API_V1_ENDPOINT.to_string(),
41+
api_key,
42+
organization: Some(organization),
3243
}
3344
}
3445

@@ -46,6 +57,10 @@ impl Client {
4657
.header(reqwest::header::CONTENT_TYPE, content_type)
4758
.bearer_auth(&self.api_key);
4859

60+
if let Some(organization) = &self.organization {
61+
request = request.header("OpenAI-Organization", organization);
62+
}
63+
4964
if is_beta_feature(path) {
5065
request = request.header("OpenAI-Beta", "assistants=v1");
5166
}

0 commit comments

Comments
 (0)