---
docId: doc_b951f5e8f3684701a4a14163e42e24fc
title: Create a function
description: "Create a custom function draft."
api:
  group: herramientas/funciones-personalizadas
  auth: bearer
  operations:
    - operationId: createFunction
      method: POST
      path: /v1/tools/functions
      postmanName: Create a function
---

<script>
  import { Ways, Note } from '$lib/components';
</script>

# Create a function

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](/api-reference/custom-functions/publish).

## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
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"]
}'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.tools.functions.create({ name: "tax_id_lookup", description: "Looks up a customer's company name by tax ID.", allowedDomains: ["api.example.com"] });
```

</Ways.Way>
</Ways>

## Request body

```json
{
  "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](/api-reference/custom-functions#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) | — |

### `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](/api-reference/secrets/create), then [bind it](/api-reference/custom-functions/bind-secret).

## Response

`201 Created`. `data` has the complete function, with the fields of [Get a function](/api-reference/custom-functions/get#response-fields). `source` is left out in the example.

```json
{
  "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 type="note">

Continue with [Verify a function](/api-reference/custom-functions/verify) to check the code before deploying. Each issue includes its line number.

</Note>

## Notes

- Follow what `nextStep` says. The order is [verify](/api-reference/custom-functions/verify), [bind secrets](/api-reference/custom-functions/bind-secret), [test](/api-reference/custom-functions/test) and [publish](/api-reference/custom-functions/publish).
- [Get the environment](/api-reference/custom-functions/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.
