BadRequestError
openai.BadRequestError (HTTP 400)
Stack trace
openai.BadRequestError: Error code: 400 - {'error': {'message': 'computer_use_preview requires beta header', 'type': 'invalid_request_error', 'param': 'tools', 'code': 'invalid_request_error'}} Why it happens
The Responses API computer_use_preview tool is in beta and requires explicit opt-in via the HTTP header. OpenAI gates beta features this way to ensure developers are aware of potential breaking changes. Without the header, the API rejects any request attempting to use computer_use_preview tools, treating it as an unknown tool type.
Detection
Monitor for 400 BadRequestError responses that mention 'computer_use_preview' in the error message. Add logging around client.responses.create() calls to catch this before production. Use try/except BadRequestError to differentiate this from other 400 errors.
Causes & fixes
OpenAI client instantiated without default headers, or header only set on some requests but not others
Pass the beta header when creating the OpenAI client: client = OpenAI(api_key=os.environ['OPENAI_API_KEY'], default_headers={'openai-beta': 'computer-use-preview-2024-10-15'})
Beta header value is spelled wrong or uses an outdated preview date
Use exactly 'computer-use-preview-2024-10-15' (case-sensitive). Check OpenAI documentation for the current preview version: preview dates change as features stabilize.
Header set on client creation but overridden or lost in middleware/proxies
If using a request interceptor or proxy, ensure headers are passed through. For custom httpx clients, add the header explicitly: httpx.Client(headers={'openai-beta': 'computer-use-preview-2024-10-15'})
Using an older OpenAI SDK version that doesn't properly support responses API with computer_use_preview
Upgrade to openai>=1.52.0: pip install --upgrade openai: verify with 'pip show openai | grep Version'
Code: broken vs fixed
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ['OPENAI_API_KEY']) # ❌ No beta header — will fail
response = client.responses.create(
model='gpt-4o',
instructions='Take a screenshot of the desktop.',
tools=[
{
'type': 'computer_use_preview', # ❌ This requires the beta header
'name': 'screenshot',
'display_name': 'Screenshot'
}
]
) import os
from openai import OpenAI
# ✅ Pass beta header when creating client
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY'],
default_headers={'openai-beta': 'computer-use-preview-2024-10-15'}
)
response = client.responses.create(
model='gpt-4o',
instructions='Take a screenshot of the desktop.',
tools=[
{
'type': 'computer_use_preview', # ✅ Header is set, this works now
'name': 'screenshot',
'display_name': 'Screenshot'
}
]
)
print(f"Response created: {response.id}") Workaround
If you cannot upgrade the SDK, manually add the header using a custom httpx client: import httpx; client = OpenAI(http_client=httpx.Client(headers={'openai-beta': 'computer-use-preview-2024-10-15'})). This bypasses SDK-level header management and sets the header directly on the transport layer.
Prevention
Always define beta headers at client instantiation time, not per-request. For multi-tool Responses API usage, create a dedicated client factory function that applies all required beta headers. Document which beta previews your system depends on in a constants file (e.g., OPENAI_BETA_HEADERS = {'openai-beta': 'computer-use-preview-2024-10-15'}) so all client creation references it.