Skip to content

openai-completions: no min floor on max_completion_tokens, sends 1 token → 400 Bad Request #6522

Description

@sh1ftred

What happened?

I'm using OpenAI models via a proxy and the context reported by this proxy is wrong. I've disabled auto compact for Pi so my context used is 400% of what's available haha. Becuase of this, the upstream provider is rejecting my requests with 400 Bad Request:

  Invalid 'max_output_tokens': integer below minimum value. Expected a value >= 16, but got 1 instead.

The Responses API path in Pi's code already floors to 16 (OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16), but openai-completions.ts passes the raw clamped (1 here) value through with no floor.

clampMaxTokensToContext in simple-options.ts uses MIN_MAX_TOKENS = 1 as its floor, and openai-completions.ts (lines 570-574) sends that straight to the provider.

Steps to reproduce

  1. Have a proxy configure context lower than actually served context. And have your session exceed 100% of the context window.
  2. Send another message, context estimation + 4096 safety margin pushes available to ≤ 1.
  3. Request fails with 400 from the provider.

Expected behavior

max_completion_tokens should never be sent below the provider's minimum (16). The completions path should floor it the same way the Responses API does.

Version: 80.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions