BadRequestError
anthropic.BadRequestError (HTTP 400)
Stack trace
anthropic.BadRequestError: Error 400: Missing required header 'Anthropic-Computer-Use-Beta' for computer use API access.
Why it happens
The Claude computer use beta feature is gated behind a special HTTP header 'Anthropic-Computer-Use-Beta'. If this header is not included in the API request, the server rejects the call with a 400 BadRequestError indicating the header is missing. This is a deliberate access control mechanism for beta features.
Detection
Monitor API responses for HTTP 400 errors with messages about missing 'Anthropic-Computer-Use-Beta' header. Log request headers to verify if the required beta header is present before retrying.
Causes & fixes
The required 'Anthropic-Computer-Use-Beta' header is not set in the API request.
Add the 'Anthropic-Computer-Use-Beta' header with value 'true' to your API client request headers to enable computer use beta access.
Using an outdated Anthropic SDK version that does not support setting the beta header.
Upgrade to Anthropic SDK version 0.20.0 or later which supports adding custom headers for beta features.
Incorrectly configured client code that overwrites or omits custom headers when making requests.
Ensure your client code merges custom headers properly and does not overwrite the 'Anthropic-Computer-Use-Beta' header before sending.
Code: broken vs fixed
from anthropic import Anthropic
client = Anthropic(api_key=os.environ['ANTHROPIC_API_KEY'])
response = client.messages.create(
model='claude-3-5-sonnet-20241022',
messages=[{'role': 'user', 'content': 'Run code to calculate 2+2'}]
) # This line triggers the missing header error import os
from anthropic import Anthropic
client = Anthropic(api_key=os.environ['ANTHROPIC_API_KEY'])
response = client.messages.create(
model='claude-3-5-sonnet-20241022',
messages=[{'role': 'user', 'content': 'Run code to calculate 2+2'}],
headers={'Anthropic-Computer-Use-Beta': 'true'} # Added required beta header
)
print(response) Workaround
If you cannot add the header immediately, catch the BadRequestError exception, log the error message, and notify the team to update the client to include the required header.
Prevention
Always include required beta or feature flags headers as documented by Anthropic for experimental APIs. Automate header injection in your API client wrapper to avoid missing headers in production.