Create an API

SDK platic.tools.apis.create()

Define an HTTP tool by sending name and description. You can complete the request and variables later with Update an API. It is created as draft; to use it, bind credentials, test it and publish it.

Example

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

Request body

{
  "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.

FieldTypeDescriptionRequired
namestringLowercase letters, digits and _; starts with a letter or digit; up to 63 characters. The agent sees it as api_<name>✓
descriptionstring10 to 1,024 characters. Explains when the agent should use it✓
requestobjectThe HTTP request. See request—
variablesarrayWho fills each {{name}}. Up to 50. See variables—
contextobject{ "lastMessagesN": 10 }: how many messages lastMessages delivers, from 1 to 50—
mappingobjectbodyStrategy (merge, replace or none) and extraBody, an object with fixed pairs for the body—
responseobjectWhich part of the response the agent receives. See response—
periodicAuthobjectUses a token that is renewed by a periodic authentication configured in Platica: cronJobId and inject (in: header or query; key; optional valuePrefix and valueSuffix)—
encryptPayloadobjectSigns the body as a JWT. { "ttlSeconds": 60 }, from 5 to 3,600. The signing key is the encryptPayload.key slot—
secretsobjectMap of slot to secret ID, to bind in this same call—

request

{
  "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 }
}
FieldTypeDescription
methodstringGET, POST, PUT, PATCH or DELETE
urlstringDestination 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
paramsarrayQuery parameters as { key, value, description?, enabled? }. Up to 25
pathVariablesarrayPath variables, with the same shape. Up to 25
headersarrayHeaders, with the same shape. Up to 25. A header that carries a credential goes with an empty value and is bound as header:<name>
bodyobject{ "mode": "none" }, { "mode": "json", "raw": "…" }, { "mode": "text", "raw": "…" } or { "mode": "form-urlencoded", "pairs": [ … ] }. raw accepts up to 16,000 characters; pairs, up to 50
authobjectHow it authenticates, without the credential: { "type": "none" }, { "type": "bearer" }, { "type": "basic", "username": "…" } or { "type": "apikey", "key": "…", "in": "header" \| "query" }
settings.timeoutMsnumberFrom 1,000 to 60,000. Default, 30,000
settings.followRedirectsbooleanWhether it follows redirects

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

Variables

[
  {
    "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"
  }
]
FieldTypeDescription
namestringUsed as {{name}} inside request. Up to 64 characters
typestringstring, number, integer, boolean, array or object
descriptionstringUp to 1,024 characters. In ai mode it is what the agent reads, and publishing requires it
requiredbooleanWhether the agent must always send it
modestringai (default), constant, context or secret
constantValueanyOnly with mode: "constant"
contextFieldstringOnly 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, defaultvariousConstraints 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.

FieldTypeDescription
pathstringPath to the useful part, for example data.items. Leave it out if the fields are at the root
strictPathbooleanWith true, the call fails if path does not exist
includestring[]Only these fields. Up to 50
excludestring[]All but these. Up to 50
maxBytesnumberMaximum response size. Default, 32,000
binarystringauto, always or never. A PDF, an image or a spreadsheet is stored and the agent receives a descriptor with a signed URL
filenamestringName of the stored file, up to 120 characters

Response

201 Created. data has the complete API, with the fields of Get an API.

{
  "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

Statusdetails.codeWhen
400INVALID_REQUESTThe 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
400SECRET_REFERENCE_REQUIREDYou 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
400INVALID_CONFIGThe 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
403FORBIDDENThe person behind the token does not have access to Integrations
404CRON_NOT_FOUNDperiodicAuth.cronJobId does not exist
409NAME_CONFLICTAnother tool with that name already exists in the workspace

Notes