Drop-in fix for the Claude 4.6 breaking change that removed assistant message prefilling.
If your code does this and now gets a 400:
response = client.messages.create(
model="claude-opus-4-6",
messages=[
{"role": "user", "content": "What is 2+2?"},
{"role": "assistant", "content": "The answer is:"},
],
)Change one import and it works again:
# before
import anthropic
# after
import anthropic_compat as anthropicThat's it. Everything else stays the same — client, methods, exceptions, all of it.
pip install anthropic-compat
Intercepts prefilled assistant messages before they hit the API and converts them into system prompt instructions. The model still starts its response where your prefill left off.
Also handles the output_format → output_config.format rename so you don't have to.
Monkey-patch anything. It wraps the official SDK and passes everything else through untouched.
If this saved you time, consider buying me a coffee.