# Create an invoice

> POST /v0/invoices. Creates an invoice priced in USD. The customer may pay in any routable token on any routable chain; the merchant receives one settlement asset at its own address (§0).


`POST /v0/invoices`

Creates an invoice priced in USD. The customer may pay in any routable token on any routable chain; the merchant receives one settlement asset at its own address (§0).

Settlement is in a USD stablecoin (USDC on base, USDC on arbitrum, USDC on ethereum, USDC on solana, USDC on polygon, USDT on tron, USDT on ethereum, USDT on arbitrum, USDT on bsc), 1:1 with `amount`, or in BTC. A BTC invoice's `amountExpected` is locked from live quotes when it is created (`priceLock`, §5.2); if no reliable price can be had the invoice is refused with `503 PRICE_UNAVAILABLE`.

Re-sending a `reference` in the same mode returns `200` with the invoice that already exists, so a retried create never charges twice. References are scoped by mode: the same `reference` under a test key and a live key makes two separate invoices.

## Authentication

A secret key (`ik_`) as a Bearer token. The prefix sets the mode: `_test_` or `_live_`. Publishable keys (`pk_`) cannot call it.

## Parameters

| Parameter | In | Required | Notes |
|---|---|---|---|
| `x-intents-affiliate` | header | no | Store plugins: the Affiliate ID from the plugin settings. Links a merchant that nobody referred yet and that has no live payment (affiliate rules); never overwrites and never changes the fee. |

## Body parameters

| Field | Type | Required | Notes |
|---|---|---|---|
| `amount` | string | yes | Price in the invoice currency, e.g. "49.00" |
| `currency` | `USD` | no |  |
| `settlement` | object | no | Choose between the merchant's registered settlement targets. API keys cannot introduce a new address (§8.3). |
| `settlement.asset` | string | yes |  |
| `settlement.address` | string | yes |  |
| `reference` | string | no | The merchant's own ID. Unique per merchant and mode, and the idempotency key. |
| `description` | string | no |  |
| `customerEmail` | string | no |  |
| `successUrl` | string | no |  |
| `cancelUrl` | string | no |  |
| `expiresInSec` | integer | no |  |
| `metadata` | object | no |  |

## Responses

| Status | Means |
|---|---|
| `200` | An invoice with this `reference` already exists in this mode; it is returned unchanged |
| `201` | Invoice created. `clientSecret` is shown only here. |


## Request



```bash title="curl"
curl https://api.intents.fi/v0/invoices \
  -X POST \
  -H 'authorization: Bearer $INTENTS_SECRET_KEY' \
  -H 'x-intents-affiliate: <x-intents-affiliate>' \
  -H 'content-type: application/json' \
  -d '{
       "amount": "49.00",
       "settlement": {
         "asset": "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
         "address": "0x6A3fB91c7D8e45A2b0C1fE97D3a8B52c4e7F10dA"
       },
       "reference": "order_1042",
       "description": "Pro plan — 1 month",
       "customerEmail": "ana@example.com",
       "successUrl": "https://northwood.example/thanks"
     }'
```

```ts title="TypeScript"
const response = await fetch("https://api.intents.fi/v0/invoices", {
  method: "POST",
  headers: {
    authorization: `Bearer ${process.env.INTENTS_SECRET_KEY}`,
    "content-type": "application/json",
  },
  body: JSON.stringify({
    "amount": "49.00",
    "settlement": {
      "asset": "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "address": "0x6A3fB91c7D8e45A2b0C1fE97D3a8B52c4e7F10dA"
    },
    "reference": "order_1042",
    "description": "Pro plan — 1 month",
    "customerEmail": "ana@example.com",
    "successUrl": "https://northwood.example/thanks"
  }),
});

if (!response.ok) {
  const { error } = await response.json();
  throw new Error(`${error.code}: ${error.message}`);
}
const data = await response.json();
```

```python title="Python"
import os
import httpx

response = httpx.post(
    "https://api.intents.fi/v0/invoices",
    headers={"authorization": f"Bearer {os.environ['INTENTS_SECRET_KEY']}"},
    json={
        "amount": "49.00",
        "settlement": {
            "asset": "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
            "address": "0x6A3fB91c7D8e45A2b0C1fE97D3a8B52c4e7F10dA"
        },
        "reference": "order_1042",
        "description": "Pro plan — 1 month",
        "customerEmail": "ana@example.com",
        "successUrl": "https://northwood.example/thanks"
    },
)
response.raise_for_status()
data = response.json()
```



## Errors

```json
{ "error": { "code": "INVOICE_EXPIRED", "message": "This invoice has expired" } }
```

Switch on `code`, not on the message: every code has a page under [Error codes](/docs/errors/). Base URL `https://api.intents.fi`; the whole reference is on [one page](/docs/api).

---

Source: https://intents.fi/docs/api/post-invoices · The whole corpus: https://intents.fi/docs/llms-full.txt
