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

# Create a machine user

> Creates a team-owned identity with an optional first API key returned only once.



## OpenAPI

````yaml post /v1/grid/machine_users
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/grid/machine_users:
    post:
      summary: Creates a machine user
      description: >-
        Creates a team-owned identity for an application, with its own Grid
        budget. Set `api_key` to also create its first API key, which the
        response returns only once. Set the machine user's spend limit with the
        user settings endpoint, using its `id` as the user ID. Requires team
        admin.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateGridMachineUserRequestV1'
        required: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedGridMachineUserV1'
      x-codeSamples:
        - lang: bash
          source: |-
            curl --request POST \
            --url https://api.baseten.co/v1/grid/machine_users \
            --header "Authorization: Bearer $BASETEN_API_KEY" \
            --data '{
              "team_id": "abc1234",
              "name": "night-shift",
              "api_key": null
            }'
        - lang: python
          source: |-
            import requests
            import os
            API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
            url = "https://api.baseten.co/v1/grid/machine_users"

            headers = {"Authorization": f"Bearer {API_KEY}"}

            response = requests.request(
                "POST",
                url,
                headers=headers,
                json={'team_id': 'abc1234', 'name': 'night-shift', 'api_key': None}
            )

            print(response.text)
components:
  schemas:
    CreateGridMachineUserRequestV1:
      additionalProperties: false
      properties:
        team_id:
          anyOf:
            - minLength: 1
              type: string
            - type: 'null'
          default: null
          description: >-
            Identifier of the team that owns the machine user. Defaults to your
            only team, if you belong to exactly one.
          examples:
            - abc1234
          title: Team Id
        name:
          description: >-
            Name of the machine user, unique within the team. At most 255
            characters.
          examples:
            - night-shift
          maxLength: 255
          minLength: 1
          title: Name
          type: string
        api_key:
          anyOf:
            - $ref: '#/components/schemas/CreateGridMachineUserAPIKeyRequestV1'
            - type: 'null'
          default: null
          description: When set, also creates the machine user's first API key.
      required:
        - name
      title: CreateGridMachineUserRequestV1
      type: object
    CreatedGridMachineUserV1:
      properties:
        id:
          description: >-
            Stable machine user identifier. Grid usage and settings identify the
            machine user by this ID as its `user_id`.
          title: Id
          type: string
        name:
          description: Name of the machine user, unique within its team.
          title: Name
          type: string
        team_id:
          description: Identifier of the team that owns the machine user.
          title: Team Id
          type: string
        team_name:
          description: Name of the team that owns the machine user.
          title: Team Name
          type: string
        created_by:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: ID of the user who created the machine user. Null when unknown.
          title: Created By
        created_at:
          description: Creation time, ISO 8601.
          format: date-time
          title: Created At
          type: string
        api_key:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            The first API key, returned only once. Null unless the request set
            `api_key`.
          title: Api Key
      required:
        - id
        - name
        - team_id
        - team_name
        - created_at
      title: CreatedGridMachineUserV1
      type: object
    CreateGridMachineUserAPIKeyRequestV1:
      additionalProperties: false
      properties:
        name:
          anyOf:
            - maxLength: 255
              minLength: 1
              type: string
            - type: 'null'
          default: null
          description: >-
            Name of the API key: lowercase letters, numbers, and hyphens, at
            most 255 characters, and unique among the machine user's active
            keys. Defaults to a name derived from the machine user's.
          examples:
            - production
          title: Name
      title: CreateGridMachineUserAPIKeyRequestV1
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````