AI Proxy (Preview)
POST/api/v2/aiproxy/chat/completions
> 🧪 Preview — This endpoint is in preview and its contract may change.
Executes an AI Proxy agent through an OpenAI-compatible Chat Completions API. Call it with the OpenAI SDKs by pointing the base URL at this route and passing your Serenity API key as a Bearer token.
Select the agent with the standard model property using the format agentCode:vendor:model (e.g. generic-proxy:OpenAI:gpt-5.4-mini). Use extra_body for execution attribution only (channel, user_identifier, group_identifier).
The tools array accepts OpenAI function (client) tools — declaration-only: when the model calls one, the call is returned to you to run, and you send the result back on a follow-up request — and AI Proxy server tools that run entirely on the server: web_search, image_generation, speech_generation and workbench. For each server tool, model/vendor (and voice/speed for speech_generation) are optional and fall back to the agent's configured defaults.
Structured output is supported through response_format: text returns plain text, json_object returns free-form JSON, and json_schema constrains the reply to a JSON schema you supply. The requested format is validated against the selected model's capabilities, so a model that cannot honour it is rejected rather than silently ignoring it.
Reasoning models are steered with the top-level reasoning_effort string, which is all the Chat Completions protocol carries. The accepted values come from the selected model's own configuration, so a model that does not expose the parameter rejects the request rather than ignoring it.
When a skill on the agent is configured to require approval, the run pauses and both the approval request and your decision travel as messages in the conversation history. See Skill Approvals for the message shapes and the full flow.
When stream is true, the response is delivered as Server-Sent Events (SSE).
Request​
Query Parameters
Use this param to override the culture of the response. Options: - en (default) - es
- application/json
Body
required
Array [
- DeveloperMessage
- SystemMessage
- UserMessage
- AssistantMessage
- ToolMessage
- FunctionMessage
]
- TextResponseFormat
- JsonObjectResponseFormat
- JsonSchemaResponseFormat
Array [
]
Array [
- FunctionTool
- CustomTool
]
extra_body
object
The OpenAI extra_body extension object of an AI Proxy request. Carries fields that are not part of the standard OpenAI request body but are used to attribute the AI Proxy agent execution. The agent, vendor and model are selected through the standard model property (agentCode:vendor:model), not here.
The channel the execution is attributed to.
Identifies the end user the execution is attributed to (usage tracking and per-user attribution).
Identifies the group the execution is attributed to.
messages
object[]
nullable
required
oneOf
content
object
required
content
object
required
content
object
required
content
object
required
content
object
required
content
object
required
logit_bias
object
nullable
metadata
object
nullable
response_format
object
The format the model must reply in. Exactly one of the three shapes.
oneOf
Plain text output. The default when response_format is omitted.
Possible values: [text]
Free-form JSON output. The prompt must still instruct the model to produce JSON.
Possible values: [json_object]
JSON output constrained to the supplied schema.
Possible values: [json_schema]
json_schema
object
required
stop
object
tool_choice
object
allowedTools
object
allowed_tools
object
required
tools
object[]
nullable
required
function
object
functionTool
object
function
object
required
customTool
object
custom
object
required
tools
object[]
nullable
oneOf
function
object
required
custom
object
required
format
object
Responses​
- 200
- 400
- 401
- 403
- 429
- 500
- 502
OK
There was a validation error. Please check your request data.
- application/json
- Schema
- Example (from schema)
Schema
- MOD1
- MOD2
Array [
]
Array [
]
Array [
]
Stable, machine-readable error code. Branch on this value, not on message.
Human-readable, localised summary of the error.
Link to the documentation section for this error code.
errors
object
nullable
Map of keys (an invalid request field or the rule that failed) to messages. Only present when the error has specific detail to report. Values are strings, except on input_validation_error, where each value is an array of messages for that field.
property name*
object
nullable
oneOf
string
string
attempts
object[]
nullable
One entry per attempt to call the AI provider, in order. Only present on agent_execution_failed and aiservice_execution_failed.
Zero-based index of the attempt.
Model pool an agent attempt used: main or fallback. Omitted for AI service attempts.
Error code of this attempt, e.g. vendor_rate_limit_error. See Vendor error codes on the API Errors page.
Raw HTTP status the AI provider returned for this attempt. Informational only; it does not set the response status.
Human-readable, localised summary of this attempt's failure.
errors
object
nullable
Detail for this attempt, e.g. vendor_error with the provider-supplied message.
agentResult
object
nullable
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
pendingActions
object[]
nullable
Tool calls the agent was waiting on for approval when it stopped (tool_approval_pending). Only present on agent validation failures.
arguments
object
nullable
The JSON the agent generated before it was rejected by the response-format validation. Only present on agent validation failures.
{
"code": "string",
"message": "string",
"documentationUrl": "string",
"errors": {},
"attempts": [
{
"index": 0,
"modelType": "string",
"code": "string",
"statusCode": 0,
"message": "string",
"errors": {}
}
],
"agentResult": {},
"pendingActions": [
{
"type": "string",
"requestId": "string",
"callId": "string",
"skillCode": "string",
"skillType": "string",
"tool": "string",
"arguments": {}
}
],
"generatedJson": "string"
}
The user is unauthorized or the session expired
- application/json
- Schema
- Example (from schema)
Schema
Stable, machine-readable error code. Branch on this value, not on message.
Human-readable, localised summary of the error.
Link to the documentation section for this error code.
{
"code": "string",
"message": "string",
"documentationUrl": "string"
}
The user does not have permission
- application/json
- Schema
- Example (from schema)
Schema
Stable, machine-readable error code. Branch on this value, not on message.
Human-readable, localised summary of the error.
Link to the documentation section for this error code.
{
"code": "string",
"message": "string",
"documentationUrl": "string"
}
If the API rate limit was exceeded, or every attempt was rate-limited by the AI provider. Wait for the time given in the Retry-After header before retrying.
- application/json
- Schema
- Example (from schema)
Schema
- MOD1
- MOD2
Array [
]
Array [
]
Array [
]
Stable, machine-readable error code. Branch on this value, not on message.
Human-readable, localised summary of the error.
Link to the documentation section for this error code.
errors
object
nullable
Map of keys (an invalid request field or the rule that failed) to messages. Only present when the error has specific detail to report. Values are strings, except on input_validation_error, where each value is an array of messages for that field.
property name*
object
nullable
oneOf
string
string
attempts
object[]
nullable
One entry per attempt to call the AI provider, in order. Only present on agent_execution_failed and aiservice_execution_failed.
Zero-based index of the attempt.
Model pool an agent attempt used: main or fallback. Omitted for AI service attempts.
Error code of this attempt, e.g. vendor_rate_limit_error. See Vendor error codes on the API Errors page.
Raw HTTP status the AI provider returned for this attempt. Informational only; it does not set the response status.
Human-readable, localised summary of this attempt's failure.
errors
object
nullable
Detail for this attempt, e.g. vendor_error with the provider-supplied message.
agentResult
object
nullable
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
pendingActions
object[]
nullable
Tool calls the agent was waiting on for approval when it stopped (tool_approval_pending). Only present on agent validation failures.
arguments
object
nullable
The JSON the agent generated before it was rejected by the response-format validation. Only present on agent validation failures.
{
"code": "string",
"message": "string",
"documentationUrl": "string",
"errors": {},
"attempts": [
{
"index": 0,
"modelType": "string",
"code": "string",
"statusCode": 0,
"message": "string",
"errors": {}
}
],
"agentResult": {},
"pendingActions": [
{
"type": "string",
"requestId": "string",
"callId": "string",
"skillCode": "string",
"skillType": "string",
"tool": "string",
"arguments": {}
}
],
"generatedJson": "string"
}
There was an unexpected error
- application/json
- Schema
- Example (from schema)
Schema
- MOD1
- MOD2
Array [
]
Array [
]
Array [
]
Stable, machine-readable error code. Branch on this value, not on message.
Human-readable, localised summary of the error.
Link to the documentation section for this error code.
errors
object
nullable
Map of keys (an invalid request field or the rule that failed) to messages. Only present when the error has specific detail to report. Values are strings, except on input_validation_error, where each value is an array of messages for that field.
property name*
object
nullable
oneOf
string
string
attempts
object[]
nullable
One entry per attempt to call the AI provider, in order. Only present on agent_execution_failed and aiservice_execution_failed.
Zero-based index of the attempt.
Model pool an agent attempt used: main or fallback. Omitted for AI service attempts.
Error code of this attempt, e.g. vendor_rate_limit_error. See Vendor error codes on the API Errors page.
Raw HTTP status the AI provider returned for this attempt. Informational only; it does not set the response status.
Human-readable, localised summary of this attempt's failure.
errors
object
nullable
Detail for this attempt, e.g. vendor_error with the provider-supplied message.
agentResult
object
nullable
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
pendingActions
object[]
nullable
Tool calls the agent was waiting on for approval when it stopped (tool_approval_pending). Only present on agent validation failures.
arguments
object
nullable
The JSON the agent generated before it was rejected by the response-format validation. Only present on agent validation failures.
{
"code": "string",
"message": "string",
"documentationUrl": "string",
"errors": {},
"attempts": [
{
"index": 0,
"modelType": "string",
"code": "string",
"statusCode": 0,
"message": "string",
"errors": {}
}
],
"agentResult": {},
"pendingActions": [
{
"type": "string",
"requestId": "string",
"callId": "string",
"skillCode": "string",
"skillType": "string",
"tool": "string",
"arguments": {}
}
],
"generatedJson": "string"
}
If every attempt failed because of an AI provider error.
- application/json
- Schema
- Example (from schema)
Schema
- MOD1
- MOD2
Array [
]
Array [
]
Array [
]
Stable, machine-readable error code. Branch on this value, not on message.
Human-readable, localised summary of the error.
Link to the documentation section for this error code.
errors
object
nullable
Map of keys (an invalid request field or the rule that failed) to messages. Only present when the error has specific detail to report. Values are strings, except on input_validation_error, where each value is an array of messages for that field.
property name*
object
nullable
oneOf
string
string
attempts
object[]
nullable
One entry per attempt to call the AI provider, in order. Only present on agent_execution_failed and aiservice_execution_failed.
Zero-based index of the attempt.
Model pool an agent attempt used: main or fallback. Omitted for AI service attempts.
Error code of this attempt, e.g. vendor_rate_limit_error. See Vendor error codes on the API Errors page.
Raw HTTP status the AI provider returned for this attempt. Informational only; it does not set the response status.
Human-readable, localised summary of this attempt's failure.
errors
object
nullable
Detail for this attempt, e.g. vendor_error with the provider-supplied message.
agentResult
object
nullable
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
The partial agent result produced before validation failed (same shape as a successful execution result). Only present on agent validation failures.
pendingActions
object[]
nullable
Tool calls the agent was waiting on for approval when it stopped (tool_approval_pending). Only present on agent validation failures.
arguments
object
nullable
The JSON the agent generated before it was rejected by the response-format validation. Only present on agent validation failures.
{
"code": "string",
"message": "string",
"documentationUrl": "string",
"errors": {},
"attempts": [
{
"index": 0,
"modelType": "string",
"code": "string",
"statusCode": 0,
"message": "string",
"errors": {}
}
],
"agentResult": {},
"pendingActions": [
{
"type": "string",
"requestId": "string",
"callId": "string",
"skillCode": "string",
"skillType": "string",
"tool": "string",
"arguments": {}
}
],
"generatedJson": "string"
}