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

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" }
  ]
}
FieldTypeDescriptionRequired
namestringStarts 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✓
descriptionstring10 to 1,000 characters. What it does and when to use it: it is what decides whether the agent calls it✓
displayNamestringName for people, up to 80 characters—
sourcestringThe complete TypeScript code, up to 100 KB. See code format. Without it, the template—
allowedDomainsstring[]Exact hosts the code can call, like api.example.com. HTTPS only, no scheme, port, path or wildcards. Up to 10—
timeoutSecondsintegerMaximum time of each execution, from 1 to 60. Default, 20—
secretSlotsarrayThe credentials the code uses, up to 10. See secretSlots—

secretSlots

FieldTypeDescription
slotstringName in uppercase letters, digits and _, starting with a letter, up to 64 characters. The code reads it as secrets.<slot>
originstringhttps:// 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

Statusdetails.codeWhen
400INVALID_REQUESTThe 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
403FORBIDDEN or INSUFFICIENT_SCOPEThe credential does not have write access to Integrations
409NAME_TAKENA function with that name already exists
409LIMIT_REACHEDThe workspace already has 20 functions

Notes

  • Follow what nextStep says. 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.