Index a knowledge base document
package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.ai.wpengine.com/v1/kb/collections/example/documents"
payload := strings.NewReader("{ \"id\": \"example\", \"content\": \"example\", \"title\": \"example\", \"type\": \"example\", \"uri\": \"example\", \"language\": \"example\", \"created_at\": \"2026-04-15T12:00:00Z\", \"modified_at\": \"2026-04-15T12:00:00Z\", \"metadata\": { \"status\": \"publish\", \"category\": \"news\", \"tags\": [ \"guide\", \"billing\" ] } }")
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/kb/collections/example/documents';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"id":"example","content":"example","title":"example","type":"example","uri":"example","language":"example","created_at":"2026-04-15T12:00:00Z","modified_at":"2026-04-15T12:00:00Z","metadata":{"status":"publish","category":"news","tags":["guide","billing"]}}'};
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/kb/collections/example/documents', [ 'body' => '{ "id": "example", "content": "example", "title": "example", "type": "example", "uri": "example", "language": "example", "created_at": "2026-04-15T12:00:00Z", "modified_at": "2026-04-15T12:00:00Z", "metadata": { "status": "publish", "category": "news", "tags": [ "guide", "billing" ] } }', 'headers' => [ 'Authorization' => 'Bearer <token>', 'Content-Type' => 'application/json', ],]);
echo $response->getBody();curl --request POST \ --url https://api.ai.wpengine.com/v1/kb/collections/example/documents \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "id": "example", "content": "example", "title": "example", "type": "example", "uri": "example", "language": "example", "created_at": "2026-04-15T12:00:00Z", "modified_at": "2026-04-15T12:00:00Z", "metadata": { "status": "publish", "category": "news", "tags": [ "guide", "billing" ] } }'Indexes a single document into the collection. “content” is required and is the text indexed for search. An “id” may be supplied to make index idempotent (re-indexing the same id replaces the document); when omitted the gateway generates one. The “id” must not contain “/”. Concurrent writes to the same id are resolved last-writer-wins. Requires a valid WP Engine bearer token.
Authorizations
Section titled “Authorizations”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “Path Parameters”The collection ID.
Request Bodyrequired
Section titled “Request Bodyrequired”object
Stable document id. Supply it to make index idempotent (re-indexing the same id replaces the document); generated when omitted.
The document text indexed for search.
Document type (e.g. the WordPress post type).
Canonical URL for the document.
ISO 639-1 language code.
Free-form metadata; values are stored as keywords for exact-match filtering.
object
Example
{ "status": "publish", "category": "news", "tags": [ "guide", "billing" ]}Responses
Section titled “ Responses ”An existing id was re-indexed — “updated” if the document changed, or “unchanged” if it was identical (a no-op).
object
The document id (supplied or generated).
Example
{ "result": "created"}The document was created
object
The document id (supplied or generated).
Example
{ "result": "created"}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 token is valid, but the request is forbidden. Error type “permission_error” means the token’s scope/permission is insufficient or the authenticated user is not authorized for the target account; “entitlement_required” means the account lacks the required product entitlement; and “account_required” means no billing account could be resolved. On /v1/chat/completions when content moderation is enabled, and on /v1/sessions/{session_id}/events, 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.
The knowledge base is not currently available. Retry after a short delay.
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" }}