# Vercel AI SDK

## 1. Install the CLI

**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
    ```

Use `swy` as a shorter alias for `swytchcode`.

## 2. Install the packages

**JavaScript**

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

**Python**

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

## 3. Initialize Swytchcode and fetch a toolkit

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

`swy init` creates `.swytchcode/` and `tooling.json` for the project. `swy get github` downloads the GitHub integration bundle - the schemas that `tools.get` reads from in the next step.

## 4. Create the tool set

**JavaScript**

    ```ts
    import 'dotenv/config';
    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'] });
    ```

**Python**

    ```python
    import os
    from dotenv import load_dotenv
    from swytchcode_runtime import Swytchcode

    load_dotenv()

    swx = Swytchcode()
    tools = swx.tools.get(toolkits=["github"])

    print(f"Loaded {len(tools)} tools")
    ```

## 5. Run the prompt

**JavaScript**

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

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

**Python**

    ```python
    result = swx.tools.execute("github.pull_requests.list", {
        "params": {"state": "open"},
        "Authorization": f"Bearer {os.getenv('GITHUB_TOKEN')}",
    })

    print(result)
    ```

## 6. Run the file

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

```bash
node main.js
```

Swytchcode provides the tool execution layer while the SDK handles the model loop.
