High severity beginner · Fix: 2-5 min

AttributeError: 'OpenAI' object has no attribute 'responses'

builtins.AttributeError

What this error means
The OpenAI Python SDK v1.52.0+ added the responses API for stateful conversations, but older SDK versions don't have this attribute, causing AttributeError when you try to call client.responses.create().

Stack trace

traceback
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'
QUICK FIX
Run pip install --upgrade openai>=1.52.0 immediately, then restart your Python process. Verify with python -c 'from openai import OpenAI; print(hasattr(OpenAI(), "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

1

requirements.txt pins an old OpenAI SDK version (e.g., openai==1.3.0 or openai<1.52.0)

✓ Fix

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.

2

Virtual environment has stale cached dependencies from a previous installation

✓ Fix

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

3

Docker or container image has pinned an old OpenAI SDK version in Dockerfile

✓ Fix

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

4

CI/CD pipeline or GitHub Actions workflow is using a cached Docker layer or pip cache with old SDK

✓ Fix

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

Broken - triggers the error
python
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?"}]
)
Fixed - works correctly
python
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}")
Upgraded OpenAI SDK to v1.52.0+ which includes the responses API for stateful conversations. The client.responses attribute now exists and the code runs successfully.

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.

Python 3.8+ · openai >=1.52.0 · tested on 1.66.0
Verified 2026-04 · gpt-4o, gpt-4o-mini
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.