The OpenAI Agents SDK lets you build agents with custom tools, handoffs, and guardrails. You can create Laso Finance tools that give your agent the ability to order cards via x402.
from agents import Agent, Runner, function_toolimport requestsLASO_BASE_URL = "https://laso.finance"@function_tooldef order_card(amount: int) -> str: """Order a prepaid card loaded with the specified USD amount. Amount must be between 5 and 1000.""" url = f"{LASO_BASE_URL}/get-card?amount={amount}" response = requests.get(url) if response.status_code == 402: payment_requirements = response.json() x_payment = sign_x402_payment(payment_requirements) response = requests.get(url, headers={"X-PAYMENT": x_payment}) data = response.json() return f"Card ordered. Card ID: {data['card']['card_id']}. Use get_card_data to poll for details."@function_tooldef get_card_data(card_id: str, id_token: str) -> str: """Check the status of a card order. Returns card details when ready. Poll every few seconds until status is 'ready'.""" response = requests.get( f"{LASO_BASE_URL}/get-card-data?card_id={card_id}", headers={"Authorization": f"Bearer {id_token}"}, ) return str(response.json())
agent = Agent( name="Payment Agent", instructions="""You help users order prepaid cards and gift cards using the Laso Finance API. When ordering a card, always poll for the card details until the status is 'ready' before presenting the card number.""", tools=[order_card, get_card_data],)