Wallgent
Integrations

Give Your OpenAI Assistant a Wallet

Add financial capabilities to OpenAI Assistants using Wallgent function calling.

Prerequisites

  • A Wallgent account and API key (get one here)
  • An OpenAI API key

1. Install

npm install @wallgent/sdk openai

2. Function Definitions

The Wallgent SDK exports OpenAI-compatible function definitions that you can pass directly to the Assistants API:

import { wallgentFunctions } from '@wallgent/sdk';

This exports 37 function definitions covering wallets, payments, policies, cards, invoices, and more. Here are the core five:

[
  {
    "name": "wallgent_create_wallet",
    "description": "Create a new Wallgent wallet for an AI agent.",
    "parameters": {
      "type": "object",
      "properties": {
        "name": { "type": "string", "description": "Wallet name" },
        "agentName": { "type": "string", "description": "Agent identifier" }
      },
      "required": ["name"]
    }
  },
  {
    "name": "wallgent_check_balance",
    "description": "Check the balance of a Wallgent wallet.",
    "parameters": {
      "type": "object",
      "properties": {
        "walletId": { "type": "string", "description": "Wallet ID" }
      },
      "required": ["walletId"]
    }
  },
  {
    "name": "wallgent_fund_wallet",
    "description": "Fund a Wallgent wallet with a specified amount.",
    "parameters": {
      "type": "object",
      "properties": {
        "walletId": { "type": "string", "description": "Wallet ID" },
        "amount": { "type": "string", "description": "Amount to fund" }
      },
      "required": ["walletId", "amount"]
    }
  },
  {
    "name": "wallgent_send_payment",
    "description": "Send a payment between Wallgent wallets.",
    "parameters": {
      "type": "object",
      "properties": {
        "fromWalletId": { "type": "string", "description": "Source wallet ID" },
        "toWalletId": { "type": "string", "description": "Destination wallet ID" },
        "amount": { "type": "string", "description": "Payment amount" },
        "description": { "type": "string", "description": "Payment description" }
      },
      "required": ["fromWalletId", "toWalletId", "amount"]
    }
  },
  {
    "name": "wallgent_get_transactions",
    "description": "Get recent transactions for a Wallgent wallet.",
    "parameters": {
      "type": "object",
      "properties": {
        "walletId": { "type": "string", "description": "Wallet ID" },
        "limit": { "type": "number", "description": "Number of transactions to return" }
      },
      "required": ["walletId"]
    }
  }
]

3. Create an Assistant

import OpenAI from 'openai';
import { wallgentFunctions } from '@wallgent/sdk';

const openai = new OpenAI();

const assistant = await openai.beta.assistants.create({
  name: 'Financial Agent',
  instructions:
    'You are a financial agent. Use Wallgent tools to manage wallets and payments.',
  model: 'gpt-4o',
  tools: wallgentFunctions.map((f) => ({ type: 'function' as const, function: f })),
});

4. Handle Tool Calls

When the assistant calls a Wallgent function, execute it using the SDK and return the result:

import { Wallgent } from '@wallgent/sdk';

const wg = new Wallgent('wg_test_your_key_here');

async function executeWallgentFunction(
  name: string,
  args: Record<string, unknown>,
): Promise<string> {
  switch (name) {
    case 'wallgent_create_wallet':
      return JSON.stringify(
        await wg.wallets.create({
          name: args.name as string,
          agentName: args.agentName as string,
        }),
      );
    case 'wallgent_check_balance':
      return JSON.stringify(
        await wg.wallets.getBalance(args.walletId as string),
      );
    case 'wallgent_fund_wallet':
      return JSON.stringify(
        await wg.wallets.fund(args.walletId as string, {
          amount: args.amount as string,
        }),
      );
    case 'wallgent_send_payment':
      return JSON.stringify(
        await wg.payments.send({
          fromWalletId: args.fromWalletId as string,
          toWalletId: args.toWalletId as string,
          amount: args.amount as string,
          description: args.description as string,
        }),
      );
    case 'wallgent_get_transactions':
      return JSON.stringify(
        await wg.wallets.getTransactions(args.walletId as string),
      );
    default:
      return JSON.stringify({ error: `Unknown function: ${name}` });
  }
}

5. Complete Working Example

This script creates an assistant, sends a message, and processes tool calls in a loop:

import OpenAI from 'openai';
import { Wallgent } from '@wallgent/sdk';
import { wallgentFunctions } from '@wallgent/sdk';

const openai = new OpenAI();
const wg = new Wallgent('wg_test_your_key_here');

// Create assistant with Wallgent tools
const assistant = await openai.beta.assistants.create({
  name: 'Financial Agent',
  instructions:
    'You are a financial agent. Use Wallgent tools to manage wallets and payments.',
  model: 'gpt-4o',
  tools: wallgentFunctions.map((f) => ({ type: 'function' as const, function: f })),
});

// Start a thread
const thread = await openai.beta.threads.create();
await openai.beta.threads.messages.create(thread.id, {
  role: 'user',
  content: 'Create a wallet called "Demo Agent", fund it with $50, then check the balance.',
});

// Run the assistant
let run = await openai.beta.threads.runs.create(thread.id, {
  assistant_id: assistant.id,
});

// Process tool calls until complete
while (run.status === 'requires_action') {
  const toolCalls = run.required_action!.submit_tool_outputs.tool_calls;
  const toolOutputs = [];

  for (const call of toolCalls) {
    const args = JSON.parse(call.function.arguments);
    const result = await executeWallgentFunction(call.function.name, args);
    toolOutputs.push({ tool_call_id: call.id, output: result });
  }

  run = await openai.beta.threads.runs.submitToolOutputsAndPoll(
    thread.id,
    run.id,
    { tool_outputs: toolOutputs },
  );
}

// Print the final response
const messages = await openai.beta.threads.messages.list(thread.id);
const response = messages.data[0].content[0];
if (response.type === 'text') {
  console.log(response.text.value);
}

GPT Builder (No-Code)

You can also connect Wallgent to a Custom GPT using Actions:

  1. In the GPT Builder, go to Configure > Actions
  2. Import the Wallgent OpenAPI spec from https://api.wallgent.com/v1/openapi.json
  3. Set the authentication type to API Key with header Authorization: Bearer wg_test_your_key_here
  4. Save and test — the GPT can now call Wallgent endpoints directly

Next Steps

  • See all 37 function definitions via import { wallgentFunctions } from '@wallgent/sdk'
  • Set up spending policies for your assistant
  • Add webhooks for event-driven workflows
  • Explore the full SDK Reference

On this page