---
docId: doc_d72b3829dccb4daaab02890a58df9df3
title: Create an API
description: Create a custom API as a draft. You can bind its secrets in the same call.
api:
  group: herramientas/apis-personalizadas
  auth: bearer
  operations:
    - operationId: createApiTool
      method: POST
      path: /v1/tools/apis
      postmanName: Create an API
---

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

# Create an API

Define an HTTP tool by sending `name` and `description`. You can complete the request and variables later with [Update an API](/api-reference/custom-apis/update). It is created as `draft`; to use it, bind credentials, test it and publish it.

## Example

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

```bash
curl -X POST "https://api.platic.ai/v1/tools/apis" \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "order_status",
  "description": "Looks up an order by its number."
}'
```

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

```ts
await platic.tools.apis.create({ name: "order_status", description: "Looks up an order by its number." });
```

</Ways.Way>
</Ways>

## Request body

```json
{
  "name": "order_lookup",
  "description": "Looks up the status of an Example Store order by its number. Use it when the customer asks where their order is.",
  "request": {
    "method": "GET",
    "url": "https://api.example-store.com/orders/{{orderId}}",
    "headers": [
      { "key": "Accept", "value": "application/json" }
    ],
    "auth": { "type": "bearer" }
  },
  "variables": [
    {
      "name": "orderId",
      "type": "string",
      "description": "Order number, as it appears in the confirmation email.",
      "required": true
    }
  ],
  "response": {
    "path": "data",
    "exclude": ["internal_notes"]
  },
  "secrets": {
    "auth.token": "5d0c7a1e9b3f4a6c8e2d1f0b7a9c3e5d6f8a0b2c4d6e8f1a3b5c7d9e0f2a4b6c"
  }
}
```

Use `request.auth` to select `bearer` authentication, then bind the token as a secret in `auth.token`.

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `name` | string | Lowercase letters, digits and `_`; starts with a letter or digit; up to 63 characters. The agent sees it as `api_<name>` | ✓ |
| `description` | string | 10 to 1,024 characters. Explains when the agent should use it | ✓ |
| `request` | object | The HTTP request. See [`request`](#request) | — |
| `variables` | array | Who fills each `{{name}}`. Up to 50. See [variables](#variables) | — |
| `context` | object | `{ "lastMessagesN": 10 }`: how many messages `lastMessages` delivers, from 1 to 50 | — |
| `mapping` | object | `bodyStrategy` (`merge`, `replace` or `none`) and `extraBody`, an object with fixed pairs for the body | — |
| `response` | object | Which part of the response the agent receives. See [`response`](#response) | — |
| `periodicAuth` | object | Uses a token that is renewed by a periodic authentication configured in Platica: `cronJobId` and `inject` (`in`: `header` or `query`; `key`; optional `valuePrefix` and `valueSuffix`) | — |
| `encryptPayload` | object | Signs the body as a JWT. `{ "ttlSeconds": 60 }`, from 5 to 3,600. The signing key is the `encryptPayload.key` slot | — |
| `secrets` | object | Map of slot to secret ID, to bind in this same call | — |

### `request`

```json
{
  "method": "POST",
  "url": "https://api.example-store.com/orders",
  "params": [
    { "key": "locale", "value": "en-US" }
  ],
  "headers": [
    { "key": "Content-Type", "value": "application/json" },
    { "key": "X-Api-Key", "value": "" }
  ],
  "body": {
    "mode": "json",
    "raw": "{ \"customer\": \"{{customerId}}\", \"note\": \"{{note}}\" }"
  },
  "auth": { "type": "none" },
  "settings": { "timeoutMs": 30000 }
}
```

| Field | Type | Description |
|-------|------|-------------|
| `method` | string | `GET`, `POST`, `PUT`, `PATCH` or `DELETE` |
| `url` | string | Destination URL, up to 1,000 characters. Accepts `{{variable}}`. A draft can be saved without a URL; testing and publishing require it. It has to be public: localhost, `.local`, `.internal` and private IPs are rejected |
| `params` | array | Query parameters as `{ key, value, description?, enabled? }`. Up to 25 |
| `pathVariables` | array | Path variables, with the same shape. Up to 25 |
| `headers` | array | Headers, with the same shape. Up to 25. A header that carries a credential goes with an empty `value` and is bound as `header:<name>` |
| `body` | object | `{ "mode": "none" }`, `{ "mode": "json", "raw": "…" }`, `{ "mode": "text", "raw": "…" }` or `{ "mode": "form-urlencoded", "pairs": [ … ] }`. `raw` accepts up to 16,000 characters; `pairs`, up to 50 |
| `auth` | object | How it authenticates, without the credential: `{ "type": "none" }`, `{ "type": "bearer" }`, `{ "type": "basic", "username": "…" }` or `{ "type": "apikey", "key": "…", "in": "header" \| "query" }` |
| `settings.timeoutMs` | number | From 1,000 to 60,000. Default, 30,000 |
| `settings.followRedirects` | boolean | Whether it follows redirects |

A row with `"enabled": false` is kept but not sent. Any `value` accepts `{{variable}}`.

### Variables

```json
[
  {
    "name": "orderId",
    "type": "string",
    "description": "Order number, as it appears in the confirmation email.",
    "required": true,
    "mode": "ai"
  },
  {
    "name": "phone",
    "type": "string",
    "description": "The customer's phone number.",
    "required": true,
    "mode": "context",
    "contextField": "phoneNumber"
  },
  {
    "name": "partnerKey",
    "type": "string",
    "description": "Shipping provider key.",
    "required": true,
    "mode": "secret"
  }
]
```

| Field | Type | Description |
|-------|------|-------------|
| `name` | string | Used as `{{name}}` inside `request`. Up to 64 characters |
| `type` | string | `string`, `number`, `integer`, `boolean`, `array` or `object` |
| `description` | string | Up to 1,024 characters. In `ai` mode it is what the agent reads, and publishing requires it |
| `required` | boolean | Whether the agent must always send it |
| `mode` | string | `ai` (default), `constant`, `context` or `secret` |
| `constantValue` | any | Only with `mode: "constant"` |
| `contextField` | string | Only with `mode: "context"`: `phoneNumber`, `workspaceId`, `conversationId`, `agentId`, `agentName`, `channelId`, `lastMessages` or `contact.<field>` for a contact field |
| `enum`, `format`, `pattern`, `minLength`, `maxLength`, `minimum`, `maximum`, `items`, `default` | various | Constraints that pass to the schema the agent sees |

For a `secret` variable, use `type: "string"`. Its name must start with a letter or `_` and contain only letters, digits and `_`. No other fields are accepted. Its value comes from the secret bound to `variable:<name>`; use it in headers, query parameters or the body. It cannot be used in the destination URL.

### `response`

Use `response` to select the data the agent needs and reduce the response it receives.

| Field | Type | Description |
|-------|------|-------------|
| `path` | string | Path to the useful part, for example `data.items`. Leave it out if the fields are at the root |
| `strictPath` | boolean | With `true`, the call fails if `path` does not exist |
| `include` | string[] | Only these fields. Up to 50 |
| `exclude` | string[] | All but these. Up to 50 |
| `maxBytes` | number | Maximum response size. Default, 32,000 |
| `binary` | string | `auto`, `always` or `never`. A PDF, an image or a spreadsheet is stored and the agent receives a descriptor with a signed URL |
| `filename` | string | Name of the stored file, up to 120 characters |

## Response

`201 Created`. `data` has the complete API, with the fields of [Get an API](/api-reference/custom-apis/get#response-fields).

```json
{
  "status": "success",
  "message": "API tool created successfully",
  "data": {
    "id": "RuzoaswTBBrhutHyKYZn",
    "toolName": "api_order_lookup",
    "name": "order_lookup",
    "description": "Looks up the status of an Example Store order by its number. Use it when the customer asks where their order is.",
    "status": "draft",
    "version": 1,
    "variables": [
      {
        "name": "orderId",
        "type": "string",
        "description": "Order number, as it appears in the confirmation email.",
        "required": true,
        "mode": "ai"
      }
    ],
    "response": { "path": "data", "exclude": ["internal_notes"] },
    "request": {
      "method": "GET",
      "url": "https://api.example-store.com/orders/{{orderId}}",
      "headers": [{ "key": "Accept", "value": "application/json" }],
      "auth": { "type": "bearer" }
    },
    "createdAt": "2026-10-28T12:05:03.902Z",
    "updatedAt": "2026-10-28T12:05:03.902Z",
    "lastTest": null,
    "verified": false,
    "secrets": [
      {
        "slot": "auth.token",
        "state": "authorized",
        "secretId": "5d0c7a1e9b3f4a6c8e2d1f0b7a9c3e5d6f8a0b2c4d6e8f1a3b5c7d9e0f2a4b6c"
      }
    ],
    "secretsRedacted": true,
    "nextStep": "Run a real test with POST /v1/tools/apis/RuzoaswTBBrhutHyKYZn/test and dryRun false. Enabling requires a successful real test of the current configuration."
  }
}
```

## Errors

| Status | `details.code` | When |
|--------|----------------|------|
| `400` | `INVALID_REQUEST` | The body fails validation: `name` in another format, `description` too short, a field with a value that is not accepted. `details.issues` has the list of problems, each with `path` and `message` |
| `400` | `SECRET_REFERENCE_REQUIRED` | You sent a credential inside the definition: in `request.auth`, in `encryptPayload.key`, in the URL or in a header with a credential name. When it applies, `details.slot` says the slot to bind |
| `400` | `INVALID_CONFIG` | The definition is not valid, for example a `context` variable without `contextField`, a `secret` variable used in the URL or a `request.url` pointing to localhost, `.local`, `.internal` or a private IP, which Platica's servers cannot reach |
| `403` | `FORBIDDEN` | The person behind the token does not have access to Integrations |
| `404` | `CRON_NOT_FOUND` | `periodicAuth.cronJobId` does not exist |
| `409` | `NAME_CONFLICT` | Another tool with that name already exists in the workspace |

<Note type="note">

If the API is saved but a secret in `secrets` cannot be bound, the response is still `201` and `data.secretsError` has `{ code, message }` with the reason. Do not create it again: bind the secret with [Bind a secret](/api-reference/custom-apis/bind-secret).

</Note>

## Notes

- Follow what `nextStep` says. The order is [bind secrets](/api-reference/custom-apis/bind-secret), [test](/api-reference/custom-apis/test) and [publish](/api-reference/custom-apis/publish).
- Secret IDs come from [List secrets](/api-reference/secrets/list) or [Create a secret](/api-reference/secrets/create).
- To start from an API that already works, use [Clone an API](/api-reference/custom-apis/clone).
