> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mag3nt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> Install and configure the mag3nt TypeScript SDK.

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @mag3nt/sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @mag3nt/sdk
  ```

  ```bash yarn theme={null}
  yarn add @mag3nt/sdk
  ```
</CodeGroup>

## Setup

```typescript theme={null}
import { Mag3nt } from "@mag3nt/sdk";

const mag3nt = new Mag3nt({
  serverURL: "https://mag3nt.com",
  security: {
    bearerAuth: process.env.MAG3NT_API_KEY,
  },
});
```

## Usage

```typescript theme={null}
// Issue a card
const card = await mag3nt.cards.cardsCreate({
  purpose: "Research Agent",
  limitAmount: 50,
});

// Pay for an API
const payment = await mag3nt.payments.paymentsExecute({
  cardId: card.card.id,
  cardToken: card.card.token,
  url: "https://api.weather.com/forecast",
});

// Check balance
const balance = await mag3nt.funding.fundingGetBalance();
```

## Error handling

```typescript theme={null}
import * as errors from "@mag3nt/sdk/models/errors";

try {
  await mag3nt.cards.cardsCreate({ purpose: "Agent", limitAmount: 100 });
} catch (error) {
  if (error instanceof errors.BalanceError) {
    console.log(`Need ${error.data$.requested}, have ${error.data$.available}`);
  }
}
```

## Available methods

| Module              | Description                               |
| ------------------- | ----------------------------------------- |
| `mag3nt.keys`       | API key management                        |
| `mag3nt.cards`      | Card issuance, controls, and transactions |
| `mag3nt.funding`    | Balance and deposits                      |
| `mag3nt.payments`   | Universal outbound payment engine         |
| `mag3nt.x402`       | x402 protocol payments (deprecated)       |
| `mag3nt.ap2`        | Agent-to-agent payments                   |
| `mag3nt.mpp`        | Micropayment streaming                    |
| `mag3nt.payLinks`   | Shareable payment links                   |
| `mag3nt.settlement` | Settlement status                         |
| `mag3nt.status`     | Platform health                           |

See the [API Reference](/api-reference/cards/list-all-cards-for-the-authenticated-wallet) for full method documentation.
