Skip to content
WP EngineDocumentation

Search a knowledge base collection

POST
/v1/kb/collections/{id}/search
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.ai.wpengine.com/v1/kb/collections/example/search', [
'body' => '{ "query": "example", "filters": { "type": [ "example" ], "uri": [ "example" ], "language": [ "example" ], "metadata": { "status": [ "publish" ], "category": [ "news", "guides" ] }, "created_at": { "gte": "2026-04-15T12:00:00Z", "lte": "2026-04-15T12:00:00Z" }, "modified_at": { "gte": "2026-04-15T12:00:00Z", "lte": "2026-04-15T12:00:00Z" } }, "sort": [ { "field": "created_at", "order": "asc" } ], "aggregations": [ { "name": "example", "field": "example", "type": "terms", "interval": "day", "size": 1 } ], "top_n": 1 }',
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();

Searches a collection. Supply a query for combined keyword and semantic matching, returning the most relevant results each with source attribution and matching snippets. Omit the query to browse, filter, sort, or aggregate the collection (no snippets are returned). Narrow results with exact-match filters on post type, URI, language, or metadata, or with created_at/modified_at date ranges. Request facet counts and metrics via aggregations. Requires a valid WP Engine bearer token with search access.

id
required
string

The collection ID.

Agent-Session-Id
string

Optional. The agent session this search is being performed for, when the call answers a tool request from that session. Used only to group the call with the rest of the session’s activity in observability data. It is ignored unless it names a session in the same project as the caller, and it never changes the response.

Media typeapplication/json

A search over a collection. Supply query for ranked hybrid retrieval (results include snippets). Omit query to browse, filter, sort, or aggregate the collection; query-less results carry no snippets. Aggregations may be requested in either mode.

object
query

Optional natural-language query. When present, results are ranked by relevance and include snippets.

string
filters

Filters applied alongside the query.

object
type

Post types to include.

Array<string>
uri

Document URIs to include.

Array<string>
language

ISO 639-1 language codes to include.

Array<string>
metadata

Exact-match filters keyed by metadata field; each field maps to a list of accepted values.

object
key
additional properties
Array<string>
Example
{
"status": [
"publish"
],
"category": [
"news",
"guides"
]
}
created_at

Inclusive date bounds (RFC-3339). Either bound may be omitted.

object
gte
string format: date-time
lte
string format: date-time
modified_at

Inclusive date bounds (RFC-3339). Either bound may be omitted.

object
gte
string format: date-time
lte
string format: date-time
sort

Order results by typed fields. Supplying sort returns field-ordered results instead of relevance-ranked ones.

Array<object>
object
field
required
string
Allowed values: created_at modified_at title.keyword type uri language
order

Defaults to asc.

string
Allowed values: asc desc
aggregations

Facet counts and metrics computed over the filtered result set.

Array<object>
object
name
required

Key the result is returned under.

string
field
required

Field to aggregate. terms accepts keyword fields (type, uri, language, title.keyword) or metadata.; min/max/date_histogram accept created_at or modified_at.

string
type
required
string
Allowed values: terms min max date_histogram
interval

Required for date_histogram; invalid for other types.

string
Allowed values: day week month quarter year
size

Maximum number of terms buckets to return (default 10). Valid only for terms; invalid for other types.

integer
>= 1 <= 1000
top_n

Maximum results to return (defaults to 10; must be between 1 and 50).

integer
>= 1 <= 50

Ranked results with source attribution

Media typeapplication/json
object
citations
required
Array<object>

A ranked result with its source attribution and matching snippet(s).

object
id
required

The document id.

string
title
string
uri
string
type

The document’s post type.

string
snippets

The matching content fragment(s).

Array<string>
score
required

The relevance score used to rank this result; higher is more relevant.

number format: double
aggregations

Present only when aggregations were requested; keyed by aggregation name.

object
key
additional properties

Buckets for terms/date_histogram; value for min/max on date fields.

object
buckets
Array<object>
object
key
string
doc_count
integer format: int64
value

RFC-3339 timestamp for min/max on date fields.

string
other_doc_count

Terms only. Documents in buckets beyond the returned size. A non-zero value means the facet was truncated; request a larger size to retrieve more buckets.

integer format: int64
Examplegenerated
{
"citations": [
{
"id": "example",
"title": "example",
"uri": "example",
"type": "example",
"snippets": [
"example"
],
"score": 1
}
],
"aggregations": {
"additionalProperty": {
"buckets": [
{
"key": "example",
"doc_count": 1
}
],
"value": "example",
"other_doc_count": 1
}
}
}

Invalid request body or parameters

Media typeapplication/json
object
error
required
object
message
required
string
type
required
string
code
required
integer
request_id
required

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.

string
Example
{
"error": {
"type": "invalid_request_error",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

Missing or invalid bearer token

Media typeapplication/json
object
error
required
object
message
required
string
type
required
string
code
required
integer
request_id
required

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.

string
Example
{
"error": {
"type": "invalid_request_error",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}
WWW-Authenticate
string
Example
Bearer realm="ai-services"

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.

Media typeapplication/json
object
error
required
object
message
required
string
type
required
string
code
required
integer
request_id
required

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.

string
Example
{
"error": {
"type": "invalid_request_error",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}

The requested resource was not found

Media typeapplication/json
object
error
required
object
message
required
string
type
required
string
code
required
integer
request_id
required

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.

string
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.

Media typetext/html
string

The knowledge base is not currently available. Retry after a short delay.

Media typeapplication/json
object
error
required
object
message
required
string
type
required
string
code
required
integer
request_id
required

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.

string
Example
{
"error": {
"type": "invalid_request_error",
"request_id": "80f1e2c3a4b5c6d7e8f9a0b1c2d3e4f5"
}
}