AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ChatOpenAI Forwards 'Stop' For O3/O4-Mini Causing HTTP 400

When using langchain-openai with model o3 or o4-mini, passing a non-empty stop parameter results in a 400 error from OpenAI. The library does not validate unsupported parameters for these models.

highConfidence 95%LangChainAffected V1.6.6

Origin Analysis

ChatOpenAI in langchain-openai does not perform model-specific parameter validation before forwarding requests; it blindly serializes the user-provided 'stop' argument into the Chat Completions payload. OpenAI's API for reasoning models (o3, o4-mini) rejects 'stop' with 'unsupported_parameter', exposing a design gap where the client library lacks model-capability metadata and relies on provider-side errors.
1. Set environment variable OPENAI_API_KEY. 2. Instantiate ChatOpenAI with model='o3' or 'o4-mini', use_responses_api=False, max_tokens=32, max_retries=0. 3. Pass stop=['<END>'] to the constructor or invoke call. 4. Call .invoke('Reply with exactly: hi'). 5. Observe HTTP 400 with body: Unsupported parameter: 'stop' is not supported with this model. type: invalid_request_error, param: stop, code: unsupported_parameter. A control call without stop succeeds.

Fixing Code Block

Edge Case Audit

This hotfix relies on a hardcoded list of unsupported models, which may become outdated if OpenAI adds stop support to o3/o4-mini or introduces new models with similar restrictions. Users who set stop dynamically or via .bind(stop=...) may bypass the check because _generate may receive stop differently; additional testing is required for those paths. The patch only affects the ChatOpenAI subclass and does not modify the upstream package; if the upstream package later fixes the issue, this wrapper should be removed to avoid duplicate validation. Rolling back is straightforward: replace SafeChatOpenAI with the original ChatOpenAI.

Ecosystem Topology