openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

ImportError: cannot import name 'ResponseTextConfigParam' from 'openai.types.responses'

Open smortezah opened this issue 1 year ago • 23 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [x] This is an issue with the Python library

Describe the bug

ImportError: cannot import name 'ResponseTextConfigParam' from 'openai.types.responses'

    from agents import Agent, Runner, RunResult
  File "/Users/.venv/lib/python3.13/site-packages/agents/__init__.py", line 52, in <module>
    from .models.multi_provider import MultiProvider
  File "/Users/.venv/lib/python3.13/site-packages/agents/models/multi_provider.py", line 7, in <module>
    from .openai_provider import OpenAIProvider
  File "/Users/.venv/lib/python3.13/site-packages/agents/models/openai_provider.py", line 8, in <module>
    from .openai_chatcompletions import OpenAIChatCompletionsModel
  File "/Users/.venv/lib/python3.13/site-packages/agents/models/openai_chatcompletions.py", line 31, in <module>
    from .openai_responses import Converter as OpenAIResponsesConverter
  File "/Users/.venv/lib/python3.13/site-packages/agents/models/openai_responses.py", line 10, in <module>
    from openai.types.responses import (
    ...<8 lines>...
    )
ImportError: cannot import name 'ResponseTextConfigParam' from 'openai.types.responses' (/Users/.venv/lib/python3.13/site-packages/openai/types/responses/__init__.py)

To Reproduce

from agents import Agent, Runner, RunResult

Code snippets


OS

macOS

Python version

Python v3.13.2

Library version

openai v1.100.0

smortezah avatar Aug 18 '25 15:08 smortezah

Am facing something similar while deploying gpt-oss-20b. ~ vllm serve openai/gpt-oss-20b

INFO 08-18 16:00:07 [__init__.py:241] Automatically detected platform cuda.
Traceback (most recent call last):
  File "/root/home/accumulate/.venv/bin/vllm", line 4, in <module>
    from vllm.entrypoints.cli.main import main
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/entrypoints/cli/__init__.py", line 3, in <module>
    from vllm.entrypoints.cli.benchmark.latency import BenchmarkLatencySubcommand
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/entrypoints/cli/benchmark/latency.py", line 5, in <module>
    from vllm.benchmarks.latency import add_cli_args, main
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/benchmarks/latency.py", line 16, in <module>
    from vllm import LLM, SamplingParams
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/__init__.py", line 64, in __getattr__
    module = import_module(module_name, __package__)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/entrypoints/llm.py", line 22, in <module>
    from vllm.engine.arg_utils import (ConvertOption, EngineArgs, HfOverrides,
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/engine/arg_utils.py", line 40, in <module>
    from vllm.reasoning import ReasoningParserManager
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/reasoning/__init__.py", line 5, in <module>
    from .deepseek_r1_reasoning_parser import DeepSeekR1ReasoningParser
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/reasoning/deepseek_r1_reasoning_parser.py", line 9, in <module>
    from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
  File "/root/home/accumulate/.venv/lib/python3.12/site-packages/vllm/entrypoints/openai/protocol.py", line 20, in <module>
    from openai.types.responses import (ResponseFunctionToolCall,
ImportError: cannot import name 'ResponseTextConfig' from 'openai.types.responses' (/root/home/accumulate/.venv/lib/python3.12/site-packages/openai/types/responses/__init__.py). Did you mean: 'ResponseFormatTextConfig'?

Main message:

ImportError: cannot import name 'ResponseTextConfig' from 'openai.types.responses' (/root/home/accumulate/.venv/lib/python3.12/site-packages/openai/types/responses/__init__.py). Did you mean: 'ResponseFormatTextConfig'?

OS

Linux

Python version

3.12

Library version

openai v1.100.0

themohitnair avatar Aug 18 '25 16:08 themohitnair

I have the same issue as OP. Downgrade to v1.99.9 helped.

bocytko avatar Aug 18 '25 16:08 bocytko

We are running into a similar issue in our CI workflows when installing LiteLLM (no install cache):

The pip install log:

#11 7.502 Collecting openai>=1.68.2 (from litellm==1.74.8->-r requirements.txt (line 18))
#11 7.522   Downloading openai-1.100.0-py3-none-any.whl.metadata (29 kB)

Runtime error:

from litellm.types.llms.openai import AllMessageValues
File "/usr/local/lib/python3.11/site-packages/litellm/types/llms/openai.py", line 36, in <module>
from openai.types.responses.response import (
ImportError: cannot import name 'ResponseTextConfig' from 'openai.types.responses.response' (/usr/local/lib/python3.11/site-packages/openai/types/responses/response.py)

Locally cached version of 1.97.1 does not cause the issue when running the project:

Requirement already satisfied: openai>=1.68.2 in ./.venv/lib/python3.10/site-packages (from litellm==1.74.8->-r requirements.txt (line 18)) (1.97.1)

We've only found out about the issue after tests suddenly started failing. This might affect other projects and package managers expecting compatible import signatures when using versions with the same major 1.X.X.

Was there some breaking change introduced with the feature release of 1.100.0?

Happy to provide more import traces.

Arthur-Sebastian avatar Aug 18 '25 16:08 Arthur-Sebastian

Was there some breaking change introduced with the feature release of 1.100.0?

The Text type was moved into different packages and imports were adjusted: https://github.com/openai/openai-python/compare/v1.99.9...v1.100.0#diff-f223e5edce97b27a0b586915deb094a5fdd40a3679826e4776f805212207cdb1L98

For the issue OP reported, I think agents package needs an update which was also noticed there:

https://github.com/openai/openai-agents-python/issues/1519

bocytko avatar Aug 18 '25 17:08 bocytko

The Text type was moved into different packages and imports were adjusted

That's going to break all projects with a 'compatible' ~= dependency specifier. Normally I'd expect a bump to major 2.0.0 if changes like that are made, so things like that don't happen - unless the symbol is considered an internal and not part of the documented API. Wonder what happened here.

Arthur-Sebastian avatar Aug 18 '25 17:08 Arthur-Sebastian

try this workaround https://github.com/vllm-project/recipes/issues/28

isnuryusuf avatar Aug 18 '25 18:08 isnuryusuf

I faced the same issue.
This PR fixes it: #1521

AbdulSamad94 avatar Aug 18 '25 18:08 AbdulSamad94

Wonder what happened here.

Probably AI reviewed the PR...

pkit avatar Aug 18 '25 18:08 pkit

We are running into the same issue in our CI when installing litellm, trace lead us here. Seems like a breaking change without a major ver. bump.

any updates on this?

eshwarprasadS avatar Aug 18 '25 19:08 eshwarprasadS

We are also running into the same issue. We broke while doing a deploy with CICD pulling in the minor bump.

IMO, This should have been a major bump if this was known. But shit happens. Looking forward to the patch.

codeninja avatar Aug 18 '25 21:08 codeninja

The patch is out since ~1h: https://github.com/openai/openai-python/releases/tag/v1.100.1

bocytko avatar Aug 18 '25 22:08 bocytko

Just bumped to openai v1.100.1 and the import error is gone; the missing types are back and my agents run fine. Here’s the diff if you want to see what changed: https://github.com/openai/openai-python/compare/v1.100.0...v1.100.1 github.com . Big thanks to the team for the quick turnaround!

harjothkhara avatar Aug 18 '25 23:08 harjothkhara

Unfortunately the v1.100.1 patch did not revert the change in openai.types.responses.response

We're still seeing the error via litellm/types/llms/openai.py - see https://github.com/BerriAI/litellm/issues/13711

Traceback (most recent call last):
  File "/Users/jldec/jentic/standard-agent/examples/cli_rewoo_api_agent.py", line 11, in <module>
    from agents.prebuilt import ReWOOAgent
  File "/Users/jldec/jentic/standard-agent/agents/prebuilt.py", line 6, in <module>
    from agents.llm.litellm import LiteLLM
  File "/Users/jldec/jentic/standard-agent/agents/llm/litellm.py", line 4, in <module>
    import litellm
  File "/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/litellm/__init__.py", line 20, in <module>
    from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler
  File "/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/litellm/llms/custom_httpx/http_handler.py", line 16, in <module>
    from litellm.litellm_core_utils.logging_utils import track_llm_api_timing
  File "/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/logging_utils.py", line 7, in <module>
    from litellm.types.utils import (
    ...<3 lines>...
    )
  File "/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/litellm/types/utils.py", line 42, in <module>
    from ..litellm_core_utils.core_helpers import map_finish_reason
  File "/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/core_helpers.py", line 8, in <module>
    from litellm.types.llms.openai import AllMessageValues
  File "/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/litellm/types/llms/openai.py", line 36, in <module>
    from openai.types.responses.response import (
    ...<6 lines>...
    )
ImportError: cannot import name 'ResponseTextConfig' from 'openai.types.responses.response' (/Users/jldec/jentic/standard-agent/.venv/lib/python3.13/site-packages/openai/types/responses/response.py)

cc: @RobertCraigie

jldec avatar Aug 18 '25 23:08 jldec

I can also confirm the error with litellm

klieret avatar Aug 19 '25 00:08 klieret

Workaround uv pip install 'openai<1.100.0' or pip install 'openai<1.100.0'

isnuryusuf avatar Aug 19 '25 04:08 isnuryusuf

Unfortunately the v1.100.1 patch did not revert the change in openai.types.responses.response

We're still seeing the error via litellm/types/llms/openai.py - see BerriAI/litellm#13711

@jldec you're right. ResponseTextConfig & ResponseTextConfigParam are still missing.

  • https://github.com/openai/openai-python/compare/v1.99.9...v1.100.1#diff-cdffb502e495fd2226542c48d57c96c1c26e8d9cee27618ddaff1b1231d16046L21
  • https://github.com/openai/openai-python/compare/v1.99.9...v1.100.1#diff-517eec825b1b41ded07cb11ff70d21bd0b8a1dba7fbbf6844fac6091a3a7682bL19

bocytko avatar Aug 19 '25 06:08 bocytko

The class ResponseTextConfigParam was removed/renamed in recent openai versions (≥ v1.0). Some parts of your code (or the agents package) are still trying to import it.In newer versions of the OpenAI Python SDK (≥ v1.0), this class was removed/renamed.So when Python tries to import it, it raises: ImportError: cannot import name 'ResponseTextConfigParam' How We Fixed It Checked the import statement in openai_responses.py. It assumed that ResponseTextConfigParam would always exist. Wrapped the import in a try/except: If the class exists (older SDK versions) → import normally. If it doesn’t (newer SDK versions) → provide a shim class (an empty placeholder). try:

from openai.types.responses import ( ResponseTextConfigParam, ResponseContentText, ResponseContentImage, ResponseContentRefusal, ) except ImportError: from openai.types.responses import ( ResponseContentText, ResponseContentImage, ResponseContentRefusal, )

class ResponseTextConfigParam:
    """Shim for compatibility with older agent code."""
    pass

Result The ImportError is gone. Older versions → still use the real ResponseTextConfigParam. Newer versions → use the stub class, so dependent code doesn’t break. Maintains backward + forward compatibility.

LuminaX-alt avatar Aug 19 '25 08:08 LuminaX-alt

The class ResponseTextConfigParam was removed/renamed in recent openai versions (≥ v1.0).

I think you are mixing up two classes here, ResponseTextConfig and ResponseTextConfigParam. The discussion so far was about ResponseTextConfig.

The issue with the patch from 1.100.0 to 1.100.1 is that it does not roll back the change in response.py itself. From 1.99.9:

https://github.com/openai/openai-python/blob/34014aedbb8946c03e97e5c8d72e03ad2259cd7c/src/openai/types/responses/response.py#L21

This would need to be reintroduced, i guess.

patrick-amaru avatar Aug 19 '25 12:08 patrick-amaru

@LuminaX-alt tf with the AI slop? Did AI tell you how to patch numerous other libraries that use openai too? Not to mention that "was removed/renamed in recent openai versions (≥ v1.0)" is false. But you don't understand that too?

pkit avatar Aug 19 '25 16:08 pkit

Call it slop if you want, but the root fix feeds all the dependents. Downstream’s handled.

LuminaX-alt avatar Aug 19 '25 16:08 LuminaX-alt