Wrap AgentRefills as a function tool and your OpenAI Agents SDK agent can buy gift cards directly, with budgets and human approval enforced server-side.
from agents import Agent, function_tool
import requests
BASE = "https://api.agentrefills.com"
H = {"Authorization": "Bearer sk_live_..."}
@function_tool
def buy_giftcard(brand_id: str, amount_minor: int) -> str:
"""Buy a gift card. amount_minor is the value in cents."""
r = requests.post(f"{BASE}/v1/purchases", headers=H, json={
"brand_id": brand_id, "amount_minor": amount_minor, "currency": "USD",
})
r.raise_for_status()
return r.json()["task_id"]
agent = Agent(name="Rewards bot", tools=[buy_giftcard])
Daily and monthly limits plus a brand allowlist, enforced on every purchase.
Purchases above your threshold are approved by a human in Slack before money moves.
If the policy engine is unreachable or undecided, the purchase is denied, never allowed.
Codes are encrypted at rest, released once, access-logged, and never written to logs or traces.
An idempotency key plus a unique payment-per-task constraint make a double charge structurally impossible.
Every order is reconstructable from an OpenTelemetry trace plus a double-entry ledger, with webhooks on completion.
Send a gift card for a survey, referral or milestone.
Resolve a ticket with a gift card instead of a slow reversal.
Send a scheduled thank-you or birthday gift, within a budget.
Buy stored-value for a team, capped and reconciled.
Wrap the AgentRefills REST endpoint in a @function_tool that POSTs to /v1/purchases, then pass it to your Agent(tools=[...]). The agent supplies a brand and an amount in cents; AgentRefills enforces the spend cap and approval threshold before any money moves.
Every agent gets its own API key scoped to per-agent daily and monthly spend caps and a brand allowlist. The policy engine enforces the caps on every purchase and fails closed, so the agent can never exceed its budget even if the policy service is unreachable.
Set an approval threshold. Any purchase above it is parked as APPROVAL_REQUIRED and a human is pinged in Slack to approve or reject before money moves. The task resumes automatically once approved.
Start in the sandbox with zero real spend, then flip to production.
Get API keys