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

# Create User

> Create a Postgres user within a specific cluster. Fetch the generated password from the credentials endpoint.



## OpenAPI

````yaml /machines-api/openapi.json post /v1/postgres/{postgres_cluster_id}/users
openapi: 3.0.1
info:
  title: Machines API
  description: >-
    This site hosts documentation generated from the Fly.io Machines API OpenAPI
    specification. Visit our complete [Machines API
    docs](https://fly.io/docs/machines/api/) for how to get started, more
    information about each endpoint, parameter descriptions, and examples.
  contact: {}
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: '1.0'
servers:
  - url: https://api.machines.dev
security: []
tags:
  - name: Apps
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/apps-resource/) for details about
      using the Apps resource.
  - name: Machines
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/machines-resource/) for details
      about using the Machines resource.
  - name: TLS Certificates
    description: >
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/certificates-resource/) for details
      about using the TLS Certificates resource.
  - name: Volumes
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/volumes-resource/) for details
      about using the Volumes resource.
  - name: Postgres Clusters
    description: >-
      Create and manage Postgres clusters, including databases, users,
      extensions, backups, and app attachments.
externalDocs:
  url: https://fly.io/docs/machines/working-with-machines/
paths:
  /v1/postgres/{postgres_cluster_id}/users:
    post:
      tags:
        - Postgres Clusters
      summary: Create User
      description: >-
        Create a Postgres user within a specific cluster. Fetch the generated
        password from the credentials endpoint.
      operationId: Postgres_users_create
      parameters:
        - name: postgres_cluster_id
          in: path
          description: Managed Postgres Cluster ID
          required: true
          schema:
            type: string
      requestBody:
        description: User details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createPostgresUserRequest'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/createPostgresUserResponse'
        '400':
          description: Username is reserved, a system user, or malformed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '409':
          description: User already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '422':
          description: username or role missing, or role invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '503':
          description: >-
            pg-admin is unavailable; retry after the interval given by the
            Retry-After header
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
      security:
        - FlyBearerAuth: []
components:
  schemas:
    createPostgresUserRequest:
      required:
        - role
        - username
      type: object
      properties:
        role:
          type: string
          description: Role to grant the user.
          example: writer
          enum:
            - schema_admin
            - writer
            - reader
        username:
          type: string
          description: >-
            Name for the new user. Must start and end with a lowercase
            alphanumeric

            character and may contain hyphens and underscores, up to 63
            characters.
          example: app_user
    createPostgresUserResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/PostgresUser'
    PostgresErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
    PostgresUser:
      type: object
      properties:
        role:
          type: string
          description: User role.
          enum:
            - schema_admin
            - writer
            - reader
        username:
          type: string
          description: User name.
  securitySchemes:
    FlyBearerAuth:
      type: apiKey
      description: >-
        A Fly API token with access to the requested organization or resource.
        Send it as `Authorization: Bearer <Fly API token>`.
      name: Authorization
      in: header

````