langchain - ✅(Solved) Fix gpt-5.4+ models not detected as Responses API models, causing tool_choice.function error [5 pull requests, 3 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35584Fetched 2026-04-08 00:25:25
View on GitHub
Comments
3
Participants
4
Timeline
20
Reactions
0
Author
Timeline (top)
cross-referenced ×6mentioned ×4subscribed ×4commented ×3

_model_prefers_responses_api doesn't cover gpt-5.4+ models (e.g. gpt-5.4-2026-03-05). This causes langchain-openai to route them through Chat Completions (/v1/chat/completions) instead of the Responses API, which results in OpenAI rejecting the request with:

Unknown parameter: 'tool_choice.function'

This happens because Chat Completions sends tool_choice: {"type": "function", "function": {"name": "..."}}, but gpt-5.4+ only accepts the Responses API format ({"type": "function", "name": "..."}).

Error Message

from langchain_openai import ChatOpenAI from langchain_core.tools import tool

@tool def my_tool(x: str) -> str: """A test tool.""" return x

Fails

llm = ChatOpenAI(model="gpt-5.4-2026-03-05") llm_with_tools = llm.bind_tools([my_tool], tool_choice="my_tool") result = await llm_with_tools.ainvoke("hello")

→ openai.BadRequestError: Unknown parameter: 'tool_choice.function'

Works

llm = ChatOpenAI(model="gpt-5.4-2026-03-05", use_responses_api=True) llm_with_tools = llm.bind_tools([my_tool], tool_choice="my_tool") result = await llm_with_tools.ainvoke("hello")

→ SUCCESS: tool called correctly

Root Cause

This happens because Chat Completions sends tool_choice: {"type": "function", "function": {"name": "..."}}, but gpt-5.4+ only accepts the Responses API format ({"type": "function", "name": "..."}).

Fix Action

Fixed

PR fix notes

PR #35594: fix(openai): update responses API model detection for pro and codex models

Description (problem / solution / changelog)

Summary

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +8/-1)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +16/-1)

PR #35595: fix: Add gpt-5.4+ models to Responses API detection (fixes #35584)

Description (problem / solution / changelog)

Problem

_model_prefers_responses_api() does not recognize gpt-5.4+ models (e.g., gpt-5.4-2026-03-05), causing them to be routed through Chat Completions instead of Responses API. This results in OpenAI rejecting requests with:

Unknown parameter: 'tool_choice.function'

Solution

Add gpt-5.4 to the Responses API model detection pattern.

Changes

  • libs/partners/openai/langchain_openai/chat_models/base.py: Add "gpt-5.4" in model_name check
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py: Add test coverage for gpt-5.4 models

Testing

  • Added test cases for gpt-5.4 and gpt-5.4-2026-03-05
  • Added negative test cases for non-Responses API models
  • All existing tests pass

Fixes #35584

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +3/-1)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +7/-0)

PR #35609: fix: detect gpt-5.4+ as Responses API models

Description (problem / solution / changelog)

Fixes #35584

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +1/-1)

PR #35643: fix: detect gpt-5.4+ models as Responses API models

Description (problem / solution / changelog)

Fixes #35584

Adds gpt-5.4 to _model_prefers_responses_api detection to ensure these models use the Responses API instead of Chat Completions.

This fixes the tool_choice.function error when using gpt-5.4+ models.

/attempt #35584

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +7/-1)

PR #35695: fix(openai): detect gpt-5.4+ as Responses API models

Description (problem / solution / changelog)

Problem

_model_prefers_responses_api() matched gpt-5.4-pro but not bare gpt-5.4 variants (e.g. gpt-5.4-2026-03-05). This caused langchain-openai to route them through Chat Completions (/v1/chat/completions) instead of the Responses API, which fails with:

openai.BadRequestError: Unknown parameter: 'tool_choice.function'

Closes #35584

Fix

Broadened the _RESPONSES_API_ONLY_PREFIXES entry from "gpt-5.4-pro" to "gpt-5.4" so all gpt-5.4 variants (base, pro, date snapshots) are correctly routed to the Responses API.

Before: ("gpt-5-pro", "gpt-5.2-pro", "gpt-5.4-pro") After: ("gpt-5-pro", "gpt-5.2-pro", "gpt-5.4")

Since "gpt-5.4" is a prefix of "gpt-5.4-pro", the pro variant continues to match.

Tests

Updated test_model_prefers_responses_api to verify:

  • gpt-5.4 → detected ✅
  • gpt-5.4-2026-03-05 → detected ✅
  • gpt-5.4-pro → still detected ✅
  • Existing models (gpt-5-pro, gpt-5.2-pro, codex) → unchanged ✅
  • Non-Responses API models (gpt-5, gpt-5.1, gpt-4.1) → not affected ✅

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +1/-1)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +3/-1)

Code Example

Unknown parameter: 'tool_choice.function'

---

from langchain_openai import ChatOpenAI
from langchain_core.tools import tool

@tool
def my_tool(x: str) -> str:
    """A test tool."""
    return x

# Fails
llm = ChatOpenAI(model="gpt-5.4-2026-03-05")
llm_with_tools = llm.bind_tools([my_tool], tool_choice="my_tool")
result = await llm_with_tools.ainvoke("hello")
# → openai.BadRequestError: Unknown parameter: 'tool_choice.function'

# Works
llm = ChatOpenAI(model="gpt-5.4-2026-03-05", use_responses_api=True)
llm_with_tools = llm.bind_tools([my_tool], tool_choice="my_tool")
result = await llm_with_tools.ainvoke("hello")
# → SUCCESS: tool called correctly

---

def _model_prefers_responses_api(model_name: str | None) -> bool:
    if not model_name:
        return False
    return "gpt-5.2-pro" in model_name or "gpt-5.4" in model_name or "codex" in model_name
RAW_BUFFERClick to expand / collapse

Description

_model_prefers_responses_api doesn't cover gpt-5.4+ models (e.g. gpt-5.4-2026-03-05). This causes langchain-openai to route them through Chat Completions (/v1/chat/completions) instead of the Responses API, which results in OpenAI rejecting the request with:

Unknown parameter: 'tool_choice.function'

This happens because Chat Completions sends tool_choice: {"type": "function", "function": {"name": "..."}}, but gpt-5.4+ only accepts the Responses API format ({"type": "function", "name": "..."}).

Reproduction

from langchain_openai import ChatOpenAI
from langchain_core.tools import tool

@tool
def my_tool(x: str) -> str:
    """A test tool."""
    return x

# Fails
llm = ChatOpenAI(model="gpt-5.4-2026-03-05")
llm_with_tools = llm.bind_tools([my_tool], tool_choice="my_tool")
result = await llm_with_tools.ainvoke("hello")
# → openai.BadRequestError: Unknown parameter: 'tool_choice.function'

# Works
llm = ChatOpenAI(model="gpt-5.4-2026-03-05", use_responses_api=True)
llm_with_tools = llm.bind_tools([my_tool], tool_choice="my_tool")
result = await llm_with_tools.ainvoke("hello")
# → SUCCESS: tool called correctly

Expected behavior

gpt-5.4-2026-03-05 is automatically routed to the Responses API, matching the same logic applied to gpt-5.2-pro and codex (added in #35058).

Proposed fix

In libs/partners/openai/langchain_openai/chat_models/base.py:

def _model_prefers_responses_api(model_name: str | None) -> bool:
    if not model_name:
        return False
    return "gpt-5.2-pro" in model_name or "gpt-5.4" in model_name or "codex" in model_name

Version

  • langchain-openai==1.1.10 (latest)

extent analysis

Fix: Update _model_prefers_responses_api to support gpt-5.4+ models

Fix Plan

  1. Update _model_prefers_responses_api function in libs/partners/openai/langchain_openai/chat_models/base.py:

def _model_prefers_responses_api(model_name: str | None) -> bool: if not model_name: return False return "gpt-5.2-pro" in model_name or "gpt-5.4" in model_name or "codex" in model_name or "gpt-5.4-" in model_name

   The change is to add `"gpt-5.4-"` to the list of model names that prefer the Responses API.

2. **Update `langchain-openai` to the latest version** (`1.1.10` or later) to ensure the updated function is used.

### Verification

1. **Reproduce the issue** using the provided example code.
2. **Apply the fix** by updating the `_model_prefers_responses_api` function and updating `langchain-openai` to the latest version.
3. **Re-run the example code** to verify that it now succeeds without errors.

### Extra Tips

* Make sure to update `langchain-openai` to the latest version to ensure the fix is applied correctly.
* If you're using a custom version of `langchain-openai`, you may need to apply additional changes to ensure compatibility with the updated function.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

gpt-5.4-2026-03-05 is automatically routed to the Responses API, matching the same logic applied to gpt-5.2-pro and codex (added in #35058).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING