Skip to content
WP EngineDocumentation

Create a message (Anthropic Messages API)

POST
/v1/messages
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.ai.wpengine.com/v1/messages', [
'body' => '{ "model": "anthropic/claude-sonnet-4-6", "messages": [ { "role": "user", "content": "example" } ], "max_tokens": 1024, "system": "example", "tools": [ {} ], "stream": false, "thinking": { "type": "enabled", "budget_tokens": 1 } }',
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();

Anthropic-native Messages endpoint, compatible with official Anthropic SDKs. Accepts the standard Anthropic Messages request shape, including system prompts, multi-turn conversations, image content blocks, tool use, extended thinking, custom stop sequences, and streaming. Prompt caching is supported: add “cache_control” breakpoints to your request (on system, tools, or message content) to cache stable prefixes; cached-token counts are reported as “cache_creation_input_tokens” and “cache_read_input_tokens” in the response usage. Authenticate with a WP Engine bearer token, or with the Anthropic SDK convention of an “x-api-key” header carrying a WP Engine API key. API keys must carry the “chat:write” permission. The model field accepts prefixed (“anthropic/claude-sonnet-4-6”) or bare (“claude-sonnet-4-6”) names; only Anthropic models are supported. The “anthropic-version” and “anthropic-beta” headers are accepted and forwarded. All errors are returned in Anthropic’s error envelope format.

Media typeapplication/json

Standard Anthropic Messages API request. The full request shape is supported and forwarded to the model, including fields not listed here (tool_choice, stop_sequences, temperature, top_p, metadata, …). See Anthropic’s Messages API reference for the complete schema.

object
model
required

Anthropic model name, prefixed or bare (e.g. “anthropic/claude-sonnet-4-6” or “claude-sonnet-4-6”).

string
Example
anthropic/claude-sonnet-4-6
messages
required

Conversation turns in Anthropic message format.

Array<object>
object
role
required
string
Allowed values: user assistant
content
required

Message content: a plain string, or an array of content blocks (text, image, tool_use, tool_result, thinking, …).

max_tokens
required

Maximum number of tokens to generate.

integer
>= 1
Example
1024
system

System prompt, as a string or array of content blocks.

tools

Tool definitions in Anthropic tool format, each with a name, description, and input_schema.

Array<object>
object
stream

When true, the response is a Server-Sent Events stream using Anthropic’s streaming event protocol.

boolean
thinking

Extended thinking configuration.

object
type
string
Allowed values: enabled disabled
budget_tokens

Token budget for thinking when enabled.

integer

Anthropic message response. When stream is false, returns a single JSON message object. When stream is true, returns Server-Sent Events using Anthropic’s streaming event protocol (message_start, content_block_delta, message_delta, message_stop, …).

Standard Anthropic Messages API response.

object
id
string
type
string
Allowed values: message
role
string
Allowed values: assistant
model
string
content

Generated content blocks (text, tool_use, thinking, …).

Array<object>
object
type
string
stop_reason
string
Allowed values: end_turn max_tokens stop_sequence tool_use model_context_window_exceeded
stop_sequence

The matched custom stop sequence, when applicable.

string
nullable
usage
object
input_tokens
integer
output_tokens
integer
cache_creation_input_tokens
integer
cache_read_input_tokens
integer
Example
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-6",
"content": [
{
"type": "text"
}
],
"stop_reason": "end_turn"
}

Invalid request body or parameters, in Anthropic error envelope format (error type “invalid_request_error”).

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

Missing or invalid credentials, in Anthropic error envelope format (error type “authentication_error”).

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}
WWW-Authenticate
string
Example
Bearer realm="ai-services"

The account’s credit balance is exhausted. Grant or top up credits before retrying. Body is in Anthropic error envelope format.

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

Valid credentials but insufficient permission, in Anthropic error envelope format (error type “permission_error”). On /v1/messages specifically, a 403 with error type “content_policy_violation” instead means the request content was blocked by content moderation policy; that response never identifies which filter or category matched.

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

The requested model was not found or does not support this endpoint, in Anthropic error envelope format (error type “not_found_error”).

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

Request body exceeds the size limit, in Anthropic error envelope format (error type “request_too_large”).

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

Rate limit exceeded. The request was throttled at the edge; wait and retry later. The response body is a short HTML page generated by the load balancer, not a structured JSON error — clients should rely on the 429 status code rather than parsing the body.

Media typetext/html
string

Upstream provider returned an error, in Anthropic error envelope format (error type “api_error”).

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

A required dependency (such as the authorization service) is temporarily unavailable, in Anthropic error envelope format (error type “overloaded_error”). Retry after a short delay with exponential back-off.

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

Upstream provider error relayed with its original status code and translated into Anthropic error envelope format. The error type reflects the status code (e.g. “rate_limit_error” for 429, “overloaded_error” for 529).

Media typeapplication/json

Anthropic error envelope, as parsed by Anthropic SDKs.

object
type
required
string
Allowed values: error
error
required
object
type
required

Anthropic error type, e.g. “invalid_request_error”, “authentication_error”, “permission_error”, “not_found_error”, “request_too_large”, “rate_limit_error”, “overloaded_error”, “api_error”, or “content_policy_violation” (request content blocked by moderation policy — never identifies which filter or category matched).

string
message
required
string
request_id

Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.

string
Example
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "max_tokens is required and must be greater than zero",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}