# OpenAI 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 @openai/agents dotenv
    ```

**Python**

    ```bash
    pip install swytchcode-runtime openai-agents 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 agent tools

**JavaScript**

    ```ts
    import 'dotenv/config';
    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
    import os
    from dotenv import load_dotenv
    from swytchcode_runtime import Swytchcode
    from swytchcode_runtime.providers.openai_agents import OpenAIAgentsProvider

    load_dotenv()

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

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

## 5. Run the agent

**JavaScript**

    ```ts
    import { Agent, run } from '@openai/agents';

    const agent = new Agent({
      name: 'Assistant',
      instructions: 'You are a helpful assistant.',
      tools,
    });

    const result = await run(agent, 'List my open GitHub issues and summarize them.');

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

**Python**

    ```python
    from agents import Agent, Runner

    agent = Agent(
        name="Assistant",
        instructions="You are a helpful assistant.",
        tools=tools,
    )

    result = Runner.run_sync(agent, "List my open GitHub issues and summarize them.")

    print(result.final_output)
    ```

## 6. Run the file

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

**JavaScript**

    ```bash
    node main.js
    ```

**Python**

    ```bash
    python main.py
    ```

The runtime maps the agent's tool calls to the Swytchcode execution layer.

## Example projects

- [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.
