Skip to content
WP EngineDocumentation

Create a session

POST
/v1/sessions
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.ai.wpengine.com/v1/sessions', [
'body' => '{ "agent": "agent_xyz", "title": "example", "reasoning_effort": "example", "metadata": { "additionalProperty": "example" }, "owner_id": "example", "site_ids": [ "example" ] }',
'headers' => [
'Authorization' => 'Bearer <token>',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();

Creates a conversation session bound to an agent. The agent field accepts either a string agent id or {id, type, version}. The session inherits its project from the referenced agent. Accepts a service-token bearer authenticating a site or an API key, either of which must be authorized for the agent’s project.

Media typeapplication/json
object
agent
required
One of:
string
title

Session title.

string
<= 512 characters
reasoning_effort

Optional session override for reasoning effort. Allowed values are the bound agent’s current model parameters.reasoning_effort on GET /v1/models. Omit to inherit the agent’s value (then the provider default).

string
metadata

String key-value metadata.

object
<= 16 properties
key
additional properties
string
owner_id

Opaque per-visitor id of the caller creating this session, for browser-session-backed consumers (e.g. a site widget minting per-visitor browser tokens). Recorded immutably and used to enforce per-visitor ownership on this session’s events for browser session tokens. Omit when the creator has no per-visitor concept.

string
<= 255 characters
site_ids

Sites this session may work on. Each must be a site registered in the agent’s project. Site and knowledge-base tool calls that name the session in the Agent-Session-Id header are refused for any other site, and for any knowledge base collection that is not one of these sites’ knowledge bases. Omit or send an empty array to allow every site in the project. An entry that is not such a site is rejected with 400 without saying why.

Array<string>
<= 100 items

Created session

Media typeapplication/json
object
id
required
string
type
required
string
Allowed values: session
agent
required
One of:
object
id
required

Unique identifier for the agent.

string
type
required
string
Allowed values: agent
project_id
required

The project the agent belongs to.

string
name
required
string
model
required
string
description

Free-form description of what the agent does. On an agent with a profile this is the profile’s current description.

string
system_prompt

User prompt template (site prompt). On an agent with a profile this is the profile’s current prompt.

string
profile

Server-owned profile the agent follows (see CreateAgentRequest.profile). Omitted when the client owns every field.

string
managed_fields

Fields owned by the agent’s profile, which the client cannot write. Omitted when the agent has no profile.

Array<string>
allowed_models

Models the agent’s profile allows as a model choice. Omitted when the agent has no profile.

Array<string>
temperature
number format: float
max_tokens

Output-token limit per turn (see CreateAgentRequest.max_tokens). Omitted when unset on the agent.

integer
reasoning_effort

Catalog-native reasoning effort stored on the agent. Omitted when unset. Allowed values follow the agent’s current model on GET /v1/models.

string
scopes

Permission scopes the agent operates under (round-trips the request value).

Array<string>
settings

Feature toggles for the agent (round-trips the request value).

object
key
additional properties
any
mcp_servers
Array<object>
object
key
additional properties
any
tools

Tool declarations (client tools, knowledge_base grounding entries, and echo/random_number evaluation tool opt-ins) round-tripped from the request.

Array
One of: discriminator: type
object
type

Discriminator for the tools[] union. Omit for a plain client tool (the default); custom is the only value this schema accepts.

string
Allowed values: custom
name

Unique tool name. Must be unique within the agent’s tools array (across every entry, regardless of type). Always present for tools created since name validation was added; may be absent on an agent whose tools were stored before that validation existed.

string
<= 64 characters /^[a-zA-Z0-9_-]{1,64}$/
description

Human-readable description of what the tool does.

string
input_schema

JSON Schema defining the tool’s input parameters.

object
label

Optional short human-readable name for the tool, used alongside name and description when the gateway matches a search query against deferred tools. Supply it when the tool’s name is a slug whose wording a natural-language query would not contain.

string
<= 64 characters
defer_loading

When true, the tool is declared but kept out of the model’s tool list until it is needed, so a large catalogue costs no context up front. The gateway offers the agent a search over the deferred tools and loads the matches, and a deferred tool the model names directly is loaded on demand. Once loaded, its input is enforced strictly against its schema — unlike a non-deferred tool, which keeps today’s lenient handling — so a malformed call is rejected with a model-readable error instead of failing downstream. Leave false (the default) for tools that must be callable from the first turn.

boolean
skills
Array<object>
object
key
additional properties
any
metadata

User-supplied string metadata. Reserved keys (“scopes”, “settings”) are surfaced on their own top-level fields rather than appearing here.

object
key
additional properties
string
<= 512 characters
created_at
required
string format: date-time
updated_at
string format: date-time
nullable
status
required
string
Allowed values: idle running rescheduling terminated error
title
string
reasoning_effort

Session override for reasoning effort. Omitted when unset (the session inherits the agent’s value, then the provider default).

string
metadata
object
key
additional properties
string
usage
required
object
input_tokens
required
integer
output_tokens
required
integer
cache_read_input_tokens
required
integer
cache_creation_input_tokens
required
integer
credits_nano
required

Cumulative billing total in nano-credits (billionths of a credit)

integer
archived_at
string format: date-time
nullable
created_at
required
string format: date-time
updated_at
string format: date-time
nullable
owner_id

Opaque per-visitor id recorded at creation, when the creator supplied one. Absent for sessions created without per-visitor attribution.

string
site_ids

Sites this session may work on, sorted. Empty when every site in the project is allowed.

Array<string>
Example
{
"type": "session",
"agent": {
"type": "agent",
"managed_fields": [
"model",
"system_prompt",
"description"
],
"tools": [
{
"type": "custom",
"defer_loading": false
}
]
},
"status": "idle"
}

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

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"
}
}

Request body exceeds the 64 KiB limit

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 server encountered an unexpected error while handling the request. Safe to retry once; if it persists, the cause is server-side and the request payload was not the problem.

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"
}
}

A required dependency is temporarily unavailable. Retry after a short delay with exponential back-off. An entitlement lookup failure uses error type “entitlement_unavailable”.

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"
}
}