Skip to main content
The Cashfree Payments Agent Toolkit enables popular agent frameworks including LangChain, Vercel’s AI SDK, and OpenAI’s Agents SDK to integrate with Cashfree APIs through function calling. Build AI-powered payment agents that can create orders, process refunds, and manage customers programmatically.

Pre-requisites

Ensure you meet the following requirements to get started with the Cashfree Agent Toolkit:

Installation

Install the toolkit using your preferred package manager:
npm install @cashfreepayments/agent-toolkit

Framework support

The toolkit supports multiple frameworks, exposed through sub-paths:
FrameworkImport PathDescription
OpenAI@cashfreepayments/agent-toolkit/openaiFor Chat Completions API and Agents SDK
LangChain@cashfreepayments/agent-toolkit/langchainFor LangChain agents
Vercel AI SDK@cashfreepayments/agent-toolkit/ai-sdkFor Vercel’s AI SDK

Usage

Each toolkit is initialised with your Cashfree credentials and environment configuration.
import {
  CashfreeAgentToolkit,
  CFEnvironment,
} from '@cashfreepayments/agent-toolkit/openai';

const environment = CFEnvironment.SANDBOX; // or PRODUCTION
const clientId = process.env.CASHFREE_CLIENT_ID;
const clientSecret = process.env.CASHFREE_CLIENT_SECRET;

const cashfree = new CashfreeAgentToolkit(environment, clientId, clientSecret);

Available tools

The toolkit provides the following tools for payment operations:
ToolDescription
createOrderCreate a new order
getOrderRetrieve details of an existing order
terminateOrderTerminate or cancel an order
createRefundInitiate a refund for an order
getAllRefundsList all refunds for an order
getRefundRetrieve details of a specific refund
orderPayUsingUpiPay for an order using UPI
orderPayUsingNetbankingPay for an order using Netbanking
orderPayUsingAppPay for an order using a payment app
orderPayUsingPlainCardPay for an order using a plain card
orderPayUsingSavedCardPay for an order using a saved card
createCustomerCreate a new customer in Cashfree
fetchCustomerInstrumentsFetch saved payment instruments for a customer

Framework-specific examples

The following examples demonstrate how to use the toolkit with each supported framework.
The OpenAI integration works with both Chat Completions API and the Agents SDK.

Initialise the toolkit

Set up the Cashfree Agent Toolkit with your credentials and environment configuration.
import {
  CashfreeAgentToolkit,
  CFEnvironment,
} from "@cashfreepayments/agent-toolkit/openai";

const cashfreeToolkit = new CashfreeAgentToolkit(
  CFEnvironment.SANDBOX,
  process.env.CASHFREE_CLIENT_ID,
  process.env.CASHFREE_CLIENT_SECRET,
);

With Chat Completions API

Use the toolkit with OpenAI’s Chat Completions API by passing the tools as JSON schema.
const completion = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [...],
  tools: cashfreeToolkit.getTools(), // Returns JSON schema
});

With OpenAI Agents SDK

Integrate the toolkit with OpenAI’s Agents SDK for building autonomous payment agents.
import { Agent } from "@openai/agents";

const agent = new Agent({
  model: "gpt-4o",
  tools: cashfreeToolkit.getAgentTools(),
});
For detailed OpenAI documentation, see the OpenAI integration guide.

Example payment agent

The following example demonstrates a complete payment agent using the OpenAI Agents SDK:
import { Agent, run } from '@openai/agents';
import {
  CashfreeAgentToolkit,
  CFEnvironment,
} from '@cashfreepayments/agent-toolkit/openai';

// Initialize the toolkit
const cashfree = new CashfreeAgentToolkit(
  CFEnvironment.SANDBOX,
  process.env.CASHFREE_CLIENT_ID,
  process.env.CASHFREE_CLIENT_SECRET
);

// Create an agent with all payment tools
const agent = new Agent({
  name: 'Payment Agent',
  instructions: 'You are a helpful payment assistant.',
  model: 'gpt-4o',
  tools: cashfree.getAgentTools(),
});

// Run the agent
const result = await run(
  agent,
  'Look up customer cust_123 and create an order for Rs. 500'
);

Resources

Explore additional resources to help you get started with the Cashfree Agent Toolkit.