AttributeError: 'OpenAI' object has no attribute 'responses'
builtins.AttributeError
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.52.0 (March 2026) to provide stateful conversation management and built-in tools like web_search_preview and computer_use_preview. If your environment has an older OpenAI SDK version installed (v1.0.0 through v1.51.x), the responses attribute does not exist on the OpenAI client object. This commonly happens when requirements.txt pins an old version, a Docker container has stale dependencies, or a CI/CD pipeline hasn't pulled the latest SDK.
Detection
Check your installed OpenAI SDK version immediately with `pip show openai | grep Version`. If it shows anything below 1.52.0, you need to upgrade. Add version pinning to your requirements.txt to prevent this in CI/CD pipelines.
Causes & fixes
requirements.txt pins an old OpenAI SDK version (e.g., openai==1.3.0 or openai<1.52.0)
Update requirements.txt to openai>=1.52.0 or remove any upper-bound cap (use openai>=1.52.0 without a max version). Run pip install --upgrade openai and verify with pip show openai.
Virtual environment has stale cached dependencies from a previous installation
Delete your venv directory entirely, create a fresh virtual environment, and reinstall: rm -rf venv && python -m venv venv && source venv/bin/activate && pip install openai>=1.52.0
Docker or container image has pinned an old OpenAI SDK version in Dockerfile
Update your Dockerfile RUN pip install openai line to specify >=1.52.0, or change RUN pip install -r requirements.txt to pull from an updated requirements.txt with openai>=1.52.0
CI/CD pipeline or GitHub Actions workflow is using a cached Docker layer or pip cache with old SDK
Clear Docker build cache with docker system prune -a and rebuild, or add --no-cache flag to docker build. For pip, add pip install --upgrade --no-cache-dir openai to your CI script.
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
# This fails with AttributeError if OpenAI SDK < 1.52.0
response = client.responses.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is 2+2?"}]
) import os
from openai import OpenAI
# Ensure OpenAI SDK >= 1.52.0 is installed
# Verify: pip show openai | grep Version
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
# Now responses API is available (SDK v1.52.0+)
response = client.responses.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is 2+2?"}]
)
print(f"Response: {response.content[0].text}") Workaround
If you cannot upgrade immediately (e.g., due to dependency conflicts), fall back to chat.completions.create() which is available in all SDK v1.x versions: response = client.chat.completions.create(model='gpt-4o', messages=[...]). This gives you non-stateful responses without conversation history management, but it will work with older SDK versions. Plan your upgrade to SDK v1.52.0+ within one sprint.
Prevention
Pin openai>=1.52.0 in requirements.txt without an upper bound (not openai>=1.52.0,<2.0.0 unless you have specific compatibility requirements). Use a CI/CD workflow that runs pip install --upgrade openai and tests import openai; assert hasattr(OpenAI(), 'responses') before deploying. Document the minimum SDK version in your README and add a setup validation script that checks it at startup.