Blog

Connect Swytchcode to the OpenAI Agents SDK: Setup Guide and Example

Connect Swytchcode to the OpenAI Agents SDK so your agent can safely call real APIs, with authentication, retries, and policy checks handled automatically.

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

DevRel Engineer

Use CasesAug 24, 2026

Why Connect Swytchcode to the OpenAI Agents SDK?

  • No custom integration code. Swytchcode fetches a tool's schema so you're not hand-writing tool definitions for every API you connect.
  • Managed execution. Every tool call runs through Swytchcode's execution pipeline: authentication, retries, idempotency, and policy checks, before it touches a real API.
  • The same setup across frameworks. The project you set up with the CLI, and the tools you enable in it, work the same way whether you're calling them from the OpenAI Agents SDK, the Anthropic SDK, LangGraph, or another supported framework.

Step 1: Install the CLI and SDKs

npm install -g swytchcode
npm install @swytchcode/runtime

Alongside whichever OpenAI Agents SDK package matches your language, openai-agents for Python or @openai/agents for JavaScript/TypeScript.

Step 2: Initialize Your Project and Enable a Tool

swy init
swy get <project.library>
swy add method <canonical_id>
swy auth connect <provider>

This sets up your project, fetches the integration you want, enables the specific method your agent needs, and connects the account it'll act on behalf of.

Step 3: Fetch Your Tools in Code

The shared pattern across every supported framework is the same: initialize the Swytchcode runtime with the matching provider, then fetch the tools you've enabled.

import { Swytchcode, TOOL_USE_INSTRUCTIONS } from "@swytchcode/runtime";

const swx = new Swytchcode(/* OpenAI Agents SDK provider */);
const tools = await swx.tools.get({ toolkits: ["<your-integration>"] });

swx.tools.get() returns the schemas for whatever you've enabled with swy add. TOOL_USE_INSTRUCTIONS is a ready-made prompt fragment describing how to use them.

One detail worth double-checking directly against the OpenAI Agents SDK quickstart: the exact provider import and how the fetched tools get attached to an Agent definition in the SDK's own format. That page will have the precise, current syntax; the pattern above is the shared shape every framework follows.

Step 4: Run the Tool-Use Loop

When the agent's run produces a tool call, hand it to Swytchcode to execute:

const result = await swx.handleToolCalls(response);

This runs the call through Swytchcode's managed pipeline, authentication, retries, idempotency, and policy checks included, and returns the result to feed back into the agent's next turn.

Frequently Asked Questions

Do I need to write my own tool schemas for the OpenAI Agents SDK? No. swx.tools.get() returns the schema for whatever you've enabled with swy add.

Does this work the same way as connecting the Anthropic SDK? Yes, the same underlying pattern applies: install the matching provider package, fetch tools with swx.tools.get(), and pass them into the framework's native tool-calling interface.

What actually happens when a tool call executes? It runs through Swytchcode's execution pipeline: authentication, input validation, retries, idempotency, and any policy rules you've set, before reaching the real API.

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