Blog

Connect Swytchcode to the Anthropic SDK: Setup Guide and Example

Connect Swytchcode to the Anthropic SDK so Claude can safely call real APIs in your application. Full setup steps and a working code example.

Connect Swytchcode to the Anthropic SDK: Setup Guide and Example
Chaitrali Kakde

DevRel Engineer

Use CasesAug 24, 2026

If you're building a custom application on the Anthropic SDK and want Claude to actually take action, not just talk, Swytchcode gives it a safe way to call real APIs. Instead of writing your own authentication, retry, and validation logic for every integration, Swytchcode's runtime SDK plugs directly into Claude's native tool-calling loop and handles all of that underneath.

This guide walks through connecting the two, end to end, with a working example.

Why Connect Swytchcode to the Anthropic SDK?

The Anthropic SDK gives you Claude's reasoning and native tool-calling loop. Swytchcode gives that loop something safe to call:

  • No custom integration code. Swytchcode fetches a tool's schema and exposes it in the exact shape the Anthropic SDK expects, so you don't hand-write tool definitions for every API you connect.
  • Managed execution. Every tool call Claude makes runs through Swytchcode's execution pipeline: authentication, retries, idempotency, and policy checks, before it touches a real API.
  • One integration, many providers. The same Swytchcode project and enabled tools work whether you're calling them from the Anthropic SDK, the OpenAI Agents SDK, LangGraph, or any other supported framework.

Prerequisites

  • Node.js installed
  • The Swytchcode CLI installed globally
  • An Anthropic API key

Step 1: Install the CLI and SDKs

npm install -g swytchcode
npm install @swytchcode/runtime @anthropic-ai/sdk

Step 2: Initialize Your Project and Enable a Tool

swy init
swy get github
swy add method github.user.starred.update
swy auth connect github

This sets up your project, fetches the GitHub integration, enables one specific method on it, and connects your GitHub account. Swap in whichever integration and method your application actually needs.

Step 3: Initialize the Provider in Code

import Anthropic from "@anthropic-ai/sdk";
import { Swytchcode, TOOL_USE_INSTRUCTIONS } from "@swytchcode/runtime";
import { AnthropicProvider } from "@swytchcode/runtime/providers/anthropic";

const anthropic = new Anthropic();
const swx = new Swytchcode(new AnthropicProvider());
const tools = await swx.tools.get({ toolkits: ["github"] });

const system = `You are a helpful assistant.\n\n${TOOL_USE_INSTRUCTIONS}`;

swx.tools.get() fetches the schemas for whatever you've enabled with swy add, already formatted for Claude's tool-calling interface. TOOL_USE_INSTRUCTIONS is a ready-made system prompt fragment that tells Claude how to use them correctly.

Step 4: Run the Tool-Use Loop

Send the user's message to Claude along with the tools array and the system prompt as usual. When Claude's response includes a tool call, hand it to Swytchcode:

const result = await swx.handleToolCalls(response);

This executes the call through Swytchcode's managed pipeline and returns the result, which you pass back to Claude to continue the conversation until it produces a final reply.

Step 5: Run It

node main.js

Frequently Asked Questions

  • Do I need to write my own tool schemas for the Anthropic SDK? No. swx.tools.get() fetches the schema for whatever tools you've enabled with swy add and returns them already formatted for Claude's tool-calling interface.
  • What does swx.handleToolCalls() actually do? It takes Claude's tool-call response, executes the requested tool through Swytchcode's execution pipeline, meaning authentication, retries, and policy checks all happen automatically, and returns the result to pass back to the model.
  • Can I use more than one integration at once? Yes. Pass multiple toolkit names to swx.tools.get({ toolkits: [...] }), as long as you've fetched and enabled tools from each one first with swy get and swy add.
  • Does this work with other frameworks too? Yes. The same pattern, install the matching provider package, fetch tools with swx.tools.get(), and pass them into the framework's native tool-calling interface, applies to the OpenAI Agents SDK, Vercel AI SDK, LangGraph, and CrewAI as well.

Where to Go Next

Ready to build?

Install the CLI and connect your first API in minutes. Free tier included, no credit card required.

More from the blog