feat: API-Schlüssel für strata aus Umgebungsvariable

strata verlangt nach dem Start mit --access lan einen Schlüssel (HTTP 401).
Der Client liest ihn aus der Umgebungsvariable STRATA_API_KEY (Name in
config.toml änderbar) und sendet ihn als Bearer-Token. Der Schlüssel steht
weder in der Konfiguration noch im Repo.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 21:13:26 +01:00
parent f35b68ae1f
commit dce98d3d11
4 changed files with 17 additions and 7 deletions

View File

@ -559,6 +559,7 @@ impl ModelClient for OllamaClient {
pub struct OpenAiClient {
pub url: String,
pub model: String,
api_key: Option<String>,
http: reqwest::blocking::Client,
}
@ -644,13 +645,14 @@ pub fn to_openai_messages(messages: &[Message]) -> Vec<Value> {
}
impl OpenAiClient {
pub fn new(url: &str, model: &str) -> Result<OpenAiClient, String> {
pub fn new(url: &str, model: &str, api_key: Option<String>) -> Result<OpenAiClient, String> {
let http = reqwest::blocking::Client::builder()
.build()
.map_err(|e| format!("HTTP-Client nicht baubar: {e}"))?;
Ok(OpenAiClient {
url: url.trim_end_matches('/').into(),
model: model.into(),
api_key,
http,
})
}
@ -667,11 +669,11 @@ impl ModelClient for OpenAiClient {
"stream": false,
"temperature": 0,
});
let resp = self
.http
.post(&self.url)
.timeout(timeout)
.json(&body)
let mut req = self.http.post(&self.url).timeout(timeout).json(&body);
if let Some(key) = &self.api_key {
req = req.bearer_auth(key);
}
let resp = req
.send()
.map_err(|e| {
if e.is_timeout() {