LangChain

Expose the Subscriby REST API to LangChain agents via the OpenAPI toolkit.

LangChain (Python and TypeScript) ships an OpenAPI toolkit that converts any OpenAPI spec into a set of tools an LLM agent can call. Subscriby's OpenAPI 3.1 spec works out of the box.

Python

from langchain_community.agent_toolkits.openapi import planner
from langchain_community.utilities.requests import RequestsWrapper
from langchain_openai import ChatOpenAI
import yaml, requests

spec = requests.get("https://api.subscriby.net/openapi.json").json()

requests_wrapper = RequestsWrapper(
    headers={
        "Authorization": "Bearer sbt_live_...",
        "Idempotency-Key": lambda: str(uuid4()),
    }
)

agent = planner.create_openapi_agent(
    api_spec=spec,
    requests_wrapper=requests_wrapper,
    llm=ChatOpenAI(model="gpt-4o"),
    allow_dangerous_requests=True,
)

agent.invoke(
    "List my Subscriby projects."
)

TypeScript

import { createOpenAPIAgent } from "@langchain/community/agents/openapi";
import { ChatOpenAI } from "@langchain/openai";

const spec = await fetch("https://api.subscriby.net/openapi.json").then((r) =>
  r.json(),
);

const agent = await createOpenAPIAgent({
  spec,
  llm: new ChatOpenAI({ model: "gpt-4o" }),
  requestOptions: {
    headers: { Authorization: "Bearer sbt_live_..." },
  },
});

await agent.invoke({ input: "List my Subscriby projects." });

Respecting rate limits and idempotency

The OpenAPI toolkit doesn't auto-inject Idempotency-Key — wire a middleware that generates a UUID per request and retries on 429:

def before_request(method, url, headers, body):
    headers["Idempotency-Key"] = str(uuid4())
    return method, url, headers, body

Narrowing the toolkit

LangChain's planner loads every operation from the spec by default. For scoped agents, pre-filter the spec to only the endpoints you want exposed:

allowed = {"/v1/projects", "/v1/projects/{id}", "/v1/webhook-endpoints"}
spec["paths"] = {k: v for k, v in spec["paths"].items() if k in allowed}

Prefer MCP for Claude-family models

If the LLM driving the agent is a Claude model, connect it directly to the MCP server instead of LangChain. You skip the OpenAPI-toolkit layer entirely and get typed responses + better ability gating.

How is this guide?

On this page

Subscriby is a product designed by you — for you.

No boardroom full of executives deciding what we ships next. Our roadmap always shaped by you with your feedback.

Share feedback or a request