Connect an API

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), 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 and Secrets.

  1. Store the credential as a secret

    Store the token with Create a secret. Reads return its identifier, not the value.

    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!,
    });

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

  2. 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)

    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 },
    });

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

  3. Test it and publish it

    Test the API with an order: this call executes your endpoint. Check the result, then publish it in the workspace catalog.

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

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

  4. Connect it to the agent

    Connect the tool using the API's id. The connection applies immediately; you do not need to publish the agent.

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

Check it worked

Call List the agent's tools: 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, it returns to draft. Agents stop using it until you bind the secret again, test it and publish it.

Next steps