AI Functions¶
An AI Function wraps an LLM as a first-class Poly resource. You set a system prompt, typed arguments, and optional tool functions (API or server functions the model may call). After generate, it appears in the SDK as poly.<context>.<name>.
Shipped in Release 33. Use the v2 API under /functions/ai. The older /ai-functions (slug / GPT-plugin) surface is deprecated for new work.
Before you execute¶
API key needs permission to manage AI functions (v1
manageAiFunctions) to create or update, and execute to run them.Create a tenant config variable that holds your provider API key. Execute fails until that is set.
Default provider is
openai, default model isgpt-5.5, defaultapiTypeisresponses.
AI Function execute is metered separately from server function executions. For current SKUs and tiers see PolyAPI pricing.
Create¶
POST /functions/ai. name is required.
{
"name": "summarizeTicket",
"context": "support",
"description": "Summarize a support ticket",
"systemPrompt": "You are a support assistant.",
"toolFunctionIds": ["<api-or-server-function-id>"],
"toolFunctions": [
{
"id": "<function-id>",
"argumentConfig": {
"apiKey": { "source": "variable", "variableId": "<vari-id>" },
"query": { "source": "ai" }
}
}
],
"enabled": true
}
Useful optional fields (Create v2 DTO):
Field |
Role |
|---|---|
|
Namespace; SDK path |
|
LLM. Defaults |
|
Model instructions. |
|
Load the system prompt from a Vari instead of (or in addition to) the inline field. |
|
Optional template for building model input from arguments. |
|
Typed I/O. A structured |
|
API or server function ids the model may call. |
|
Same tools, plus per-argument |
|
Optional caller prompt argument. |
|
If |
|
Default |
Also: GET/PATCH/DELETE /functions/ai/:id, GET /functions/ai to list.
Execute¶
POST /functions/ai/:id/execute with a JSON object of argument names to values. Requires an API key with Execute and access to the function.
POST /functions/ai/{id}/execute
Authorization: Bearer <api-key>
Content-Type: application/json
{ "ticketText": "Customer cannot log in" }
Then generate the SDK:
$ npx poly generate
$ python -m polyapi generate
TypeScript and Python both render AI Functions. Call poly.<context>.<name>(...) the same way you call other generated functions.
Tools¶
Attach tools with toolFunctionIds (ids only) and/or toolFunctions (ids plus argument sources).
Each tool argument source is one of:
|
Fill |
|---|---|
|
Model chooses the value (default if omitted) |
|
Fixed value you store on the tool config |
|
Taken from the AI Function’s own execute arguments |
|
Taken from a Vari ( |
Helper: POST /functions/ai/resolve-tool-functions with body { "ids": ["…"] }.
Logs¶
TEXT executions only. GET /functions/ai/:id/logs.
Query params:
lastHoursorlastDays(not both)limit(max 100)executionId,keyword,level
DELETE /functions/ai/:id/logs clears stored logs for that function.
Permissions¶
Action |
v1 flag / v2 resource |
|---|---|
Create |
|
Update / delete |
Entity access + |
Execute |
Entity access + |
v2 catalog |
Resource |
Keys that already had manageApiFunctions were granted manageAiFunctions in the permissions migration.
Limits and caveats¶
Do not use the legacy
/ai-functionsslug API for new work.Chat traffic is also subject to a chat-questions rate limit on the API.
Related: Functions (when to use a server or API function as a tool), Vari Variables (keys and prompt Vari).