langchain - ✅(Solved) Fix logprobs not returned when using the response api [1 pull requests, 5 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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#36211Fetched 2026-04-08 01:26:23
View on GitHub
Comments
5
Participants
4
Timeline
17
Reactions
0
Author
Assignees
Timeline (top)
commented ×5labeled ×3mentioned ×3subscribed ×3

The principal issue is that when if you set use_responses_api=True and use logprobs=True, then any invocation fails. `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, logprobs=True )

response = client.invoke("say hello world")` TypeError: Responses.create() got an unexpected keyword argument 'logprobs'

Looking at the doc, it seems logprobs is considered as a preserved parameter and is passed to responses.create which explain the error. The supported parameter (using the official openai library) is include=["message.output_text.logprobs" thus the following code works: `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, include=["message.output_text.logprobs"] )

response = client.invoke("say hello world")` however with the changes in the responses format vs the chat format, the logprobs are not properly parsed resulting in missing logprobs in the response.response_metadata which i expected.

Error Message

Traceback (most recent call last): File "<input>", line 12, in <module> File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 402, in invoke self.generate_prompt( ~~~~~~~~~~~~~~~~~~~~^ [self._convert_input(input)], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<6 lines>... **kwargs, ^^^^^^^^^ ).generations[0][0], ^ File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1123, in generate_prompt return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs) ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 933, in generate self._generate_with_cache( ~~~~~~~~~~~~~~~~~~~~~~~~~^ m, ^^ ...<2 lines>... **kwargs, ^^^^^^^^^ ) ^ File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1235, in _generate_with_cache result = self._generate( messages, stop=stop, run_manager=run_manager, **kwargs ) File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1496, in _generate raise e File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1474, in _generate raw_response = self.root_client.responses.with_raw_response.create( **payload ) File "C:\Users\ml-na\PycharmProjects\pipeline-llm.venv\Lib\site-packages\openai_legacy_response.py", line 367, in wrapped return cast(LegacyAPIResponse[R], func(*args, **kwargs)) ~~~~^^^^^^^^^^^^^^^^^ TypeError: Responses.create() got an unexpected keyword argument 'logprobs'

Root Cause

The principal issue is that when if you set use_responses_api=True and use logprobs=True, then any invocation fails. `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, logprobs=True )

response = client.invoke("say hello world")` TypeError: Responses.create() got an unexpected keyword argument 'logprobs'

Looking at the doc, it seems logprobs is considered as a preserved parameter and is passed to responses.create which explain the error. The supported parameter (using the official openai library) is include=["message.output_text.logprobs" thus the following code works: `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, include=["message.output_text.logprobs"] )

response = client.invoke("say hello world")` however with the changes in the responses format vs the chat format, the logprobs are not properly parsed resulting in missing logprobs in the response.response_metadata which i expected.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

filetype: 1.2.0 google-genai: 1.68.0 httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.1.3 openai: 2.29.0 opentelemetry-api: 1.40.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pytest: 9.0.2 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.3 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 websockets: 16.0 wrapt: 1.17.3 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #36371: fix(openai): add support for logprobs when using the response api

Description (problem / solution / changelog)

Fixes #36211

Fix the issue where the combination of use_responses_api=True and logprobs=True prevented any invocation. Precommit validated and all unit-tests passing including the new ones written for this fix. Test scope are discutable: i've decided to test that the request_payload is compatible with the response api instead of testing the output of _construct_responses_api_payload in the case of logprobs=True which may have been more proper. If necessary i can do the changes. Also, i have no tested the case of refusal when logprobs = True. I also think a small update to the integration test could be useful but did not write it. Final test made was to make sure that for the following snipped `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, logprobs=True, )

response = client.invoke("say hello world")` response had the logprobs in the response_metadata which is the case with this PR.

<!-- Replace everything above this line with a 1-2 sentence description of your change. Keep the "Fixes #xx" keyword and update the issue number. -->

Read the full contributing guidelines: https://docs.langchain.com/oss/python/contributing/overview

All contributions must be in English. See the language policy.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

Thank you for contributing to LangChain! Follow these steps to have your pull request considered as ready for review.

  1. PR title: Should follow the format: TYPE(SCOPE): DESCRIPTION
  1. PR description:
  • Write 1-2 sentences summarizing the change.
  • The Fixes #xx line at the top is required for external contributions — update the issue number and keep the keyword. This links your PR to the approved issue and auto-closes it on merge.
  • If there are any breaking changes, please clearly describe them.
  • If this PR depends on another PR being merged first, please include "Depends on #PR_NUMBER" in the description.
  1. Run make format, make lint and make test from the root of the package(s) you've modified.
  • We will not consider a PR unless these three are passing in CI.
  1. How did you verify your code works?

Additional guidelines:

  • All external PRs must link to an issue or discussion where a solution has been approved by a maintainer, and you must be assigned to that issue. PRs without prior approval will be closed.
  • PRs should not touch more than one package unless absolutely necessary.
  • Do not update the uv.lock files or add dependencies to pyproject.toml files (even optional ones) unless you have explicit permission to do so by a maintainer.

Social handles (optional)

<!-- If you'd like a shoutout on release, add your socials below -->

Twitter: @ LinkedIn: https://linkedin.com/in/

Changed files

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

Code Example

from langchain_openai import ChatOpenAI

client = ChatOpenAI(
    model="gpt-5.2",
    use_responses_api=True,
    logprobs=True
)

response = client.invoke("say hello world")

---

Traceback (most recent call last):
  File "<input>", line 12, in <module>
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 402, in invoke
    self.generate_prompt(
    ~~~~~~~~~~~~~~~~~~~~^
        [self._convert_input(input)],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
        **kwargs,
        ^^^^^^^^^
    ).generations[0][0],
    ^
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1123, in generate_prompt
    return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 933, in generate
    self._generate_with_cache(
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
        m,
        ^^
    ...<2 lines>...
        **kwargs,
        ^^^^^^^^^
    )
    ^
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1235, in _generate_with_cache
    result = self._generate(
        messages, stop=stop, run_manager=run_manager, **kwargs
    )
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1496, in _generate
    raise e
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1474, in _generate
    raw_response = self.root_client.responses.with_raw_response.create(
        **payload
    )
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\openai\_legacy_response.py", line 367, in wrapped
    return cast(LegacyAPIResponse[R], func(*args, **kwargs))
                                      ~~~~^^^^^^^^^^^^^^^^^
TypeError: Responses.create() got an unexpected keyword argument 'logprobs'
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

Reproduction Steps / Example Code (Python)

from langchain_openai import ChatOpenAI

client = ChatOpenAI(
    model="gpt-5.2",
    use_responses_api=True,
    logprobs=True
)

response = client.invoke("say hello world")

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "<input>", line 12, in <module>
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 402, in invoke
    self.generate_prompt(
    ~~~~~~~~~~~~~~~~~~~~^
        [self._convert_input(input)],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
        **kwargs,
        ^^^^^^^^^
    ).generations[0][0],
    ^
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1123, in generate_prompt
    return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 933, in generate
    self._generate_with_cache(
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
        m,
        ^^
    ...<2 lines>...
        **kwargs,
        ^^^^^^^^^
    )
    ^
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1235, in _generate_with_cache
    result = self._generate(
        messages, stop=stop, run_manager=run_manager, **kwargs
    )
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1496, in _generate
    raise e
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1474, in _generate
    raw_response = self.root_client.responses.with_raw_response.create(
        **payload
    )
  File "C:\Users\ml-na\PycharmProjects\pipeline-llm\.venv\Lib\site-packages\openai\_legacy_response.py", line 367, in wrapped
    return cast(LegacyAPIResponse[R], func(*args, **kwargs))
                                      ~~~~^^^^^^^^^^^^^^^^^
TypeError: Responses.create() got an unexpected keyword argument 'logprobs'

Description

The principal issue is that when if you set use_responses_api=True and use logprobs=True, then any invocation fails. `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, logprobs=True )

response = client.invoke("say hello world")` TypeError: Responses.create() got an unexpected keyword argument 'logprobs'

Looking at the doc, it seems logprobs is considered as a preserved parameter and is passed to responses.create which explain the error. The supported parameter (using the official openai library) is include=["message.output_text.logprobs" thus the following code works: `from langchain_openai import ChatOpenAI

client = ChatOpenAI( model="gpt-5.2", use_responses_api=True, include=["message.output_text.logprobs"] )

response = client.invoke("say hello world")` however with the changes in the responses format vs the chat format, the logprobs are not properly parsed resulting in missing logprobs in the response.response_metadata which i expected.

System Info

System Information

OS: Windows OS Version: 10.0.26200 Python Version: 3.14.3 (tags/v3.14.3:323c59a, Feb 3 2026, 16:04:56) [MSC v.1944 64 bit (AMD64)]

Package Information

langchain_core: 1.2.22 langchain: 1.2.13 langsmith: 0.7.22 langchain_google_genai: 4.2.1 langchain_openai: 1.1.12 langgraph_sdk: 0.3.12

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

filetype: 1.2.0 google-genai: 1.68.0 httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.1.3 openai: 2.29.0 opentelemetry-api: 1.40.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pytest: 9.0.2 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.3 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 websockets: 16.0 wrapt: 1.17.3 xxhash: 3.6.0 zstandard: 0.25.0

extent analysis

Fix Plan

To fix the issue, you need to modify the logprobs parameter when using use_responses_api=True. The logprobs parameter is not supported in the responses.create method. Instead, you should use the include parameter to specify the fields you want to include in the response.

Here are the steps to fix the issue:

  • Replace logprobs=True with include=["message.output_text.logprobs"] when creating the ChatOpenAI client.
  • Update the code to parse the logprobs from the response correctly.

Code Changes

from langchain_openai import ChatOpenAI

client = ChatOpenAI(
    model="gpt-5.2",
    use_responses_api=True,
    include=["message.output_text.logprobs"]
)

response = client.invoke("say hello world")

To parse the logprobs from the response, you can access the logprobs field in the output_text section of the response:

logprobs = response.response_metadata["logprobs"]

However, since the response format has changed, you may need to update the code to parse the logprobs correctly.

Verification

To verify that the fix worked, you can check the response metadata to see if the logprobs are included:

print(response.response_metadata)

This should output the response metadata, including the logprobs.

Extra Tips

  • Make sure to update the code to handle any errors that may occur when parsing the logprobs.
  • If you're using an older version of the langchain_openai library, you may need to update to the latest version to use the include parameter.
  • You can refer to the OpenAI documentation for more information on the include parameter and the response format.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix logprobs not returned when using the response api [1 pull requests, 5 comments, 4 participants]