Create a chat completion
package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.ai.wpengine.com/v1/chat/completions"
payload := strings.NewReader("{ \"model\": \"google/gemini-3.5-flash\", \"messages\": [ { \"role\": \"user\", \"content\": \"Say hello in one short sentence.\" } ] }")
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/chat/completions';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"model":"google/gemini-3.5-flash","messages":[{"role":"user","content":"Say hello in one short sentence."}]}'};
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/chat/completions', [ 'body' => '{ "model": "google/gemini-3.5-flash", "messages": [ { "role": "user", "content": "Say hello in one short sentence." } ] }', 'headers' => [ 'Authorization' => 'Bearer <token>', 'Content-Type' => 'application/json', ],]);
echo $response->getBody();curl --request POST \ --url https://api.ai.wpengine.com/v1/chat/completions \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "google/gemini-3.5-flash", "messages": [ { "role": "user", "content": "Say hello in one short sentence." } ] }'Requires a valid WP Engine bearer token. API keys must carry the “chat:write” permission.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
Model identifier in the format “provider/model-name” (e.g. “openai/gpt-oss-120b-maas”, “google/gemini-3.5-flash”, “anthropic/claude-sonnet-4-6”).
Example
google/gemini-3.5-flashobject
Example
userExample
Say hello in one short sentence.Tool calls made by the assistant.
object
Example
functionobject
JSON-encoded arguments for the function call.
JSON Schema describing the function parameters.
ID of the tool call this message is a response to (role must be “tool”).
Sampling temperature. See the model’s parameters.temperature metadata on /models for the accepted range and support. Rejected with HTTP 400 when out of range, unsupported, or not applicable.
Nucleus sampling parameter.
Hard upper bound on output tokens for this request, forwarded to the model provider. Generation stops when the limit is reached; the response may be truncated mid-content rather than rejected. finish_reason: "length" (OpenAI-compatible routes) indicates the budget was hit. On reasoning-capable models (see capabilities on GET /v1/models), internal reasoning tokens may count against this budget alongside visible output. Per-model valid ranges are published in GET /v1/models/{model_id}/schema.
If true, the response is streamed as Server-Sent Events.
Stop sequences.
Tools available to the model. Function tools invoke caller-defined functions; native web_search tools enable server-side search on models that advertise the web_search capability (see GET /v1/models).
object
Example
functionobject
JSON-encoded arguments for the function call.
JSON Schema describing the function parameters.
object
Example
web_searchDomains the model may search. Omit to allow all domains supported by the provider.
Domains the model must not search.
Controls how the model selects tools. Can be “auto”, “none”, “required”, or an object specifying a particular function.
Structured output format. See the model’s parameters.response_format_type metadata on /models for the accepted values. Rejected with HTTP 400 when the type is unsupported or not applicable.
object
The response format type. Use “text” for plain text (default), “json_object” for unstructured JSON mode, or “json_schema” for structured output that conforms to a provided JSON Schema.
Example
json_schemaDescribes the JSON Schema the model must follow when response_format.type is “json_schema”.
object
A name identifying this schema (for caching and logging).
Example
recipeOptional human-readable description of the schema purpose.
A JSON Schema object describing the desired output structure. Supports standard JSON Schema types (object, array, string, number, integer, boolean) with provider-specific subset limitations.
object
Whether to request strict schema adherence. When true, the gateway forwards this preference to providers that support strict/JSON-schema-constrained decoding (for example, OpenAI and Anthropic). Not all providers honor this flag, and the gateway does not independently validate or guarantee schema compliance.
Catalog-native reasoning effort. Allowed values are the model’s parameters.reasoning_effort on GET /v1/models. Omit to use the provider default. Models that do not publish an enum reject any non-empty value. Mutually exclusive with provider_options.thinking_config on google/* models.
Example
highProvider-specific parameters. Supported openai/* and google/* models.
object
Example
{ "thinking_config": { "thinking_budget": 1024, "include_thoughts": true }}Example
{ "model": "google/gemini-3.5-flash", "messages": [ { "role": "user", "content": "Say hello in one short sentence." } ]}Responses
Section titled “Responses”Chat completion response. When stream is false, returns a single JSON object. When stream is true, returns Server-Sent Events with chunked JSON payloads terminated by a “data: [DONE]” message.
object
Unix timestamp.
object
object
Tool calls made by the assistant.
object
object
JSON-encoded arguments for the function call.
JSON Schema describing the function parameters.
ID of the tool call this message is a response to (role must be “tool”).
object
Example
{ "id": "chatcmpl-abc123", "object": "chat.completion", "choices": [ { "message": { "role": "system", "content": "Say hello in one short sentence.", "tool_calls": [ { "type": "function" } ] }, "finish_reason": "stop" } ]}SSE stream of ChatCompletionChunk objects
Invalid request body or parameters
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}Missing or invalid bearer token
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "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. Distinct from 429, which is edge rate limiting.
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}The token is valid, but the caller is not permitted to perform this action — either its scope/permission is insufficient or the authenticated user is not authorized for the target account (error type “permission_error”). On /v1/chat/completions 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.
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}The requested resource was not found
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "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
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}A required dependency is temporarily unavailable. Retry after a short delay with exponential back-off.
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}default
Section titled “default”Upstream provider error passed through with its original status code and response body. The shape may vary by provider.
object
object
Correlation ID for this request, matching the X-Request-ID response header — a 32-character trace ID behind the load balancer, otherwise a UUID. Quote it in support reports.
Example
{ "error": { "type": "invalid_request_error", "request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5" }}