← Blog

Claude API Slack App: A Complete Build Guide

2026-11-15 · 5 min read · SubToAPI Team

Building a Slack app that talks to Claude means wiring up three pieces: a Slack app configuration (slash command or Events API), a backend endpoint that receives Slack's requests, and a call out to Claude that returns a response Slack can post back into the channel. None of this is exotic — it's a webhook handler plus an LLM call — but Slack's request/response timing rules and signature verification trip up a lot of first builds.

This guide walks through the full stack: setting up the Slack app, handling the 3-second ack window, calling Claude for the actual response, and posting it back asynchronously. We'll use Node.js for the backend, but the pattern applies to any language.

How Slack apps actually work

There are two common entry points for a Claude-powered bot:

Both require your server to respond within 3 seconds, or Slack shows a timeout error to the user. Since a Claude completion can take longer than that — especially for longer answers — the standard pattern is:

  1. Acknowledge the request immediately (empty 200, or a "thinking…" message).
  2. Call Claude in the background.
  3. Post the real answer to Slack using a response_url or the chat.postMessage API once Claude replies.

Step 1: Create the Slack app

In the Slack API dashboard, create a new app and configure:

Install the app to your workspace and copy the Bot Token and Signing Secret — you'll need both.

Step 2: Verify Slack's request signature

Every request from Slack includes a signature you must verify before trusting the payload. Skip this and anyone can POST fake commands to your endpoint.

const crypto = require("crypto");

function verifySlackRequest(req) {
  const timestamp = req.headers["x-slack-request-timestamp"];
  const sig = req.headers["x-slack-signature"];
  const base = `v0:${timestamp}:${req.rawBody}`;
  const hash = "v0=" + crypto
    .createHmac("sha256", process.env.SLACK_SIGNING_SECRET)
    .update(base)
    .digest("hex");
  return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(sig));
}

Reject the request with a 401 if this fails.

Step 3: Ack fast, then call Claude

Here's the slash command handler, acknowledging immediately and doing the real work afterward:

app.post("/slack/ask", async (req, res) => {
  if (!verifySlackRequest(req)) return res.sendStatus(401);

  const { text, response_url } = req.body;
  res.json({ response_type: "ephemeral", text: "Thinking…" });

  const answer = await askClaude(text);

  await fetch(response_url, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ response_type: "in_channel", text: answer }),
  });
});

The response_url Slack gives you is valid for up to 30 minutes, so even slow Claude responses are fine.

Step 4: Call Claude

This is where SubToAPI simplifies things. Instead of managing Anthropic SDK auth, rate limit handling, and billing separately, you call a single HTTPS endpoint with your sub_live_ key:

async function askClaude(prompt) {
  const res = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "claude-sonnet-4.5",
      max_tokens: 500,
      messages: [{ role: "user", content: prompt }],
    }),
  });
  const data = await res.json();
  return data.content[0].text;
}

This is a single application key you can rotate without touching your personal Claude account, which matters once the Slack app is shared across a team — see the docs/quickstart for setup and docs/messages for the request/response shape.

Step 5: Handle app mentions in channels

The Events API handler is similar but uses chat.postMessage instead of a response URL:

app.post("/slack/events", async (req, res) => {
  if (req.body.type === "url_verification") {
    return res.send(req.body.challenge);
  }
  if (!verifySlackRequest(req)) return res.sendStatus(401);

  res.sendStatus(200); // ack immediately

  const event = req.body.event;
  if (event.type === "app_mention") {
    const question = event.text.replace(/<@[^>]+>/, "").trim();
    const answer = await askClaude(question);

    await fetch("https://slack.com/api/chat.postMessage", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${process.env.SLACK_BOT_TOKEN}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ channel: event.channel, text: answer, thread_ts: event.ts }),
    });
  }
});

Threading replies with thread_ts keeps busy channels readable.

Streaming into Slack messages

Slack doesn't support token-by-token streaming in a message the way a chat UI does, but you can still improve perceived latency by posting a placeholder message, then editing it with chat.update as chunks arrive from a streamed Claude response. This is worth doing for longer answers (summaries, code explanations) where a 10+ second silent wait feels broken. See docs/streaming for how streamed responses are chunked.

Giving the bot tool access

If your Slack bot should look things up — ticket status, a knowledge base, internal docs — use tool calling instead of stuffing everything into the prompt. Define a tool schema, let Claude decide when to call it, execute the function in your handler, and feed the result back. The docs/tools page covers the request/response cycle for defining and returning tool results.

Deployment notes

Questions

Do I need Anthropic's own SDK to build a Slack bot with Claude? No. Any HTTP client works since it's a standard REST call. SubToAPI exposes the same /v1/messages shape over a single application key, which avoids managing separate Claude credentials per environment.

Why does my Slack command show "operation_timeout"? Slack cuts off slash command requests after 3 seconds. Acknowledge immediately with a placeholder response, then post the real Claude answer asynchronously using the response_url.

Can multiple people on my team share the same Claude-powered Slack bot without hitting rate limits individually? Yes — route all requests through one backend key rather than per-user credentials, and monitor combined usage from one place. A Team or Scale plan adds seats if multiple developers need to manage or debug the integration.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →