Source: https://developers.tokportal.com/convert-slots-to-credits/
Markdown: https://developers.tokportal.com/convert-slots-to-credits.md

# Convert Video Slots to Credits

Turn **unused video slots** back into credits. Use it when a bundle has more video slots than you will post, for example after a campaign was shortened or when you bought slots ahead of time.

The converted slots are removed from their bundles and their credits go back to your workspace balance. The account manager has nothing to do.

Only video slots can be converted. A whole bundle cannot: account creation and warming are not returned.

**Credits returned:** a video slot costs 2 credits today, so a slot gives back at most 2 credits.

## How it works

Conversion takes two calls:

1. **Quote**: name the slots. TokPortal answers with the slots it can convert, the credits that would come back, their expiry dates, the slots it refuses and why, and a `quote_id` valid **10 minutes**. Nothing is converted.
2. **Convert**: send the `quote_id`. The conversion is **irreversible**.

> **WARNING: Confirm with the user before step 2**
> Agents and integrations must show the user the amount (`credits`) and the expiry (`credit_groups`) from the quote and get their confirmation before calling step 2. Over MCP, the step 2 tool is flagged `destructiveHint: true`.

## Step 1: Get a quote

```
POST /videos/convert-to-credits/quote
```

### Request Body

| Field        | Type             | Required | Description                                                                    |
| ------------ | ---------------- | -------- | ------------------------------------------------------------------------------ |
| `video_ids`  | string\[] (UUID) | No       | Video slots to convert, by video ID.                                           |
| `bundle_ids` | string\[] (UUID) | No       | Bundles whose unused slots (`pending` or `configured`) should all be included. |

Send `video_ids`, `bundle_ids` or both, with at least one ID. Duplicates are ignored. One quote covers at most **1,000 slots** (counting every unused slot of the bundles you name) and **200 bundles**.

```bash
curl -X POST https://app.tokportal.com/api/ext/videos/convert-to-credits/quote \
  -H "X-API-Key: sk_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "video_ids": ["{video_id}"],
    "bundle_ids": ["{bundle_id}"]
  }'
```

### Response (200)

```json
{
  "data": {
    "quote_id": "uuid",
    "expires_at": "2026-11-23T10:10:00Z",
    "credits": 4,
    "credit_groups": [
      { "credits": 2, "expires_at": null },
      { "credits": 2, "expires_at": "2027-01-15T00:00:00Z" }
    ],
    "convertible": [
      {
        "video_id": "uuid",
        "bundle_id": "uuid",
        "position": 4,
        "status": "configured",
        "credits": 2,
        "expired_credits": 0
      },
      {
        "video_id": "uuid",
        "bundle_id": "uuid",
        "position": 5,
        "status": "pending",
        "credits": 2,
        "expired_credits": 0
      }
    ],
    "not_convertible": [
      {
        "video_id": "uuid",
        "bundle_id": "uuid",
        "position": 3,
        "reason": "slot_status",
        "status": "published",
        "expired_on": null
      }
    ],
    "missing_bundle_ids": []
  }
}
```

| Field                | Type           | Description                                                                                                                                                        |
| -------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `quote_id`           | string \| null | Pass it to step 2 within 10 minutes. `null` when nothing can be converted, and on a dry run.                                                                       |
| `expires_at`         | string \| null | When the quote expires.                                                                                                                                            |
| `credits`            | integer        | Total credits the conversion would give back.                                                                                                                      |
| `credit_groups`      | array          | `{ credits, expires_at }` per expiry date. `expires_at: null` means the credits never expire.                                                                      |
| `convertible`        | array          | Slots that would be converted: `{ video_id, bundle_id, position, status, credits, expired_credits }`.                                                              |
| `not_convertible`    | array          | Refused slots: `{ video_id, bundle_id, position, reason, status, expired_on }`. See [Reasons](https://developers.tokportal.com/convert-slots-to-credits/#reasons). |
| `missing_bundle_ids` | array          | Requested bundles that do not exist in this workspace.                                                                                                             |

Send the `X-TokPortal-Dry-Run: true` header to get the same answer without storing a quote (`quote_id` is `null`). See [Sandbox](https://developers.tokportal.com/sandbox).

## Step 2: Convert

```
POST /videos/convert-to-credits
```

| Field      | Type          | Required | Description                                           |
| ---------- | ------------- | -------- | ----------------------------------------------------- |
| `quote_id` | string (UUID) | Yes      | The `quote_id` from step 1, less than 10 minutes old. |

```bash
curl -X POST https://app.tokportal.com/api/ext/videos/convert-to-credits \
  -H "X-API-Key: sk_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "quote_id": "{quote_id}"
  }'
```

### Response (200)

```json
{
  "data": {
    "quote_id": "uuid",
    "credits": 4,
    "credit_groups": [
      { "credits": 2, "expires_at": null },
      { "credits": 2, "expires_at": "2027-01-15T00:00:00Z" }
    ],
    "converted": [
      {
        "video_id": "uuid",
        "bundle_id": "uuid",
        "position": 4,
        "status": "configured",
        "credits": 2,
        "expired_credits": 0
      },
      {
        "video_id": "uuid",
        "bundle_id": "uuid",
        "position": 5,
        "status": "pending",
        "credits": 2,
        "expired_credits": 0
      }
    ],
    "bundles": [
      { "bundle_id": "uuid", "slots_converted": 2, "mission_completed": false }
    ],
    "credits_balance": 1244
  }
}
```

| Field             | Type           | Description                                                                                                                             |
| ----------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `credits`         | integer        | Credits added back to the balance.                                                                                                      |
| `credit_groups`   | array          | Same shape as in the quote.                                                                                                             |
| `converted`       | array          | Slots removed from their bundles. Their video IDs and positions no longer exist.                                                        |
| `bundles`         | array          | `{ bundle_id, slots_converted, mission_completed }` per bundle. `mission_completed` is `true` when the conversion completed the bundle. |
| `credits_balance` | number \| null | Balance after the conversion. `null` on a dry run.                                                                                      |

A quote is redeemed **once**. If any quoted slot changed since the quote, nothing is converted: the call answers `409 VIDEO_SLOT_CONVERSION_QUOTE_CHANGED` and you ask for a new quote. With the dry-run header, step 2 checks the quote and returns what it would convert, without converting anything.

### What changes after a conversion

- The slots are removed from their bundles. Their video IDs and positions stop existing: a call on a converted position answers `VIDEO_NOT_FOUND`, or `VIDEO_POSITION_OUT_OF_RANGE` when it was the highest one.
- The remaining slots keep their positions. A bundle's positions can now have gaps, and a position is never reused: slots added later with [add-video-slots](https://developers.tokportal.com/publish-unpublish#add-video-slots) are numbered after the highest existing position.
- The bundle's `videos_quantity` goes down by the number of slots converted.
- The credits go back to the workspace balance, with the expiry shown in the quote.
- When the last open slot of an `accepted` bundle is converted, the bundle completes (`mission_completed: true`), unless its account, warming or edits are still in progress.
- The account manager has nothing to do.

## Eligibility

A slot can be converted only when every rule below holds. The quote lists each refused slot in `not_convertible` with its reason.

| Rule           | Requirement                                                                                                                                         |
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| Slot status    | `pending` or `configured`. [Unschedule](https://developers.tokportal.com/video-actions#unschedule-a-video) a `published` or `accepted` video first. |
| Bundle payment | The bundle was paid with credits.                                                                                                                   |
| Bundle status  | `accepted` or `pending_setup`.                                                                                                                      |
| Bundle history | TokPortal never reset the bundle, and it was never refunded after a ban.                                                                            |
| Slot history   | The slot was never posted and carries no paid work.                                                                                                 |
| Credit expiry  | At least part of the credits that paid for the slot has not expired.                                                                                |

### Reasons

| `reason`                       | Meaning                                                                                                                            |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| `not_found`                    | No such slot in this workspace.                                                                                                    |
| `bundle_not_paid_with_credits` | The bundle was not paid with credits.                                                                                              |
| `bundle_status`                | Only `accepted` and `pending_setup` bundles qualify. `status` carries the bundle's status.                                         |
| `slot_status`                  | Only `pending` and `configured` slots qualify. Unschedule a published or accepted video first. `status` carries the slot's status. |
| `bundle_ban_refunded`          | The bundle was refunded after a ban.                                                                                               |
| `bundle_reset`                 | TokPortal reset the bundle's account, so its slots cannot be told apart from delivered ones.                                       |
| `slot_has_history`             | The slot was posted or carries paid work.                                                                                          |
| `credits_expired`              | Every credit that paid for the slot has expired. `expired_on` gives the date.                                                      |

## Credit expiry

Returned credits keep the **expiry date of the credits that originally paid for the slot**:

- Credits that never expire come back never expiring (`expires_at: null`).
- Credits with an expiry date come back with that same date.
- The part already expired is not returned. It shows as `expired_credits` on the slot, and `credits` is reduced by that amount.
- A slot whose credits have all expired cannot be converted (`credits_expired`, with `expired_on`).

`credit_groups` adds up the returned credits per expiry date, so you can show the user exactly what comes back and until when.

## Errors

| Code                                    | Status | When                                                                                                                            |
| --------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------- |
| `VIDEO_SLOT_CONVERSION_TOO_MANY_SLOTS`  | 400    | More than 1,000 slots or 200 bundles in one quote. `details.max_slots` and `details.max_bundles` give the limits                |
| `VIDEO_SLOT_CONVERSION_QUOTE_NOT_FOUND` | 404    | The quote does not exist in this workspace                                                                                      |
| `VIDEO_SLOT_CONVERSION_QUOTE_EXPIRED`   | 409    | The quote is older than 10 minutes. Ask for a new quote                                                                         |
| `VIDEO_SLOT_CONVERSION_QUOTE_USED`      | 409    | The quote was already redeemed. Its slots are converted                                                                         |
| `VIDEO_SLOT_CONVERSION_QUOTE_CHANGED`   | 409    | A slot or its credits changed since the quote. Nothing was converted. Check `details.not_convertible`, then ask for a new quote |

Nothing is converted when step 2 fails.

## Webhook

Each converted slot emits one [`video.converted_to_credits`](https://developers.tokportal.com/webhooks#the-videoconverted_to_credits-event) event with `video_id`, `bundle_id`, `position`, `status: "converted_to_credits"`, `previous_status` (`pending` or `configured`) and `credits_returned`.

## MCP

| Step       | Tool                                                                 |
| ---------- | -------------------------------------------------------------------- |
| 1. Quote   | `tokportal_quote_video_slot_conversion`                              |
| 2. Convert | `tokportal_convert_video_slots_to_credits` (`destructiveHint: true`) |

Show the user the quoted amount and expiry and get a clear yes before calling the second tool. See [MCP server](https://developers.tokportal.com/mcp#tool-annotations).

> **NOTE: Dashboard**
> In the dashboard, open the bundle's **Videos** page and choose **Convert to credits** in the options of an unused video, or select several unused videos to convert them together. The dashboard shows the same quote, with the amount and expiry, before you confirm.
