> ## Documentation Index
> Fetch the complete documentation index at: https://hedgeem-api.qeetoto.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Leave table

> Credits the player's seat balance back to their wallet (account balance)
and resets the game state to `STATUS_START`.

Call this when the player clicks **Back to Lobby** or otherwise exits a
game session. The `game-shell.html` compliance bar calls this endpoint
automatically before navigating home.

**Idempotent:** safe to call if the player is not currently seated or if
their seat balance is already zero — returns the current account balance
with `creditsReturned: 0`.

This is the reverse of `POST /api/tables/{tableId}/sit`. Together they
implement the casino-style two-balance model:
- `wallets.balance` — account (lobby header)
- `game_table_state.seat_balance` — chips on the felt at a specific table




## OpenAPI

````yaml /openapi.yaml post /api/tables/{tableId}/leave
openapi: 3.0.0
info:
  title: Texas Hedge'Em API
  version: 0.4.0
  description: >
    REST API for Texas Hedge'Em v5 — a player-vs-house poker odds game.


    Players place bets on the odds of multiple simultaneous poker hands

    at three betting stages: **Hole**, **Flop**, and **Turn**.

    The River card determines the winning hand and pays out winners.


    **Base URL:** `https://hedgeem-server.qeetoto.com`


    **Authentication:** All endpoints except `/api/health` and `GET /api/tables`

    require a Supabase JWT passed as a Bearer token in the `Authorization`
    header.

    See [Authentication](/authentication) for details.


    **Two-balance wallet model:** Every player has two separate balances:

    `accountBalance` (funds in their lobby wallet) and `seatBalance` (chips on
    the

    felt at a specific table). Sit deducts from account; Leave credits seat back
    to

    account; Top-up transfers account → seat during a session.
  contact:
    url: https://github.com/texashedgeem/hedgeem-v5
  license:
    name: MIT
servers:
  - url: https://hedgeem-server.qeetoto.com
    description: Production (Vercel)
  - url: http://localhost:3000
    description: Local development
security:
  - bearerAuth: []
paths:
  /api/tables/{tableId}/leave:
    post:
      tags:
        - Tables
      summary: Leave table
      description: >
        Credits the player's seat balance back to their wallet (account balance)

        and resets the game state to `STATUS_START`.


        Call this when the player clicks **Back to Lobby** or otherwise exits a

        game session. The `game-shell.html` compliance bar calls this endpoint

        automatically before navigating home.


        **Idempotent:** safe to call if the player is not currently seated or if

        their seat balance is already zero — returns the current account balance

        with `creditsReturned: 0`.


        This is the reverse of `POST /api/tables/{tableId}/sit`. Together they

        implement the casino-style two-balance model:

        - `wallets.balance` — account (lobby header)

        - `game_table_state.seat_balance` — chips on the felt at a specific
        table
      operationId: leaveTable
      parameters:
        - $ref: '#/components/parameters/tableId'
      responses:
        '200':
          description: Seat balance credited back to wallet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LeaveResponse'
              examples:
                with_credits:
                  summary: Player had chips — credited back
                  value:
                    acknowledgement: ACK
                    creditsReturned: 475
                    newAccountBalance: 1475
                no_credits:
                  summary: Seat was already empty
                  value:
                    acknowledgement: ACK
                    creditsReturned: 0
                    newAccountBalance: 1000
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  parameters:
    tableId:
      name: tableId
      in: path
      required: true
      description: Unique numeric table identifier
      schema:
        type: integer
        minimum: 1
        example: 1
  schemas:
    LeaveResponse:
      type: object
      properties:
        acknowledgement:
          type: string
          enum:
            - ACK
            - NACK
        creditsReturned:
          type: number
          description: >-
            Amount credited back from seat to wallet (£). Zero if seat was
            already empty.
          example: 475
        newAccountBalance:
          type: number
          description: Player's wallet balance after crediting seat funds.
          example: 1475
    ApiError:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message
          example: Invalid tableId.
  responses:
    Unauthorized:
      description: Missing or invalid Bearer token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error: Missing or invalid Authorization header.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Supabase Auth JWT. Obtain via Supabase Auth sign-in.

````