Claude API Slack App: A Complete Build Guide
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:
- Slash commands (
/ask What's the deploy status?) — Slack sends a POST to your configured URL with the command text. - Events API (app mentions) — Slack sends a POST whenever your bot is
@mentionedin a channel it's in.
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:
- Acknowledge the request immediately (empty 200, or a "thinking…" message).
- Call Claude in the background.
- Post the real answer to Slack using a
response_urlor thechat.postMessageAPI once Claude replies.
Step 1: Create the Slack app
In the Slack API dashboard, create a new app and configure:
- Slash Command:
/ask, pointing tohttps://your-server.com/slack/ask - Event Subscriptions: subscribe to
app_mention, pointing tohttps://your-server.com/slack/events - OAuth scopes:
chat:write,commands,app_mentions:read
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
- Keep the signing secret and bot token out of your repo — environment variables only.
- Use a persistent queue (even a simple in-memory one for low volume) if multiple requests arrive before Claude responds.
- Rate limit per-user or per-channel if your workspace is large, so one chatty channel doesn't dominate your Claude usage.
- If you're exposing this to multiple teams or workspaces, issue a separate SubToAPI key per workspace from the dashboard so you can see usage and cost broken out per integration rather than one combined bill.
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.