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

# Get a token that says who's playing a game

> The play page asks for one for the game it plays and hands it to the game (`window.patch`), so the game's own server can tell who's playing without asking Patch. Signed-out players get 401: a game asks them to sign in with `patch.signIn()`. With an API key, it's a token for the key's account, for testing a game's server.



## OpenAPI

````yaml /api-reference/openapi.json post /games/token
openapi: 3.1.0
info:
  title: Patch API
  version: 1.0.0
  description: >-
    The public API behind patch.gg, the desktop app and pch. Changes within v1
    are additive only. Errors are { error: { code, message, details } }; branch
    on code.
servers:
  - url: https://patch.gg/api/v1
security: []
paths:
  /games/token:
    post:
      tags:
        - Games
      summary: Get a token that says who's playing a game
      description: >-
        The play page asks for one for the game it plays and hands it to the
        game (`window.patch`), so the game's own server can tell who's playing
        without asking Patch. Signed-out players get 401: a game asks them to
        sign in with `patch.signIn()`. With an API key, it's a token for the
        key's account, for testing a game's server.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                project:
                  type: string
                  pattern: ^[a-z0-9][a-z0-9_-]*\/[a-z0-9][a-z0-9-]*$
                  example: mira/lantern-run
                release:
                  type: string
                  format: uuid
                  description: >-
                    The release a test link plays (`?release=` on the play
                    page): anyone signed in may play one that hasn't been turned
                    down, whoever can see the game.
              required:
                - project
      responses:
        '200':
          description: A token for the game
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GameToken'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Not signed in
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearer: []
components:
  schemas:
    GameToken:
      type: object
      properties:
        token:
          type: string
          description: >-
            A JWT signed with ES256 by a key at GET /v1/games/keys, for 15
            minutes. `iss` is this environment's address (https://patch.gg in
            production), `aud` the game's project id, `sub` the player's id in
            this game; `game`, `handle`, `name` and `picture` are claims too.
        expires_at:
          type: string
        player:
          $ref: '#/components/schemas/GamePlayer'
        game:
          type: object
          properties:
            id:
              type: string
              format: uuid
              description: 'The project''s id: the token''s `aud`'
            handle:
              type: string
              example: mira/lantern-run
          required:
            - id
            - handle
      required:
        - token
        - expires_at
        - player
        - game
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: version_exists
            message:
              type: string
            details: {}
          required:
            - code
            - message
      required:
        - error
    GamePlayer:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: >-
            The player's id in this game only: the token's `sub`. Another game
            sees another id for the same person.
        handle:
          type:
            - string
            - 'null'
          description: Their Patch handle, lowercase; null until they've picked one
          example: mira
        name:
          type:
            - string
            - 'null'
          description: Their handle as they write it
        picture:
          type:
            - string
            - 'null'
          format: uri
          description: Their picture, or null for the figure Patch grows from their handle
      required:
        - id
        - handle
        - name
        - picture
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: An API key (pch_...) or the token from pch login.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.