Skip to main content

AI API

Endpoints for interacting with AI models through a unified provider layer. These endpoints are served by the backend API service, not the web application. They are available at the backend base URL, which may differ from the web API base URL depending on your deployment.
These endpoints are internal backend endpoints and are not exposed through the web application’s /api routes. All /api/ai/* endpoints require bearer token (API key) authentication — the auth middleware is applied at the router mount level, so requests without a valid token receive a 401 response regardless of the endpoint. The chat and cost estimation endpoints additionally require a valid subscription plan. All POST requests must include the Content-Type: application/json header.
All /api/ai/* endpoints share a rate limit of 30 requests per minute per IP, not just the chat endpoint.

Health check

Requires bearer token authentication. Returns the availability status of configured AI providers.

Response

The status field is healthy when the OpenRouter provider is reachable and degraded when it is not. Only the OpenRouter provider is checked.

Error response

When the provider check fails, the response uses status: "error" and includes the error message:

List models

Requires bearer token authentication. Returns all available AI models across providers.

Response

Errors

List models by provider

Requires bearer token authentication.

Path parameters

Response

Select model

Requires bearer token authentication and a valid subscription plan. Automatically selects the best model for a given task type.

Request body

Response

Errors

Chat completion

Send a chat completion request through the unified AI provider layer. The model is auto-selected if not specified.
This endpoint requires a valid subscription plan. Requests without a recognized plan or active Stripe subscription receive a 402 response. The requested model must also be available on your plan — see plan-based model access below.
The chat endpoint uses header-based authentication. Access control is enforced through the x-user-plan and x-stripe-subscription-id headers rather than JWT verification. Admin emails (configured via ADMIN_EMAILS) bypass both plan and subscription requirements.

Request headers

The following headers are required for plan enforcement:

Request body

Example request

Example request with Algorithm mode

When algorithmMode is enabled, the agent responds using a structured 7-phase format for non-trivial tasks:

Response

Returns a structured response with the following shape:

Errors

402 error example

403 error example

Token quotas (planned)

Token quotas are not yet enforced. The backend does not currently track token usage or reject requests based on usage limits. The quota system described below is planned for a future release. When implemented, requests exceeding the plan limit will be rejected with a 429 status and a QUOTA_EXCEEDED error code.

Plan-based model access

Each subscription plan grants access to a specific set of AI models. The chat endpoint enforces these limits automatically via the plan middleware.
Admin users are automatically granted network-level access regardless of their subscription plan.
The plan middleware (x-user-plan header) enforces model access, skill limits, and A2A message quotas. The provisioning endpoint enforces separate agent creation limits: solo 1, collective 3, label 10, network unlimited. The provisioning limits determine how many agents you can create, while the middleware limits in the table above apply to per-request AI model access and skill usage.

Model fallbacks

Each AI provider is configured with a primary model and a fallback model. When the primary model is unavailable or returns an error, the system automatically retries the request using the fallback model.
minimax (MiniMax/MiniMax-Text-01) is available in the provider configuration map but is not currently supported in the model fallback chain. It may be enabled in a future release.
Fallback routing is handled transparently. The response always indicates which model ultimately served the request via the model field.

Task-based model selection

In addition to provider-level fallbacks, the backend AI service uses tag-based model selection that picks the best available model based on the type of work being performed. When you specify a taskType, the system searches the available OpenRouter models for matching capability tags and selects the first match. When no model matches the requested task tags, the first available model from the OpenRouter catalog is used as a fallback. All task-based requests are routed through OpenRouter.

Algorithm mode

The chat endpoint supports an optional structured problem-solving mode called PAI Algorithm mode. When enabled via the algorithmMode parameter, a system prompt is injected that instructs the model to process non-trivial tasks using a 7-phase format: The Algorithm system prompt is prepended to the messages array as a system message. If the messages already contain a system message with Algorithm phase markers, the prompt is not duplicated. For simple greetings or acknowledgments, the model skips the 7-phase format and responds naturally.
Algorithm mode is opt-in and does not affect billing or model selection. It only modifies the system prompt sent to the model. Based on Daniel Miessler’s TheAlgorithm v0.2.24.

Estimate cost

Requires bearer token authentication and a valid subscription plan. Estimate the cost of a request based on token counts and model pricing.

Request body

Response

Errors