# Create a one-off invoice (charged to the card on file, or sent with a pay link)

`POST /api/v1/invoices/one-off`

Requires an `Idempotency-Key` header and the `invoices.write` capability. Lines are `one_time`, priced in the customer’s currency and taxed like any invoice. A retry with the same key after a crash returns the invoice already written and charges it only if nothing has.

Needs the `invoices:write` scope, or a full-access key.

## Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | required | Required. A unique value for this operation, chosen by you. A retry with the same key and the same body returns the first response instead of running again. The same key with a different body answers 409 `idempotency_key_reused`; a key whose first request is still running answers 409 `idempotency_in_progress`. |

## Request body

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "customer_id": {
      "type": "string",
      "format": "uuid",
      "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
    },
    "customer_external_id": {
      "type": "string",
      "description": "Exactly one of `customer_id` / `customer_external_id`."
    },
    "lines": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "plan_id": {
                "type": "string",
                "format": "uuid",
                "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
              },
              "quantity": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 1000000,
                "default": 1
              }
            },
            "required": [
              "plan_id"
            ]
          },
          {
            "type": "object",
            "properties": {
              "plan_code": {
                "type": "string",
                "description": "The latest active version of this plan code."
              },
              "quantity": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 1000000,
                "default": 1
              }
            },
            "required": [
              "plan_code"
            ]
          },
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "string",
                "maxLength": 500
              },
              "amount_cents": {
                "type": "string",
                "pattern": "^\\d+$",
                "description": "Unit amount.",
                "example": "1999"
              },
              "quantity": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 1000000,
                "default": 1
              }
            },
            "required": [
              "description",
              "amount_cents"
            ]
          }
        ]
      },
      "minItems": 1,
      "maxItems": 20
    },
    "currency": {
      "type": "string",
      "enum": [
        "USD",
        "AUD",
        "CAD",
        "GBP",
        "EUR",
        "INR",
        "NPR"
      ],
      "example": "USD",
      "description": "Optional check; must equal the customer’s currency."
    },
    "metadata": {
      "type": "object",
      "additionalProperties": {
        "anyOf": [
          {
            "type": "string",
            "maxLength": 500
          },
          {
            "type": "number"
          },
          {
            "type": "boolean"
          },
          {
            "type": "null"
          }
        ]
      },
      "description": "At most 20 flat keys, 4 KB as JSON; carried by `invoice.paid`. `credit_pack_pool`, `credit_pack_amount` and `tax_notes` are reserved.",
      "example": {
        "gos_pack": "25k",
        "gos_credits": "25000",
        "gos_request_id": "r1"
      }
    },
    "collection_method": {
      "type": "string",
      "enum": [
        "charge_automatically",
        "send_invoice"
      ],
      "default": "charge_automatically"
    },
    "days_until_due": {
      "type": "integer",
      "minimum": 1,
      "maximum": 365,
      "description": "For send_invoice (asked for, or the no-card fallback). Default 14."
    }
  },
  "required": [
    "lines"
  ]
}
```

## Responses

### 201

The invoice, finalized. With a card on file it is charged after commit (`payment.status` `attempted`; paid is confirmed by `invoice.paid`, which carries the metadata). With no card it is issued as `send_invoice` with a `due_date` and `pay_url`, and never auto-charged. A declined card is `payment.status` `failed` with a `pay_url` — not an error. Paid at once (`payment` null) when the customer credit balance covers it.

JSON Schema:

```json
{
  "type": "object",
  "properties": {
    "data": {
      "type": "object",
      "properties": {
        "invoice": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "format": "uuid",
              "example": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
            },
            "number": {
              "type": "string"
            },
            "status": {
              "type": "string",
              "enum": [
                "finalized",
                "paid"
              ]
            },
            "total_cents": {
              "type": "string",
              "pattern": "^\\d+$",
              "description": "Invoice total.",
              "example": "1999"
            },
            "amount_due_cents": {
              "type": "string",
              "pattern": "^\\d+$",
              "description": "After customer credit.",
              "example": "1999"
            },
            "currency": {
              "type": "string",
              "enum": [
                "USD",
                "AUD",
                "CAD",
                "GBP",
                "EUR",
                "INR",
                "NPR"
              ],
              "example": "USD"
            },
            "collection_method": {
              "type": "string",
              "enum": [
                "charge_automatically",
                "send_invoice"
              ],
              "description": "`send_invoice` when asked for, or when `charge_automatically` was asked for and the customer has no card on file."
            },
            "due_date": {
              "type": [
                "string",
                "null"
              ],
              "format": "date",
              "description": "send_invoice only."
            },
            "metadata": {
              "type": "object",
              "additionalProperties": {}
            }
          },
          "required": [
            "id",
            "number",
            "status",
            "total_cents",
            "amount_due_cents",
            "currency",
            "collection_method",
            "due_date",
            "metadata"
          ]
        },
        "payment": {
          "allOf": [
            {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string",
                  "enum": [
                    "attempted",
                    "skipped",
                    "failed"
                  ]
                },
                "payment_intent_id": {
                  "type": "string",
                  "description": "When attempted; settlement arrives by webhook."
                },
                "reason": {
                  "type": "string",
                  "description": "Why it was skipped or failed; the invoice stays open."
                }
              },
              "required": [
                "status"
              ],
              "description": "What happened when the invoice was charged against the default card after commit."
            },
            {
              "type": [
                "object",
                "null"
              ]
            }
          ]
        },
        "pay_url": {
          "type": [
            "string",
            "null"
          ],
          "description": "The hosted pay page, when the customer has to pay it themselves (send_invoice, or a failed charge). A bearer link: send it only to the customer."
        }
      },
      "required": [
        "invoice",
        "payment",
        "pay_url"
      ]
    },
    "_agent": {
      "type": "object",
      "properties": {
        "summary": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "ok"
          ]
        },
        "next_actions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "summary",
        "status",
        "next_actions",
        "warnings"
      ]
    },
    "api_version": {
      "type": "string",
      "example": "2026-07-01"
    }
  },
  "required": [
    "data",
    "_agent",
    "api_version"
  ]
}
```

### 400

No `Idempotency-Key` header (required: the same key replayed returns the stored reply and never charges again).

### 403

The caller lacks the `invoices.write` capability; nothing is written.

### 404

Unknown customer or plan.

### 422

`currency_mismatch` (`currency` is not the customer’s), `plan_not_one_time` (a plan line must sell a one_time plan), a zero total, or a malformed body.
