fix(ai): clamp OpenAI Responses max output token floor

closes #6265
This commit is contained in:
Armin Ronacher 2026-07-06 02:21:15 +02:00
parent fda6451a2f
commit 2e4ad6a094
3 changed files with 7 additions and 2 deletions

View file

@ -11,6 +11,7 @@
- Fixed Amazon Bedrock prompt-cache points for Claude Fable 5 and Claude Sonnet 5 ([#6235](https://github.com/earendil-works/pi/issues/6235)).
- Fixed DS4 server context overflow detection for `Prompt has ... tokens, but the configured context size is ... tokens` errors ([#6262](https://github.com/earendil-works/pi/issues/6262)).
- Fixed OpenAI Codex WebSocket sessions to rotate cached connections before the backend's 60-minute limit, avoiding connection-limit failures on long sessions ([#6268](https://github.com/earendil-works/pi/issues/6268)).
- Fixed OpenAI Responses and Azure OpenAI Responses requests to avoid sending `max_output_tokens` values below the provider minimum ([#6265](https://github.com/earendil-works/pi/issues/6265)).
- Fixed retry classification for Cloudflare 524 timeout responses ([#6239](https://github.com/earendil-works/pi/issues/6239)).
### Added

View file

@ -20,6 +20,8 @@ import { buildBaseOptions } from "./simple-options.ts";
const DEFAULT_AZURE_API_VERSION = "v1";
const AZURE_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode", "azure-openai-responses"]);
// OpenAI Responses rejects max_output_tokens below 16: https://github.com/earendil-works/pi/issues/6265
const OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
function parseDeploymentNameMap(value: string | undefined): Map<string, string> {
const map = new Map<string, string>();
@ -264,7 +266,7 @@ function buildParams(
};
if (options?.maxTokens) {
params.max_output_tokens = options?.maxTokens;
params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
}
if (options?.temperature !== undefined) {

View file

@ -25,6 +25,8 @@ import { convertResponsesMessages, convertResponsesTools, processResponsesStream
import { buildBaseOptions } from "./simple-options.ts";
const OPENAI_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
// OpenAI Responses rejects max_output_tokens below 16: https://github.com/earendil-works/pi/issues/6265
const OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
function hasHeader(headers: ProviderHeaders | undefined, name: string): boolean {
if (!headers) return false;
@ -232,7 +234,7 @@ function buildParams(model: Model<"openai-responses">, context: Context, options
};
if (options?.maxTokens) {
params.max_output_tokens = options?.maxTokens;
params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
}
if (options?.temperature !== undefined) {