Skip to main content

Installation

pip install mag3nt

Setup

import mag3nt
from mag3nt.models.components import Security
import os

sdk = mag3nt.Mag3nt(
    server_url="https://mag3nt.com",
    security=Security(bearer_auth=os.environ["MAG3NT_API_KEY"]),
)

Usage

# Issue a card
card = sdk.cards.cards_create(
    purpose="Research Agent",
    limit_amount=50,
)

# Check balance
balance = sdk.funding.funding_get_balance()

# Pay for an API
payment = sdk.payments.payments_execute(
    card_id=card.card.id,
    card_token=card.card.token,
    url="https://api.weather.com/forecast"
)

# List transactions
txns = sdk.cards.cards_list_transactions(id=card.card.id)

Async support

Every method has an async variant with the _async suffix:
import asyncio

async def main():
    cards = await sdk.cards.cards_list_async()
    balance = await sdk.funding.funding_get_balance_async()

asyncio.run(main())

Error handling

from mag3nt.models.errors import BalanceError, Mag3ntError

try:
    sdk.cards.cards_create(purpose="Agent", limit_amount=100)
except BalanceError as e:
    print(f"Need {e.requested}, have {e.available}")
except Mag3ntError as e:
    print(f"Error: {e.status_code}")

Available methods

ModuleDescription
sdk.keysAPI key management
sdk.cardsCard issuance, controls, and transactions
sdk.fundingBalance and deposits
sdk.paymentsUniversal outbound payment engine
sdk.x402x402 protocol payments (deprecated)
sdk.ap2Agent-to-agent payments
sdk.mppMicropayment streaming
sdk.pay_linksShareable payment links
sdk.settlementSettlement status
sdk.statusPlatform health
See the API Reference for full method documentation.