# Create credit refund

> POST /v1/billing/credit-refunds. .

Source: https://legion.ambient.xyz/docs/api/billing/create-credit-refund

`POST https://api.legion.ambient.xyz/v1/billing/credit-refunds`

Authenticate with an API key: `Authorization: Bearer $LEGION_API_KEY`.

. Refunds `amount` of the organization's unused credit through Stripe, to the payment methods of
the top-ups `getCreditRefundQuote` draws on. The balance goes down by `amount`: `payout` goes back to you
and `fee` is the Stripe processing fee kept. `expected_fee` is the fee you were shown; when the fee for
that amount is different now the request is 409 `refund_quote_changed` and nothing moves: get a new quote
and confirm again. Refunds reach a card in 5 to 10 business days.

Refused with 409 `rentals_running` while the organization has a rental that is starting or running (or
waiting to come back): stop them first. A test organization is 409 `test_org_no_refunds`. More than can
be refunded is 409 `exceeds_refundable`.

Requires an `Idempotency-Key`: a repeat with the same key returns the same refund, finishing any part an
error left, and the same key with another amount is 422 `idempotency_key_reused`. Payments failing or not
answering within 3 seconds is 503 `payments_unavailable`: some of the refund may have been made, so retry
with the same key, which finishes it and never refunds twice. Requires `billing.topup` (owners). At most 5
refunds an hour per organization (429 `rate_limited`).

## Headers

- `Idempotency-Key`, string, required: Client-chosen key, unique per request intent, at most 255 characters.

## Request body

- `amount`, Money, required: What to refund, at least 1 cent; `getCreditRefundQuote`'s `amount`.
- `expected_fee`, Money, required: The fee the quote showed for that amount.

Example:

```json
{
  "amount": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "expected_fee": {
    "amount_minor": 250,
    "currency": "USD"
  }
}
```

## Responses

### 201

The refund.

- `id`, string (uuid), required: The refund's ID.
- `amount`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `fee`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `payout`, Money, required
  - `amount_minor`, integer (int64), required: Amount in minor units (cents for USD).
  - `currency`, MoneyCurrency, required: ISO 4217 currency code. Only USD is supported.
- `parts`, array of CreditRefundPart, required
  - `top_up_id`, string, required: The top-up refunded, the `id` of `listTopUps`.
  - `amount`, Money, required: What leaves the balance for this top-up, its fee included.
  - `fee`, Money, required: The part of this top-up's Stripe fee that is kept.
- `created_at`, string (date-time), required

Example:

```json
{
  "id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
  "amount": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "fee": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "payout": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "parts": [
    {
      "top_up_id": "string",
      "amount": {
        "amount_minor": 250,
        "currency": "USD"
      },
      "fee": {
        "amount_minor": 250,
        "currency": "USD"
      }
    }
  ],
  "created_at": "2026-10-15T12:00:00Z"
}
```

### 400

The request is malformed or fails validation. An image reference that
is not a container image reference answers `invalid_image_reference`.

### 401

Missing, unknown, expired or revoked credentials.

### 403

The caller lacks the permission this operation requires (`forbidden`),
or signed in without having joined an organization yet
(`no_organization`; `getOnboarding` and the invitation and
organization operations under it work), or could not sign in
(`email_unverified`, `account_conflict`, and `domain_not_allowed`). `not_invited` is no longer returned to
session tokens.

`access_not_approved`: a signed-in person who is not approved
for the beta yet. Every operation that takes a credential answers it to
them, except `getMe` and `joinMyWaitlist`; the problem carries
`access` (`waitlisted` or `not_requested`, and the email). Approved
means a member of an organization, holding a pending invitation, or Legion; an API key always belongs to a member.

`oauth_token_mcp_only`: the caller sent an OAuth access token (`lgo_`), which is accepted
only by `mcpMessage` and the tool calls it dispatches. Every other operation answers it, whatever
the token's scope. Use an API key or the Legion web app.

`org_suspended`: the caller's organization is suspended. Every operation that takes a
credential answers it, by session or API key, except `getMe` (which shows `org.suspended_at` and
`org.suspension_reason`) and the support operations under `/v1/support/`.

`terms_not_accepted`: an approved caller who has not accepted
the current version of the Terms of Use and the Acceptable Use Policy. Every operation that takes a credential answers it, except `getMe`,
`acceptLegalDocuments`, `joinMyWaitlist` and the wind-down operations
(`listRentals`, `stopRental`, `deleteRental`, `listHosts`,
`updateListing` with `listed` false, `removeHost`); the problem
carries `legal`. An API key acts for the person who created it, so it
is refused until that person accepts. Terminal
operations also return
`session_required` (called with an API key) and `step_up_required`
(neither a sign-in nor a step-up challenge within the step-up window).

### 409

The resource's current state does not allow the operation. `legal_versions_stale`: a legal document version sent is not the current one; the
problem's `legal` holds the current documents.

### 422

The Idempotency-Key was already used with a different request body.

### 429

Rate limited (`code` is `rate_limited`), or the organization asked the
pull-through mirror to copy in too many different tags or digests of one
repository today (`mirror_quota_exceeded`). Retry after the `Retry-After`
seconds.

### 500

An unexpected server error. Safe to retry.

### 503

The payments service failed or did not answer within 3 seconds
(`payments_unavailable`). Nothing changed; retry with backoff.

## Errors

- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)
- 409 [`rentals_running`](https://legion.ambient.xyz/docs/errors#rentals_running)
- 409 [`test_org_no_refunds`](https://legion.ambient.xyz/docs/errors#test_org_no_refunds)
- 409 [`exceeds_refundable`](https://legion.ambient.xyz/docs/errors#exceeds_refundable)
- 409 [`refund_quote_changed`](https://legion.ambient.xyz/docs/errors#refund_quote_changed)
- 422 [`idempotency_key_reused`](https://legion.ambient.xyz/docs/errors#idempotency_key_reused)
- 429 [`rate_limited`](https://legion.ambient.xyz/docs/errors#rate_limited)
- 503 [`payments_unavailable`](https://legion.ambient.xyz/docs/errors#payments_unavailable)

## Example request

```sh
curl -s -X POST "https://api.legion.ambient.xyz/v1/billing/credit-refunds" \
  -H "Authorization: Bearer $LEGION_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": {
    "amount_minor": 250,
    "currency": "USD"
  },
  "expected_fee": {
    "amount_minor": 250,
    "currency": "USD"
  }
}'
```
