High severity beginner · Fix: 2-5 min

AttributeError or ImportError

AttributeError: 'OpenAI' object has no attribute 'responses' OR ImportError: cannot import responses API

What this error means
The Responses API (stateful conversation feature) is only available in OpenAI SDK v1.66.0 or later; older versions don't have the client.responses.create() method.

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.66.0` and verify with `python -c "import openai; print(openai.__version__)"` before running code using client.responses.create().

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

1

OpenAI SDK version is below 1.66.0: older version installed in your environment

✓ Fix

Run `pip install --upgrade openai>=1.66.0` to install the latest SDK with Responses API support

2

Virtual environment or requirements.txt specifies an old pinned version of openai (e.g., openai==1.50.0)

✓ Fix

Update your requirements.txt from 'openai==1.50.0' to 'openai>=1.66.0' and run `pip install -r requirements.txt --upgrade`

3

Using a Docker image or CI/CD build that was created before SDK v1.66.0 was released

✓ Fix

Rebuild your Docker image with `pip install --upgrade openai>=1.66.0` in the Dockerfile, or update your CI/CD build cache

4

Multiple Python environments installed (system Python + conda + venv) and you're running code in the wrong one

✓ Fix

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

Broken - triggers the error
python
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)
Fixed - works correctly
python
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)
Added version check before calling client.responses.create() to catch the version mismatch early and guide developers to upgrade. This prevents the cryptic AttributeError and provides clear remediation.

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.

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

Community Notes

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