Make your first request

Create an API key, send a message to your agent from the command line, then do the same from a Node service.

This walkthrough takes you from nothing to a real reply from your agent. You'll create an API key, send one message with curl, and then hold a short conversation from code. The example is a hotel's booking app asking its concierge agent about early check-in.

You need a Manager in your workspace to create the key, an agent to talk to, curl, and Node 18 or later for the code sample.

1. Create an API key

In the dashboard, go to SettingsChannelsAPI and choose Add API. Name the key after the service that will use it, such as Booking app backend, and choose Create key. Copy the key now: it starts with sk_live_ and is shown only once. See API keys for the full steps.

2. Find your agent's ID

Open the agent in the dashboard. Its ID is the long value in the address bar, such as 66f1c2a9e4b0f1a2b3c4d5e6. The key works with any agent in the workspace, so each request names the agent it's for.

3. Send a message with curl

curl -X POST https://api.trycareflow.com/v1/conversations/messages \
  -H "Authorization: Bearer sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "assistantId": "66f1c2a9e4b0f1a2b3c4d5e6",
    "message": "Can I check in before 2pm on Friday?"
  }'

The reply comes back in the same response, once the agent has finished looking things up:

{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "reply": "Early check-in from 11am is possible when your room is ready. I've noted your request for Friday.",
    "externalId": "conv_3f9a1c7e5b2d8f0a6c4e1b93",
    "conversationId": "6710b3e2c4a1f09d8e7b6a52",
    "toolsCalled": [],
    "workflowCompleted": false
  }
}

reply is what you show the customer. It can contain Markdown, like bold text and lists. conversationId is the conversation you'll now find in your Inbox. externalId is the key for continuing this conversation, covered next.

4. Keep the conversation going

The agent remembers what was said when you send the same externalId with each message. You can let Careflow create one, as above, and send it back next time. It's usually simpler to use your own stable ID for the customer, such as their guest or account number:

async function askConcierge(guestId, text) {
  const res = await fetch("https://api.trycareflow.com/v1/conversations/messages", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.CAREFLOW_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      assistantId: process.env.CAREFLOW_AGENT_ID,
      externalId: `guest-${guestId}`,
      message: text,
    }),
    signal: AbortSignal.timeout(120_000),
  });
  const body = await res.json();
  if (body.code !== "SUCCESS") {
    throw new Error(`${res.status} ${body.message}: ${body.error ?? ""}`);
  }
  return body.data.reply;
}
 
console.log(await askConcierge("48213", "Can I check in before 2pm on Friday?"));
console.log(await askConcierge("48213", "Great. Is breakfast included?"));

The second question follows on from the first, because both carry guest-48213. Messages with the same externalId stay in one conversation while they keep coming. After 30 minutes with no messages, the next one opens a new conversation in the Inbox, with a new conversationId.

The two-minute timeout matters. A reply can take several seconds when the agent uses tools, and a client that gives up too early and retries can end up sending the same message twice.

5. Read a failure

If something is wrong, the response has code set to ERROR. A bad key looks like this:

{ "code": "ERROR", "message": "unauthorized", "error": "invalid or revoked API key" }

An agent ID from another workspace, or a typo in it, returns 404 with assistant not found for this API key. Errors lists every case.

Where to go next