High severity HTTP 400 beginner · Fix: 5-15 min

ToolNotEnabledError

openai.BadRequestError (HTTP 400: tool not enabled)

What this error means
The OpenAI Responses API rejected your request because web_search_preview is not enabled for your organization or model.

Stack trace

traceback
openai.BadRequestError: Error code: 400 — {'error': {'message': 'web_search_preview tool is not enabled for this organization', 'type': 'invalid_request_error', 'param': 'tools', 'code': 'tool_not_enabled'}}
QUICK FIX
Enable web_search_preview at https://platform.openai.com/account/organization/overview under Settings > Features, create a new API key, and retry with model='gpt-4o' and tools=[{'type': 'web_search_preview'}].

Why it happens

The web_search_preview tool requires explicit enablement at the OpenAI account level before it can be used in Responses API calls. This is a gating mechanism to ensure responsible use of web search capabilities. If your account hasn't been provisioned with access to this tool, or if you're using an older API key without the necessary permissions, the API will reject any request that includes web_search_preview in the tools array.

Detection

Check the client.responses.create() call before deployment: verify that web_search_preview is listed in the tools parameter. Monitor 400 errors in production logs for 'tool_not_enabled' in the error message: this indicates the tool was requested but not enabled.

Causes & fixes

1

web_search_preview tool is not enabled for your OpenAI organization account

✓ Fix

Log in to https://platform.openai.com/account/organization/overview, navigate to Settings > Features, and request access to web_search_preview. Once approved (usually 24-48 hours), regenerate your API key and retry.

2

Using an old API key created before web_search_preview was enabled on your account

✓ Fix

Delete the old API key and create a new one at https://platform.openai.com/api-keys after web_search_preview has been enabled on your account.

3

Model specified does not support web_search_preview (using deprecated gpt-4-turbo or older)

✓ Fix

Switch to gpt-4o or gpt-4o-mini in your client.responses.create() call: web_search_preview is only available on current-generation models.

4

Typo or case-sensitive mismatch in tool name ('web_search' instead of 'web_search_preview')

✓ Fix

Verify the exact tool name is 'web_search_preview' (all lowercase, with underscore). Check for typos: web_search_preview (correct), web_search (wrong), WebSearchPreview (wrong: must be lowercase).

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 will fail with ToolNotEnabledError if web_search_preview is not enabled
response = client.responses.create(
    model='gpt-4o',
    messages=[
        {'role': 'user', 'content': 'What are the latest AI breakthroughs in 2026?'}
    ],
    tools=[
        {'type': 'web_search_preview'}  # ← Error: tool not enabled
    ]
)
Fixed - works correctly
python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))

# Fixed: Ensure web_search_preview is enabled in your OpenAI account first
# 1. Go to https://platform.openai.com/account/organization/overview
# 2. Enable web_search_preview in Settings > Features
# 3. Create a new API key after enablement

response = client.responses.create(
    model='gpt-4o',  # Ensure using current model, not gpt-4-turbo
    messages=[
        {'role': 'user', 'content': 'What are the latest AI breakthroughs in 2026?'}
    ],
    tools=[
        {'type': 'web_search_preview'}  # ← Now enabled and correct
    ]
)

print('Search completed:', response.content[0].text if response.content else 'No results')
The fix requires enabling web_search_preview at the account level first (not in code), then using gpt-4o model with the correctly-named tool in the tools array.

Workaround

If web_search_preview cannot be enabled on your account yet, implement fallback search: wrap the client.responses.create() call in try/except, catch BadRequestError with 'tool_not_enabled' in the message, and fall back to a standard web search API (DuckDuckGo, Google Search API) that you call directly. Store results and re-prompt the LLM with the search results in the messages array instead of using web_search_preview.

Prevention

At deployment time, test web_search_preview availability with a minimal request before shipping code that depends on it. Create a health check endpoint that calls client.responses.create() with web_search_preview enabled; if it returns 400 with 'tool_not_enabled', alert ops that the feature is not provisioned. Store feature flags in environment config (ENABLE_WEB_SEARCH=true/false) and conditionally add tools only if the feature is flagged as enabled.

Python 3.9+ · openai >=1.66.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.