summaryrefslogtreecommitdiff
path: root/internal/llm/openrouter.go
diff options
context:
space:
mode:
authorFlorian <2320560+florianbuetow@users.noreply.github.com>2026-01-31 23:48:38 +0100
committerFlorian <2320560+florianbuetow@users.noreply.github.com>2026-01-31 23:48:38 +0100
commit22009e90a4576764687328ed3cf81efbd2813d77 (patch)
treee69b810f813955e24b79409bc27ff6b86adf11e3 /internal/llm/openrouter.go
parent7194696eb8c4c5bd50f69df96e9a6b87cec1f049 (diff)
feat: add configurable request timeout for LLM calls
Local LLMs (LM Studio, Ollama, etc.) often need more than the default 30-second timeout. Added request_timeout config option (in seconds) to [general] section and HEXAI_REQUEST_TIMEOUT env var. Original constructor signatures preserved via *WithTimeout variants, so no test changes required.
Diffstat (limited to 'internal/llm/openrouter.go')
-rw-r--r--internal/llm/openrouter.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/llm/openrouter.go b/internal/llm/openrouter.go
index 4aae398..21e3102 100644
--- a/internal/llm/openrouter.go
+++ b/internal/llm/openrouter.go
@@ -23,14 +23,21 @@ type openRouterClient struct {
}
func newOpenRouter(baseURL, model, apiKey string, defaultTemp *float64) Client {
+ return newOpenRouterWithTimeout(baseURL, model, apiKey, defaultTemp, 0)
+}
+
+func newOpenRouterWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) Client {
if strings.TrimSpace(baseURL) == "" {
baseURL = "https://openrouter.ai/api/v1"
}
if strings.TrimSpace(model) == "" {
model = "openrouter/auto"
}
+ if timeoutSec <= 0 {
+ timeoutSec = 30
+ }
return openRouterClient{
- httpClient: &http.Client{Timeout: 30 * time.Second},
+ httpClient: &http.Client{Timeout: time.Duration(timeoutSec) * time.Second},
apiKey: apiKey,
baseURL: baseURL,
defaultModel: model,