# Native SDK

Use the framework selector to see the matching packages and runtime provider code.

Use `swy` as a shorter alias for `swytchcode` in any of the commands below.

## Choose your framework

**Anthropic SDK**

    1. **Install the CLI and SDK**

**npm**

           ```bash
            npm install -g swytchcode
           ```

**Windows**

           ```powershell
           irm https://cli.swytchcode.com/install.ps1 | iex
           ```

**macOS / Linux**

           ```bash
          curl -fsSL https://cli.swytchcode.com/install.sh | sh
           ```

**JavaScript / TypeScript**

           ```bash
           npm install @swytchcode/runtime @anthropic-ai/sdk
           ```

**Python**

           ```bash
           pip install swytchcode-runtime anthropic python-dotenv
           ```

    2. **Initialize Swytchcode, fetch a toolkit, and enable a tool**

       `swy init` creates the project's `tooling.json`, `swy get` downloads the GitHub integration bundle, and `swy add method` resolves one of its methods into `tooling.json.tools` so it can actually be called. The example below stars a repo, so it also connects a GitHub account.

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

    3. **Initialize the provider**

**JavaScript / TypeScript**

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

           async function runAgent() {
             const anthropic = new Anthropic();

             // 1. Initialize Swytchcode with the Anthropic provider
             const swx = new Swytchcode(new AnthropicProvider());

             // 2. Fetch the tools you want your agent to use (e.g., GitHub tools)
             const tools = await swx.tools.get({ toolkits: ["github"] });

             // 3. Build the system prompt: your own instructions plus TOOL_USE_INSTRUCTIONS,
             // which tells Claude to call the tool directly for action requests instead of
             // just describing what it would do
             const system = `You are a helpful assistant.\n\n${TOOL_USE_INSTRUCTIONS}`;

             const messages: Anthropic.MessageParam[] = [
               { role: "user", content: "Star the swytchcodehq/swytchcode-examples repo on GitHub for me." },
             ];

             // 4. Loop until Claude stops requesting tool calls: run any tool calls
             // Claude made and send the results back so it can keep working toward
             // a final natural-language reply instead of stopping after one round
             const MAX_TURNS = 10;
             let response: Anthropic.Message;
             for (let turn = 0; ; turn++) {
               if (turn >= MAX_TURNS) {
                 throw new Error(`Exceeded ${MAX_TURNS} tool-use turns without a final reply`);
               }

               response = await anthropic.messages.create({
                 model: "claude-sonnet-5",
                 max_tokens: 1024,
                 system,
                 tools: tools,
                 messages,
               });
               messages.push({ role: "assistant", content: response.content });

               if (response.stop_reason === "max_tokens") {
                 throw new Error("Response truncated at max_tokens - increase the limit and retry");
               }
               if (response.stop_reason !== "tool_use") break;

               const toolResults = await swx.handleToolCalls(response);
               messages.push({ role: "user", content: toolResults as Anthropic.ToolResultBlockParam[] });
             }

             for (const block of response.content) {
               if (block.type === "text") console.log(block.text);
             }
           }

           runAgent();
           ```

**Python**

           ```python
           import os
           from dotenv import load_dotenv
           import anthropic
           from swytchcode_runtime import Swytchcode, TOOL_USE_INSTRUCTIONS
           from swytchcode_runtime.providers.anthropic import AnthropicProvider

           load_dotenv()  # Loads .env automatically

           def run_agent():
               client = anthropic.Anthropic()

               # 1. Initialize Swytchcode with the Anthropic provider
               swx = Swytchcode(provider=AnthropicProvider())

               # 2. Fetch the tools you want your agent to use (e.g., GitHub tools)
               tools = swx.tools.get(toolkits=["github"])

               # 3. Build the system prompt: your own instructions plus TOOL_USE_INSTRUCTIONS,
               # which tells Claude to call the tool directly for action requests instead of
               # just describing what it would do
               system = f"You are a helpful assistant.\n\n{TOOL_USE_INSTRUCTIONS}"

               messages = [{"role": "user", "content": "Star the swytchcodehq/swytchcode-examples repo on GitHub for me."}]

               # 4. Loop until Claude stops requesting tool calls: run any tool calls
               # Claude made and send the results back so it can keep working toward
               # a final natural-language reply instead of stopping after one round
               while True:
                   response = client.messages.create(
                       model="claude-sonnet-5",
                       max_tokens=1024,
                       system=system,
                       tools=tools,
                       messages=messages,
                   )
                   messages.append({"role": "assistant", "content": response.content})

                   if response.stop_reason == "max_tokens":
                       raise RuntimeError("Response truncated at max_tokens - increase the limit and retry")
                   if response.stop_reason != "tool_use":
                       break

                   tool_results = swx.handle_tool_calls(response)
                   messages.append({"role": "user", "content": tool_results})

               for block in response.content:
                   if block.type == "text":
                       print(block.text)

           if __name__ == "__main__":
               run_agent()
           ```

    4. **Handle the tool loop**

       Pass the tool result back to Claude. For a manual loop in Python, use `swx.handle_tool_calls(response)` to execute tool calls and create `tool_result` blocks.

    5. **Run the file**

       Save the example as `main.js` or `main.py`, then run:

**JavaScript / TypeScript**

           ```bash
           node main.js
           ```

**Python**

           ```bash
           python main.py
           ```

**OpenAI Agents**

    1. **Install the CLI and SDK**

**npm**

           ```bash
           npm install -g swytchcode
           ```

**Windows**

           ```powershell
           irm https://cli.swytchcode.com/install.ps1 | iex
           ```

**macOS / Linux**

           ```bash
           curl -fsSL https://cli.swytchcode.com/install.sh | sh
           ```

**JavaScript / TypeScript**

           ```bash
           npm install @swytchcode/runtime @openai/agents
           ```

**Python**

           ```bash
           pip install swytchcode-runtime openai-agents python-dotenv
           ```

    2. **Initialize Swytchcode and fetch a toolkit**

       `swy init` creates the project's `tooling.json`; `swy get github` downloads the GitHub integration bundle that `tools.get` reads from below.

       ```bash
       swy init
       swy get github
       ```

    3. **Initialize the provider**

**JavaScript / TypeScript**

           ```ts
           import { Swytchcode } from '@swytchcode/runtime';
           import { OpenAIAgentsProvider } from '@swytchcode/runtime/providers/openai-agents';

           const swx = new Swytchcode(new OpenAIAgentsProvider());
           const tools = await swx.tools.get({ toolkits: ['github'] });
           ```

**Python**

           ```python
           from swytchcode_runtime import Swytchcode
           from swytchcode_runtime.providers.openai_agents import OpenAIAgentsProvider

           swx = Swytchcode(provider=OpenAIAgentsProvider())
           tools = swx.tools.get(toolkits=['github'])
           ```

    4. **Pass `tools` to your agent**

       The returned tools use the native OpenAI Agents format. Pass them into your agent and let Swytchcode handle execution, authentication, and policy checks.

    5. **Run the file**

       Save the example as `main.js` or `main.py`, then run the matching command:

**JavaScript / TypeScript**

           ```bash
           node main.js
           ```

**Python**

           ```bash
           python main.py
           ```

**Vercel AI SDK**

    1. **Install the CLI and SDK**

**npm**

           ```bash
           npm install -g swytchcode
           ```

**Windows**

           ```powershell
           irm https://cli.swytchcode.com/install.ps1 | iex
           ```

**macOS / Linux**

           ```bash
           curl -fsSL https://cli.swytchcode.com/install.sh | sh
           ```

       ```bash
       npm install @swytchcode/runtime ai @ai-sdk/openai
       ```

    2. **Initialize Swytchcode and fetch a toolkit**

       `swy init` creates the project's `tooling.json`; `swy get github` downloads the GitHub integration bundle that `tools.get` reads from below.

       ```bash
       swy init
       swy get github
       ```

    3. **Initialize the provider and run the model**

       ```ts
       import { openai } from '@ai-sdk/openai';
       import { generateText } from 'ai';
       import { Swytchcode } from '@swytchcode/runtime';
       import { VercelProvider } from '@swytchcode/runtime/providers/vercel';

       const swx = new Swytchcode(new VercelProvider());
       const tools = await swx.tools.get({ toolkits: ['github'] });

       const result = await generateText({
         model: openai('gpt-4.1'),
         tools,
         prompt: 'Summarize my open pull requests from GitHub.',
       });

       console.log(result.text);
       ```

      4. **Run the file**

         Save the example as `main.js`, then run:

         ```bash
         node main.js
         ```

**Other providers**

    Choose a framework-specific guide to see its provider and tool setup:

    - [LangGraph](/quickstarts/langgraph/)
    - [CrewAI](/quickstarts/crewai/)
    - [OpenAI SDK](/quickstarts/openai-sdk/)
    - [Anthropic SDK](/quickstarts/anthropic-sdk/)
    - [Runtime SDK reference](/runtime-sdk/)

## Where to go next

- [Gmail Assistant](https://github.com/swytchcodehq/swytchcode-examples/tree/main/gmail-assistant-anthropic-typescript) - Searches, reads, drafts, and sends Gmail messages through an Anthropic tool-use loop powered by Swytchcode.
- [Star Repo Agent](https://github.com/swytchcodehq/swytchcode-examples/tree/main/star-repo-openai-agents-python) - Minimal OpenAI Agents SDK example that stars a GitHub repo through Swytchcode-brokered OAuth.
- [OpenAI SDK](https://docs.swytchcode.com/quickstarts/openai-sdk/) - Integrate Swytchcode tools with the OpenAI Agents SDK to build reliable agents.
- [Anthropic SDK](https://docs.swytchcode.com/quickstarts/anthropic-sdk/) - Connect Claude-based agents to trusted tools using the Anthropic integration.
- [LangGraph](https://docs.swytchcode.com/quickstarts/langgraph/) - Build stateful, multi-step workflows and execute tools through Swytchcode.
- [CrewAI](https://docs.swytchcode.com/quickstarts/crewai/) - Enable CrewAI agents to discover and execute trusted tools.
- [Runtime SDKs](https://docs.swytchcode.com/runtime-sdk/) - Learn how the JavaScript and Python Runtime SDKs power tool execution across frameworks.
