> ## Documentation Index
> Fetch the complete documentation index at: https://docs.decibel.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /api/v1/referrals/redeem

> Redeems a referral code for an account. Validates the code in ClickHouse,
then submits an `admin_create_new_subaccount` transaction on-chain to create
the user's subaccount (bypassing invite-only gating).

Referral tracking (code → user → referrer) stays entirely off-chain in ClickHouse.
Fee discounts and on-chain referral relationships will be bulk-registered post-TGE.

After successful on-chain tx, writes a record to `referral_redemptions` in ClickHouse
to track usage_count for code exhaustion.

This handler is **idempotent**: retrying the same (account, code) pair returns 200.
Retrying with a *different* code returns 409.

**Graceful degradation**: if ClickHouse writes fail after on-chain tx success,
the handler still returns 200 (the tx is the source of truth). Failed CH writes
are logged with `RECONCILE_NEEDED` prefix for manual follow-up.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/referrals/redeem
openapi: 3.1.0
info:
  title: Decibel Trading API
  description: >-
    RESTful API for Decibel. Provides read-only endpoints for market data,
    trading operations, positions, and analytics.
  contact:
    name: Decibel Team
    url: https://decibel.trade/
  license:
    name: ''
  version: 1.0.0
servers:
  - url: https://api.mainnet.aptoslabs.com/decibel
    description: Mainnet
  - url: https://api.testnet.aptoslabs.com/decibel
    description: Testnet
security:
  - bearerAuth: []
tags:
  - name: Market Data
    description: Market information and real-time data endpoints
  - name: User
    description: User information and account management
  - name: Account
    description: Account-specific endpoints and data
  - name: Trades
    description: Trading operations and history
  - name: Positions
    description: User position management
  - name: Orders
    description: Order management and history
  - name: TWAP
    description: Time-weighted average price orders
  - name: Bulk Orders
    description: Bulk order management
  - name: Vaults
    description: Vault operations and management
  - name: Analytics
    description: Analytics and performance metrics
  - name: Points
    description: Points-related account metrics
  - name: Trading Points
    description: Trading points endpoints
  - name: Trading Hz
    description: Trading Hz endpoints
  - name: Tier
    description: Tier information endpoints
  - name: Streaks
    description: User streak tracking endpoints
  - name: Predeposit Rewards
    description: Season 0 predeposit USDC rewards
  - name: Referrals
    description: Referral code management and tracking
  - name: Affiliates
    description: Affiliate code and earnings endpoints
paths:
  /api/v1/referrals/redeem:
    post:
      tags:
        - Referrals
      summary: POST /api/v1/referrals/redeem
      description: >-
        Redeems a referral code for an account. Validates the code in
        ClickHouse,

        then submits an `admin_create_new_subaccount` transaction on-chain to
        create

        the user's subaccount (bypassing invite-only gating).


        Referral tracking (code → user → referrer) stays entirely off-chain in
        ClickHouse.

        Fee discounts and on-chain referral relationships will be
        bulk-registered post-TGE.


        After successful on-chain tx, writes a record to `referral_redemptions`
        in ClickHouse

        to track usage_count for code exhaustion.


        This handler is **idempotent**: retrying the same (account, code) pair
        returns 200.

        Retrying with a *different* code returns 409.


        **Graceful degradation**: if ClickHouse writes fail after on-chain tx
        success,

        the handler still returns 200 (the tx is the source of truth). Failed CH
        writes

        are logged with `RECONCILE_NEEDED` prefix for manual follow-up.
      operationId: handle_redeem_referral
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RedeemReferralRequestDto'
        required: true
      responses:
        '200':
          description: Referral code redeemed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RedeemReferralResponseDto'
        '400':
          description: Invalid account or referral code format
        '404':
          description: Referral code not found
        '409':
          description: Already redeemed or code inactive
        '500':
          description: Internal server error
        '501':
          description: Referral redemption not enabled
components:
  schemas:
    RedeemReferralRequestDto:
      type: object
      description: Request body for POST /api/v1/referrals/redeem
      required:
        - referral_code
        - account
      properties:
        account:
          type: string
          description: The wallet address redeeming the code (not a subaccount address)
        referral_code:
          type: string
          description: The referral code to redeem
    RedeemReferralResponseDto:
      type: object
      description: Response for POST /api/v1/referrals/redeem
      required:
        - referral_code
        - account
      properties:
        account:
          type: string
          description: The wallet address that redeemed the code (not a subaccount address)
        referral_code:
          type: string
          description: The referral code that was redeemed
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token from Geomi. See
        [Authentication](/api-reference/rest/authentication) for setup
        instructions.

````