> ## 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.

# Create an API key for an agent or CI

> Only from a signed-in session, so one key can't mint another.



## OpenAPI

````yaml /api-reference/openapi.json post /tokens
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:
  /tokens:
    post:
      tags:
        - Account
      summary: Create an API key for an agent or CI
      description: Only from a signed-in session, so one key can't mint another.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                scopes:
                  type: array
                  items:
                    type: string
                    enum:
                      - read
                      - publish
                      - admin
                  minItems: 1
                  default:
                    - read
                expires_in_days:
                  type: integer
                  minimum: 1
                  maximum: 3650
              required:
                - name
      responses:
        '201':
          description: The new key, shown once
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedToken'
        '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:
    CreatedToken:
      allOf:
        - $ref: '#/components/schemas/Token'
        - type: object
          properties:
            key:
              type: string
              description: Shown once. Starts with pch_.
          required:
            - key
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: version_exists
            message:
              type: string
            details: {}
          required:
            - code
            - message
      required:
        - error
    Token:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type:
            - string
            - 'null'
        start:
          type:
            - string
            - 'null'
          description: The first characters, to tell keys apart
        scopes:
          type: array
          items:
            type: string
            enum:
              - read
              - publish
              - admin
        created_at:
          type: string
        expires_at:
          type:
            - string
            - 'null'
        last_used_at:
          type:
            - string
            - 'null'
      required:
        - id
        - name
        - start
        - scopes
        - created_at
        - expires_at
        - last_used_at
  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.