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

BadRequestError

anthropic.BadRequestError (HTTP 400)

What this error means
Anthropic's Claude API requires a special beta header for computer use features; missing this header causes a 400 BadRequestError.

Stack trace

traceback
anthropic.BadRequestError: Error 400: Missing required header 'Anthropic-Computer-Use-Beta' for computer use API access.
QUICK FIX
Add the header 'Anthropic-Computer-Use-Beta': 'true' to your API request headers immediately.

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

1

The required 'Anthropic-Computer-Use-Beta' header is not set in the API request.

✓ Fix

Add the 'Anthropic-Computer-Use-Beta' header with value 'true' to your API client request headers to enable computer use beta access.

2

Using an outdated Anthropic SDK version that does not support setting the beta header.

✓ Fix

Upgrade to Anthropic SDK version 0.20.0 or later which supports adding custom headers for beta features.

3

Incorrectly configured client code that overwrites or omits custom headers when making requests.

✓ Fix

Ensure your client code merges custom headers properly and does not overwrite the 'Anthropic-Computer-Use-Beta' header before sending.

Code: broken vs fixed

Broken - triggers the error
python
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
Fixed - works correctly
python
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)
Added the required 'Anthropic-Computer-Use-Beta' header with value 'true' to the API request to enable computer use beta access and avoid the 400 error.

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.

Python 3.9+ · anthropic >=0.20.0 · tested on 0.20.x
Verified 2026-04 · claude-3-5-sonnet-20241022, claude-3-5-haiku-20241022
Verify ↗

Community Notes

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