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

# Create Temporary Api Key

> Create a temporary API key

A temporary key acts for the caller, and the caller's credits pay for its jobs, but within limits. It expires after
``minutes`` and is never extended. It may use up to ``credit_limit`` credits, runs jobs on simulators only (a dry run may
name any device), and can't delete anything, restart jobs, choose the handle, manage temporary keys, or use the MCP
server. Values above the maximums are lowered to them. Every request creates a new key; the key is in the response this
one time only.

Only the main API key may create temporary keys. The endpoint answers ``402`` when the caller has no credits, or their
temporary keys have used the day's credits, and ``429`` when the caller has the most active keys allowed or has created
the most keys allowed in 24 hours.

Args:
    user (User): User authenticated with their main API key.
    data (TemporaryApiKeySubmitModel): What the key is for, and its lifetime and credit limit.
    db: Database.

Returns:
    NewTemporaryApiKeyModel: The new key, with the key itself.



## OpenAPI

````yaml https://api.haiqu.ai/openapi.json post /user/temporary-keys
openapi: 3.1.0
info:
  title: Haiqu API
  summary: Haiqu RESTful API service.
  description: Cloud service providing the access to Haiqu cloud runtime
  contact:
    name: Haiqu Inc.
    url: https://haiqu.ai/
    email: info@haiqu.ai
  version: 1.8.1
servers: []
security: []
paths:
  /user/temporary-keys:
    post:
      summary: Create Temporary Api Key
      description: >-
        Create a temporary API key


        A temporary key acts for the caller, and the caller's credits pay for
        its jobs, but within limits. It expires after

        ``minutes`` and is never extended. It may use up to ``credit_limit``
        credits, runs jobs on simulators only (a dry run may

        name any device), and can't delete anything, restart jobs, choose the
        handle, manage temporary keys, or use the MCP

        server. Values above the maximums are lowered to them. Every request
        creates a new key; the key is in the response this

        one time only.


        Only the main API key may create temporary keys. The endpoint answers
        ``402`` when the caller has no credits, or their

        temporary keys have used the day's credits, and ``429`` when the caller
        has the most active keys allowed or has created

        the most keys allowed in 24 hours.


        Args:
            user (User): User authenticated with their main API key.
            data (TemporaryApiKeySubmitModel): What the key is for, and its lifetime and credit limit.
            db: Database.

        Returns:
            NewTemporaryApiKeyModel: The new key, with the key itself.
      operationId: create_temporary_api_key_user_temporary_keys_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TemporaryApiKeySubmitModel'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NewTemporaryApiKeyModel'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyQuery: []
        - APIKeyHeader: []
components:
  schemas:
    TemporaryApiKeySubmitModel:
      properties:
        client:
          type: string
          maxLength: 50
          minLength: 1
          title: Client
          description: What the key is for, such as `chatgpt`.
        label:
          anyOf:
            - type: string
              maxLength: 200
            - type: 'null'
          title: Label
          description: A note to tell keys apart, such as the title of the notebook.
        minutes:
          type: integer
          minimum: 1
          title: Minutes
          description: How long the key lasts, at most 60 minutes. It is never extended.
          default: 30
        credit_limit:
          type: integer
          minimum: 1
          title: Credit Limit
          description: The most credits that the key's jobs may use, at most 3600.
          default: 600
      type: object
      required:
        - client
      title: TemporaryApiKeySubmitModel
      description: >-
        A request for a temporary API key. Values above the maximums are lowered
        to them.
    NewTemporaryApiKeyModel:
      properties:
        id:
          type: integer
          title: Id
        prefix:
          type: string
          title: Prefix
          description: The start of the key, to tell keys apart.
        client:
          type: string
          title: Client
        label:
          anyOf:
            - type: string
            - type: 'null'
          title: Label
        credit_limit:
          type: integer
          title: Credit Limit
        credits_spent:
          type: number
          title: Credits Spent
          description: >-
            The credits that the key's finished jobs have used. A job is charged
            when it ends.
          default: 0
        created_at:
          type: string
          format: date-time
          title: Created At
        expires_at:
          type: string
          format: date-time
          title: Expires At
        revoked_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Revoked At
        key:
          type: string
          title: Key
      type: object
      required:
        - id
        - prefix
        - client
        - label
        - credit_limit
        - created_at
        - expires_at
        - revoked_at
        - key
      title: NewTemporaryApiKeyModel
      description: >-
        A new temporary API key, with the key itself, which is shown this one
        time only.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyQuery:
      type: apiKey
      in: query
      name: HAIQU_API_KEY
    APIKeyHeader:
      type: apiKey
      in: header
      name: authorization

````

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