AttributeError or ImportError
AttributeError: 'OpenAI' object has no attribute 'responses' OR ImportError: cannot import responses API
Stack trace
AttributeError: 'OpenAI' object has no attribute 'responses'
File "your_script.py", line 42, in <module>
response = client.responses.create(
AttributeError: 'OpenAI' object has no attribute 'responses' Why it happens
The Responses API was introduced in OpenAI SDK v1.66.0 as a stateful alternative to the standard chat completions API. It enables conversation continuity using previous_response_id without managing message history manually. If your project has an older SDK version installed, the client object won't have the responses attribute, causing an AttributeError when you try to call client.responses.create().
Detection
Run `pip show openai | grep Version` before using client.responses.create(). If the version is below 1.66.0, you'll hit this error immediately. Add version checks in your CI/CD: `assert openai.__version__ >= '1.66.0'` at module load time.
Causes & fixes
OpenAI SDK version is below 1.66.0: older version installed in your environment
Run `pip install --upgrade openai>=1.66.0` to install the latest SDK with Responses API support
Virtual environment or requirements.txt specifies an old pinned version of openai (e.g., openai==1.50.0)
Update your requirements.txt from 'openai==1.50.0' to 'openai>=1.66.0' and run `pip install -r requirements.txt --upgrade`
Using a Docker image or CI/CD build that was created before SDK v1.66.0 was released
Rebuild your Docker image with `pip install --upgrade openai>=1.66.0` in the Dockerfile, or update your CI/CD build cache
Multiple Python environments installed (system Python + conda + venv) and you're running code in the wrong one
Verify which Python/environment you're using with `which python` and `python -m pip show openai`, then activate the correct virtual environment
Code: broken vs fixed
import openai
from openai import OpenAI
import os
# BROKEN: assumes Responses API exists but SDK is old
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
# This line fails with AttributeError if openai < 1.66.0
response = client.responses.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.content) import openai
from openai import OpenAI
import os
# FIXED: verify SDK version before using Responses API
if openai.__version__ < '1.66.0':
raise RuntimeError(
f"Responses API requires openai>=1.66.0, but you have {openai.__version__}. "
"Run: pip install --upgrade openai>=1.66.0"
)
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
# Now safe to use Responses API (SDK v1.66.0+)
response = client.responses.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.content) Workaround
If you cannot upgrade the SDK immediately, use client.chat.completions.create() instead of client.responses.create(). This standard API is available in all SDK v1+ versions. You'll lose stateful conversation continuity and must manage message history manually: maintain a list of all previous messages and pass them to every API call. This is slower and more error-prone but avoids the version requirement.
Prevention
Pin openai>=1.66.0 in your project dependencies (requirements.txt, pyproject.toml, or Gemfile equivalent) to enforce minimum SDK version across all environments. Add a CI/CD check: `python -c "import openai; assert openai.__version__ >= '1.66.0'"` that fails fast if version is wrong. Document Responses API feature as requiring SDK v1.66.0+ in your team's onboarding guide.