# Redeem a Voucher

`POST /v1/credits:redeem`

Redeem a credit voucher for your organization, as the billing page does.

Any member of the organization may redeem; a key needs `credits:write`.
Credits are the organization's, so a workspace or restricted key is
refused. An unknown, used or expired code is a 400 with the reason.
Buying credits stays in the dashboard.

- Base URL: `https://api.qualia.dev`
- Authentication: an API key in the `X-API-Key` header, or `Authorization: Bearer …`

## Request body

Required: `application/json` `RedeemVoucherRequest`

## Responses

- `200` The voucher's credits were added: `application/json` `VoucherRedemptionResponse`
- `400` An unknown, used or expired code, in the billing page's words: `application/json` `ErrorResponse`
- `401` Invalid or missing API key: `application/json` `ErrorResponse`
- `403` The key lacks credits:write, or is a workspace key: `application/json` `ErrorResponse`
- `422` Validation Error: `application/json` `HTTPValidationError`

## Schemas

```yaml
RedeemVoucherRequest:
  properties:
    code:
      type: string
      maxLength: 256
      minLength: 1
      description: The voucher code to redeem
  type: object
  required:
    - code
  title: RedeemVoucherRequest
  description: A voucher code, as the billing page takes it.
VoucherRedemptionResponse:
  properties:
    credits_granted:
      type: integer
      description: Credits the voucher added
    account_id:
      type: string
      description: The organization they were added to
  type: object
  required:
    - credits_granted
    - account_id
  title: VoucherRedemptionResponse
  description: A redeemed voucher.
ErrorResponse:
  properties:
    detail:
      type: string
      description: Error message describing what went wrong
  type: object
  required:
    - detail
  title: ErrorResponse
  description: Standard error response.
HTTPValidationError:
  properties:
    detail:
      items:
        $ref: "#/components/schemas/ValidationError"
      type: array
  type: object
  title: HTTPValidationError
ValidationError:
  properties:
    loc:
      items:
        type:
          - string
          - integer
      type: array
      title: Location
    msg:
      type: string
      title: Message
    type:
      type: string
      title: Error Type
    input: {}
    ctx:
      type: object
      title: Context
  type: object
  required:
    - loc
    - msg
    - type
  title: ValidationError
```
