From f38facd43064b8415053ef098ec3e582805962e5 Mon Sep 17 00:00:00 2001 From: Hemilt0n Date: Sun, 15 Mar 2026 20:39:17 +0800 Subject: [PATCH] fix(proxy): use max_completion_tokens for o1/o3 series models (#1451) * fix(proxy): use max_completion_tokens for o1/o3 series models When converting Anthropic requests to OpenAI format for o1/o3 series models (like o1-mini, o3-mini), use max_completion_tokens instead of max_tokens to avoid unsupported_parameter errors. Fixes #1448 * fix: revert incorrect o-series max_completion_tokens in Responses API path Responses API uses max_output_tokens for all models including o-series. The o-series max_completion_tokens fix should only apply to Chat Completions API. --------- Co-authored-by: Hajen Teowideo Co-authored-by: Jason Young <44939412+farion1231@users.noreply.github.com> Co-authored-by: Jason --- src-tauri/src/proxy/providers/transform.rs | 65 ++++++++++++++++++- .../proxy/providers/transform_responses.rs | 15 ++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/proxy/providers/transform.rs b/src-tauri/src/proxy/providers/transform.rs index 65fa4784e..3eb6f6565 100644 --- a/src-tauri/src/proxy/providers/transform.rs +++ b/src-tauri/src/proxy/providers/transform.rs @@ -6,6 +6,14 @@ use crate::proxy::error::ProxyError; use serde_json::{json, Value}; +/// Detect OpenAI o-series reasoning models (o1, o3, o4-mini, etc.) +/// These models require `max_completion_tokens` instead of `max_tokens`. +pub fn is_openai_o_series(model: &str) -> bool { + model.len() > 1 + && model.starts_with('o') + && model.as_bytes().get(1).is_some_and(|b| b.is_ascii_digit()) +} + /// Anthropic 请求 → OpenAI 请求 /// /// `cache_key`: optional prompt_cache_key to inject for improved cache routing @@ -50,9 +58,14 @@ pub fn anthropic_to_openai(body: Value, cache_key: Option<&str>) -> Result) -> Result