ToolNotEnabledError
openai.BadRequestError (HTTP 400: tool not enabled)
Stack trace
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'}} 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
web_search_preview tool is not enabled for your OpenAI organization account
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.
Using an old API key created before web_search_preview was enabled on your account
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.
Model specified does not support web_search_preview (using deprecated gpt-4-turbo or older)
Switch to gpt-4o or gpt-4o-mini in your client.responses.create() call: web_search_preview is only available on current-generation models.
Typo or case-sensitive mismatch in tool name ('web_search' instead of 'web_search_preview')
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
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
]
) 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') 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.