diff --git a/services/worker/src/analysis/openrouter.rs b/services/worker/src/analysis/openrouter.rs index 7232971..13a6ae2 100644 --- a/services/worker/src/analysis/openrouter.rs +++ b/services/worker/src/analysis/openrouter.rs @@ -8,8 +8,9 @@ use serde_json::{Value, json}; use super::prompt::{Prompt, validate}; pub const DEFAULT_BASE_URL: &str = "https://openrouter.ai/api/v1"; -/// Room for reasoning tokens as well as the answer. -const MAX_TOKENS: u32 = 16_000; +/// Room for reasoning tokens as well as the answer: reasoning models (e.g. +/// DeepSeek) think at length before answering. Only a cap, not a cost. +const MAX_TOKENS: u32 = 32_000; pub struct OpenRouter { http: reqwest::Client, @@ -143,7 +144,8 @@ fn error_message(body: &Value, fallback: &str) -> String { impl OpenRouter { pub fn new(base_url: &str, api_key: &str, referer: Option) -> Self { let http = reqwest::Client::builder() - .timeout(Duration::from_secs(300)) + // Reasoning models can take several minutes for a long analysis. + .timeout(Duration::from_secs(600)) .connect_timeout(Duration::from_secs(10)) .build() .expect("HTTP client"); @@ -203,8 +205,10 @@ impl OpenRouter { let content = extract_json(raw).ok_or_else(|| { LlmError::Transient(format!("answer is not JSON: {}", raw.chars().take(200).collect::())) })?; - validate(&prompt.schema, &content) - .map_err(|e| LlmError::Transient(format!("answer does not match the schema: {e}")))?; + validate(&prompt.schema, &content).map_err(|e| { + tracing::warn!(model, answer = %raw.chars().take(500).collect::(), "answer does not match the schema"); + LlmError::Transient(format!("answer does not match the schema: {e}")) + })?; let usage = &reply["usage"]; let tokens = |key: &str| usage[key].as_i64().and_then(|n| i32::try_from(n).ok());