Claude brings a different auth pattern from OpenAI: an x-api-key header, a required version header, and max_tokens you must always include. This guide covers every field exactly as the Anthropic API expects them.
Anthropic's Messages API works well in a WhatsApp chatbot. The setup is close to OpenAI's but with three important differences that catch people out: the auth header is named x-api-key, a second required header called anthropic-version must be present, and max_tokens is not optional. Miss any one of these and the request returns an error with no useful reply.
This guide assumes you know the External API Request step. If not, read the foundation guide first.
Current model IDs and pricing: docs.anthropic.com/en/docs/models-overview. Claude model IDs include a date in them; retired model IDs return an error, so check this page if a previously working call breaks.
POST.
https://api.anthropic.com/v1/messages| Header name | Value | Why |
|---|---|---|
| x-api-key | Your Anthropic key (sk-ant-...) | Authentication |
| anthropic-version | 2023-06-01 | Required API version header. The date is fixed; do not change it. |
| Content-Type | application/json | Tells the API you are sending JSON |
All three are required. The anthropic-version value is 2023-06-01 regardless of which model or release date you are using.
Claude uses a top-level system field (outside the messages array) for the persona instruction, which differs from OpenAI's approach of putting it as a system-role message.
{
"model": "claude-sonnet-4-6",
"max_tokens": 500,
"system": "You are a helpful support assistant for {{business_name}}. Answer briefly and politely.",
"messages": [
{
"role": "user",
"content": "{{customer_message}}"
}
]
}Unlike OpenAI, Claude's API will return a validation error if you omit max_tokens. There is no default. 500 is a sensible starting point for WhatsApp-length replies. The field limits the reply length and therefore the cost per request.
Claude's response format differs from OpenAI's. The answer is in a content array, not a choices array.
{
"content": [
{
"type": "text",
"text": "...Claude's reply is here..."
}
],
"model": "claude-sonnet-4-6-20250514",
"stop_reason": "end_turn",
"usage": { "input_tokens": 42, "output_tokens": 67 }
}Map content[0].text into your next WhatsApp message step. If you request only a text reply (the default), there will always be exactly one content block of type text.
A customer asks about rescheduling their appointment. The system prompt tells Claude about your booking policy; the customer's message is the question.
{
"model": "claude-sonnet-4-6",
"max_tokens": 400,
"system": "You are the booking assistant for a dental clinic. Appointments can be rescheduled up to 24 hours before with no fee. Cancellations within 24 hours incur a fee of Rs 200. Rescheduling can be done by replying to this chat or calling 022-1234-5678. Keep answers brief.",
"messages": [
{
"role": "user",
"content": "{{customer_message}}"
}
]
}Claude reads the policy from the system field and answers clearly. You do not need to script every variation of the question; the model handles the phrasing and fills in the right answer from the context you gave it.
| Symptom | Likely cause | Fix |
|---|---|---|
| 400 Bad Request | Missing max_tokens, or missing anthropic-version header | Add max_tokens to the body; confirm anthropic-version: 2023-06-01 is in headers |
| 401 Unauthorized | Wrong or revoked API key | Re-check the key in console.anthropic.com; confirm header is x-api-key, not Authorization |
| 404 Not Found | Model ID has been retired | Check docs.anthropic.com for the current model IDs; Claude model names include a date stamp that becomes invalid when retired |
| 529 Overloaded | Anthropic capacity spike | Retry after a short pause; consider adding a delay step before the Claude call |
| Reply cut off | max_tokens too low | Raise max_tokens in the body |
Anthropic returns detailed error messages in the response body. Always read the error field before troubleshooting.
Free trial, no credit card required. And if you ever get stuck, we are the only platform in India that answers you live on WhatsApp.