Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/kestrel-providers/src/openai_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ impl OpenAiCompatProvider {
});

if let Some(max_tokens) = request.max_tokens {
body["max_tokens"] = json!(max_tokens);
let effective = if is_reasoning_model(&request.model) {
max_tokens.max(16384)
} else {
max_tokens
};
body["max_tokens"] = json!(effective);
}
if let Some(temp) = request.temperature {
body["temperature"] = json!(temp);
Expand Down Expand Up @@ -381,6 +386,19 @@ fn build_openai_tool_call_deltas(
Some(deltas)
}

/// Check if a model is a known reasoning model that uses thinking tokens.
///
/// Reasoning models consume `max_tokens` budget with thinking/reasoning tokens.
/// We auto-inflate the budget so thinking doesn't crowd out actual content.
fn is_reasoning_model(model: &str) -> bool {
let m = model.to_lowercase();
m.contains("glm-5")
|| m.starts_with("deepseek-r")
|| m.starts_with("o1")
|| m.starts_with("o3")
|| m.starts_with("o4")
}

#[derive(Debug, Deserialize)]
struct OpenAiResponse {
choices: Vec<OpenAiChoice>,
Expand Down
Loading