Create a function
SDK platic.tools.functions.create()
Create a function in the draft state. Only name and description are required; without source, it uses the starter template. It is not deployed or available to agents until you publish it.
Example
curl -X POST "https://api.platic.ai/v1/tools/functions" \
-H "Authorization: Bearer $PLATIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "tax_id_lookup",
"description": "Looks up a customer'\''s company name by tax ID.",
"allowedDomains": ["api.example.com"]
}' await platic.tools.functions.create({ name: "tax_id_lookup", description: "Looks up a customer's company name by tax ID.", allowedDomains: ["api.example.com"] }); Request body
{
"name": "tax_id_lookup",
"displayName": "Tax ID lookup",
"description": "Looks up a customer's company name by tax ID. Use it when the customer gives their tax ID.",
"source": "import { z } from \"zod\";\nimport { defineFunction } from \"@platica/functions\";\n\nexport default defineFunction({ … });\n",
"allowedDomains": ["api.example.com"],
"timeoutSeconds": 20,
"secretSlots": [
{ "slot": "API_KEY", "origin": "https://api.example.com" }
]
} | Field | Type | Description | Required |
|---|---|---|---|
name | string | Starts with a lowercase letter and uses lowercase letters, digits and _; 3 to 41 characters. The agent sees the tool as fn_<name>. It cannot be changed later | ✓ |
description | string | 10 to 1,000 characters. What it does and when to use it: it is what decides whether the agent calls it | ✓ |
displayName | string | Name for people, up to 80 characters | — |
source | string | The complete TypeScript code, up to 100 KB. See code format. Without it, the template | — |
allowedDomains | string[] | Exact hosts the code can call, like api.example.com. HTTPS only, no scheme, port, path or wildcards. Up to 10 | — |
timeoutSeconds | integer | Maximum time of each execution, from 1 to 60. Default, 20 | — |
secretSlots | array | The credentials the code uses, up to 10. See secretSlots | — |
secretSlots
| Field | Type | Description |
|---|---|---|
slot | string | Name in uppercase letters, digits and _, starting with a letter, up to 64 characters. The code reads it as secrets.<slot> |
origin | string | https:// origin the secret is sent to, and no other. Its host has to be in allowedDomains |
Declare the credential slot. Store its value as a workspace secret, then bind it.
Response
201 Created. data has the complete function, with the fields of Get a function. source is left out in the example.
{
"status": "success",
"message": "Function created as a draft",
"data": {
"id": "Hk2s9QmXc1",
"name": "tax_id_lookup",
"displayName": "Tax ID lookup",
"description": "Looks up a customer's company name by tax ID. Use it when the customer gives their tax ID.",
"status": "draft",
"draftChecksum": null,
"allowedDomains": ["api.example.com"],
"timeoutSeconds": 20,
"secretSlots": [
{ "slot": "API_KEY", "origin": "https://api.example.com" }
],
"inputSchema": null,
"liveVersion": null,
"lastVerify": null,
"createdAt": "2026-11-24T17:50:00.000Z",
"createdBy": "user:8sKd2LxQp0",
"updatedAt": "2026-11-24T17:50:00.000Z",
"updatedBy": "user:8sKd2LxQp0",
"toolName": "fn_tax_id_lookup",
"toolId": null,
"secrets": [
{ "slot": "API_KEY", "origin": "https://api.example.com", "state": "missing", "secretId": null }
],
"nextStep": "Verify the code with POST /v1/tools/functions/Hk2s9QmXc1/verify, bind the API_KEY secret with POST /v1/tools/functions/Hk2s9QmXc1/secrets, then test and publish."
}
} Errors
| Status | details.code | When |
|---|---|---|
400 | INVALID_REQUEST | The body fails validation: name in another format, description too short, a domain with a scheme or path, an origin whose host is not in allowedDomains. details.issues has the list of problems |
403 | FORBIDDEN or INSUFFICIENT_SCOPE | The credential does not have write access to Integrations |
409 | NAME_TAKEN | A function with that name already exists |
409 | LIMIT_REACHED | The workspace already has 20 functions |
Note
Continue with Verify a function to check the code before deploying. Each issue includes its line number.
Notes
- Follow what
nextStepsays. The order is verify, bind secrets, test and publish. - Get the environment gives the template and the exact types of
@platica/functions. - You can keep the code in your repository and create or update it from your CI.