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

# Create API key

> Issue a scoped API key for a workspace.



## OpenAPI

````yaml api-reference/accounts/openapi.json POST /v1/{workspaceId}/developer/api-keys
openapi: 3.0.3
info:
  title: Persistence Accounts and Workspaces API
  version: '1.0'
  description: Manage Persistence workspaces and their API keys.
servers:
  - url: https://api.persistence.dev
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Accounts and workspaces
    description: Workspace management and API key creation.
paths:
  /v1/{workspaceId}/developer/api-keys:
    post:
      tags:
        - Accounts and workspaces
      summary: Create API key
      description: >-
        Create an API key for a workspace. The response contains the key value,
        which is returned only on creation.
      operationId: createApiKey
      parameters:
        - name: workspaceId
          in: path
          required: true
          schema:
            type: string
          description: Workspace ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiKeyRequest'
        description: API key creation request
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    ApiKeyRequest:
      type: object
      required:
        - name
        - scopes
      properties:
        description:
          type: string
        expiresAt:
          type: string
        name:
          type: string
        revokeExisting:
          type: boolean
        scopes:
          type: array
          items:
            type: string
    ApiKeyResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/ApiKey'
        success:
          type: boolean
    Error:
      type: object
      properties:
        code:
          type: string
        error:
          type: string
    ApiKey:
      type: object
      properties:
        createdAt:
          type: string
        createdBy:
          type: string
        description:
          type: string
        expiresAt:
          type: string
        id:
          type: string
        key:
          type: string
        lastUsedAt:
          type: string
        name:
          type: string
        scopes:
          type: array
          items:
            $ref: '#/components/schemas/ApiKeyScope'
        spaceName:
          type: string
        status:
          $ref: '#/components/schemas/APIKeyStatus'
        updatedAt:
          type: string
    ApiKeyScope:
      type: object
      properties:
        description:
          type: string
        name:
          type: string
        scope:
          type: string
    APIKeyStatus:
      type: string
      enum:
        - active
        - revoked
      x-enum-varnames:
        - APIKeyStatusActive
        - APIKeyStatusRevoked
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key issued for your workspace.

````