Create a message (Anthropic Messages API)
package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.ai.wpengine.com/v1/messages"
payload := strings.NewReader("{ \"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 } }")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>") req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close() body, _ := io.ReadAll(res.Body)
fmt.Println(res) fmt.Println(string(body))
}const url = 'https://api.ai.wpengine.com/v1/messages';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, 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}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}<?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();curl --request POST \ --url https://api.ai.wpengine.com/v1/messages \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "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 } }'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.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”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
Anthropic model name, prefixed or bare (e.g. “anthropic/claude-sonnet-4-6” or “claude-sonnet-4-6”).
Example
anthropic/claude-sonnet-4-6Conversation turns in Anthropic message format.
object
Message content: a plain string, or an array of content blocks (text, image, tool_use, tool_result, thinking, …).
Maximum number of tokens to generate.
Example
1024System prompt, as a string or array of content blocks.
Tool definitions in Anthropic tool format, each with a name, description, and input_schema.
object
When true, the response is a Server-Sent Events stream using Anthropic’s streaming event protocol.
Extended thinking configuration.
object
Token budget for thinking when enabled.
Responses
Section titled “Responses”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
Generated content blocks (text, tool_use, thinking, …).
object
The matched custom stop sequence, when applicable.
object
Example
{ "id": "msg_01XFDUDYJgAACzvnptvVoYEL", "type": "message", "role": "assistant", "model": "claude-sonnet-4-6", "content": [ { "type": "text" } ], "stop_reason": "end_turn"}SSE stream of Anthropic message events
Invalid request body or parameters, in Anthropic error envelope format (error type “invalid_request_error”).
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
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”).
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
Example
{ "type": "error", "error": { "type": "invalid_request_error", "message": "max_tokens is required and must be greater than zero", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}Headers
Section titled “Headers”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.
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
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.
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
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”).
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
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”).
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
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.
Upstream provider returned an error, in Anthropic error envelope format (error type “api_error”).
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
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.
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
Example
{ "type": "error", "error": { "type": "invalid_request_error", "message": "max_tokens is required and must be greater than zero", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}default
Section titled “default”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).
Anthropic error envelope, as parsed by Anthropic SDKs.
object
object
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).
Correlation ID for this request, matching the X-Request-ID response header. Quote it in support reports.
Example
{ "type": "error", "error": { "type": "invalid_request_error", "message": "max_tokens is required and must be greater than zero", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}