OpenAI Agents + Skalor
Add fiduciary-controlled payments to OpenAI function-calling agents and the new OpenAI Agents SDK. Works with GPT-4o, GPT-4o-mini, and any function-calling model.
Two integration paths
OpenAI Function Calling
Direct integration with the Chat Completions API. Define Skalor as a tool function. Works in Python and TypeScript.
OpenAI Agents SDK
Use the new agents package with @function_tool decorators. Python only (for now).
Install
pip install skalor-sdk openaiexport SKALOR_API_KEY="zc_your_key_here"
export OPENAI_API_KEY="sk-..."
Integration
Define Skalor as a function tool in the Chat Completions API. The model decides when to call it based on the function description.
import json
import openai
from skalor import Client
# 1. Initialize Skalor client
zc = Client(api_key="zc_your_key_here")
# 2. Define the Skalor function for OpenAI
skalor_function = {
"type": "function",
"function": {
"name": "authorize_payment",
"description": (
"Authorize a payment through the Skalor fiduciary firewall. "
"Use this when you need to pay for a vendor API that returns "
"HTTP 402 Payment Required. All payments are gated by 5 "
"fiduciary controls (kill switch, vendor allowlist, per-tx "
"limit, daily budget, human-in-the-loop)."
),
"parameters": {
"type": "object",
"properties": {
"amount_usd": {
"type": "number",
"description": "Dollar amount to authorize",
},
"merchant": {
"type": "string",
"description": "Vendor domain or URL (e.g. api.openai.com)",
},
"intent": {
"type": "string",
"description": "Why this payment is needed (min 15 chars, for audit trail)",
},
},
"required": ["amount_usd", "merchant", "intent"],
},
},
}
# 3. Handle tool calls from the model
def handle_tool_call(tool_call):
"""Execute the Skalor payment authorization."""
args = json.loads(tool_call.function.arguments)
result = zc.authorize_spend(
amount=args["amount_usd"],
merchant=args["merchant"],
intent=args["intent"],
)
if result.approved:
return json.dumps({
"status": "approved",
"amount_usd": result.amount_usd,
"transaction_id": result.transaction_id,
"message": f"Payment of ${result.amount_usd} to {args['merchant']} approved.",
})
else:
return json.dumps({
"status": "denied",
"reason": result.denial_reason,
"message": result.message,
})
# 4. Run the agent loop
client = openai.OpenAI()
messages = [
{
"role": "system",
"content": (
"You are a research agent with a spending budget managed by "
"Skalor. When you need to access a paid API, use the "
"authorize_payment tool first. If denied, explain why to the user."
),
},
{
"role": "user",
"content": "Get me the latest market analysis from the premium data API",
},
]
# Initial call
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=[skalor_function],
)
# Tool call loop
while response.choices[0].message.tool_calls:
message = response.choices[0].message
messages.append(message)
for tool_call in message.tool_calls:
result = handle_tool_call(tool_call)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": result,
})
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=[skalor_function],
)
print(response.choices[0].message.content)Function Parameters
The function schema tells the model when and how to authorize payments:
| Parameter | Type | Required | Description |
|---|---|---|---|
amount_usd | number | Yes | Dollar amount to authorize |
merchant | string | Yes | Vendor domain or full URL |
intent | string | Yes | Audit trail reason (min 15 chars) |
Dual-Protocol Settlement
For advanced use cases, use authorize_intent() directly to choose between MPP (Tempo/PathUSD) and x402 (Base L2/USDC) settlement:
from skalor import Client
zc = Client(api_key="zc_your_key_here")
# MPP settlement (Tempo/PathUSD) — default
result = zc.authorize_intent(
agent_id="your-agent-uuid",
amount=0.05,
merchant_url="https://api.openai.com",
protocol="mpp",
reasoning="GPT-4o inference for Q2 lead scoring pipeline",
)
# x402 settlement (Base L2/USDC) — for x402-compatible vendors
result = zc.authorize_intent(
agent_id="your-agent-uuid",
amount=0.05,
merchant_url="https://indie-api.dev",
protocol="x402",
reasoning="Premium dataset access for competitive analysis",
)
# Use clearance headers to retry the vendor request
print(result["clearance_headers"])5 Fiduciary Gates
Every authorize_payment call goes through 5 gates before money moves:
- Kill Switch — Is the agent active?
- Vendor Allowlist — Is this vendor authorized?
- Per-Tx Limit — Within single-payment policy?
- Daily Budget — Under the daily cap?
- Human-in-the-Loop — Needs CFO sign-off?