---
docId: doc_09f4b591a5b349d2b15bfe4bb41f2ba8
title: Connect an API
description: "Define, test and connect your own API as an agent tool."
---

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

# Connect an API

<span id="what-youll-build"></span>

Connect your orders API so the agent can look up an order's status. Store the credential as a secret, define the call, test it and assign the tool to the agent.

## Before you start

- An agent ([create one](/guides/create-an-agent)), with its id in `AGENT_ID`.
- An endpoint in your system that returns JSON.

If the endpoint needs no credential, skip step 1.

In the platform: [REST APIs](/help/integrations/functions/rest-apis) and [Secrets](/help/integrations/functions/secrets).

<Steps>
<Steps.Step>

**Store the credential as a secret**

Store the token with [Create a secret](/api-reference/secrets/create). Reads return its identifier, not the value.

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

```bash
curl https://api.platic.ai/v1/secrets \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme · Orders API",
    "kind": "bearer",
    "value": "<your API token>"
  }'
```

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

```ts
import { Platic } from "platic-sdk";

const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
const agentId = process.env.AGENT_ID!;

const secret = await platic.secrets.create({
  name: "Acme · Orders API",
  kind: "bearer",
  value: process.env.ACME_API_TOKEN!,
});
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Store the token of Acme's orders API as a secret.

</Ways.Say>

Tool: [`create_secret`](/mcp/tools#create_secret). To keep the token out of the chat, store it yourself in **Integrations → Functions → Secrets** and ask it to use that one.

</Ways.Way>
</Ways>

The response has the secret's `id`, never the value. Keep it in `SECRET_ID`.

</Steps.Step>
<Steps.Step>

**Define the API**

Define the URL, input data and when the agent should use it. Bind the secret to the `auth.token` field instead of including its value. ([Create an API tool](/api-reference/custom-apis/create))

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

```bash
curl https://api.platic.ai/v1/tools/apis \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "order_lookup",
    "description": "Looks up the status of an order by its number. Use it when the customer asks where their order is.",
    "request": {
      "method": "GET",
      "url": "https://api.acme.com/orders/{{orderId}}",
      "auth": { "type": "bearer" }
    },
    "variables": [
      { "name": "orderId", "type": "string", "description": "Order number, as it appears in the confirmation email.", "required": true }
    ],
    "secrets": { "auth.token": "'$SECRET_ID'" }
  }'
```

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

```ts
const api = await platic.tools.apis.create({
  name: "order_lookup",
  description: "Looks up the status of an order by its number. Use it when the customer asks where their order is.",
  request: {
    method: "GET",
    url: "https://api.acme.com/orders/{{orderId}}",
    auth: { type: "bearer" },
  },
  variables: [
    { name: "orderId", type: "string", description: "Order number, as it appears in the confirmation email.", required: true },
  ],
  secrets: { "auth.token": secret.id },
});
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Create a tool that looks up an order's status: a GET to https://api.acme.com/orders/ followed by the order number, with the orders API secret. Use it when a customer asks where their order is.

</Ways.Say>

Tool: [`create_api_tool`](/mcp/tools#create_api_tool).

</Ways.Way>
</Ways>

The API is created as a draft. Save its `id` in `API_ID` and read `nextStep` to see what remains.

</Steps.Step>
<Steps.Step>

**Test it and publish it**

[Test the API](/api-reference/custom-apis/test) with an order: this call executes your endpoint. Check the result, then [publish it](/api-reference/custom-apis/publish) in the workspace catalog.

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

```bash
curl https://api.platic.ai/v1/tools/apis/$API_ID/test \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "input": { "orderId": "AC-48210" } }'

curl -X POST https://api.platic.ai/v1/tools/apis/$API_ID/enable \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

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

```ts
await platic.tools.apis.test(api.id, { input: { orderId: "AC-48210" } });
await platic.tools.apis.enable(api.id);
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Test the orders tool with order number AC-48210 and, if it works, publish it.

</Ways.Say>

Tool: [`test_api_tool`](/mcp/tools#test_api_tool) and [`enable_api_tool`](/mcp/tools#enable_api_tool).

</Ways.Way>
</Ways>

Check `extracted`: it contains the data the agent will receive. It should include the information needed to answer.

</Steps.Step>
<Steps.Step>

**Connect it to the agent**

[Connect the tool](/api-reference/agents/tools/connect) using the API's id. The connection applies immediately; you do not need to publish the agent.

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

```bash
curl -X PUT https://api.platic.ai/v1/agents/$AGENT_ID/tools/$API_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

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

```ts
await platic.agents.tools.connect(agentId, api.id);
```

</Ways.Way>
<Ways.Way name="asistente">
<Ways.Say>

Give the orders tool to the Sales agent.

</Ways.Say>

Tool: [`connect_agent_tool`](/mcp/tools#connect_agent_tool).

</Ways.Way>
</Ways>

</Steps.Step>
</Steps>

## Check it worked

Call [List the agent's tools](/api-reference/agents/tools/list): `order_lookup` should appear. Ask the agent about an order and check that it requests the number and calls your API.

When you [edit the API](/api-reference/custom-apis/update), it returns to draft. Agents stop using it until you bind the secret again, test it and publish it.

## Next steps

- [Connect an MCP server](/guides/connect-an-mcp-server) if the tools you need already exist in one.
- [Write a custom function](/guides/custom-functions) when one HTTP call is not enough.
- [Test it before you publish](/guides/evals): a scenario can require the agent to call your API.
- [Custom APIs](/api-reference/custom-apis): credential slots, lifecycle and what happens when you edit.
