> ## Documentation Index
> Fetch the complete documentation index at: https://factory-docs-auto-sync-jp-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate a service account API key

> DESTRUCTIVE: atomically revokes the existing key and issues a replacement that inherits its name, returning the new one-time key value (shown only once). The previous key stops authenticating the instant this call succeeds, so any client still using it will immediately start failing with 401. Update every consumer with the new value before rotating, or set `gracePeriodMinutes` to keep the old key valid for a short overlap window.



## OpenAPI

````yaml https://api.factory.ai/api/v0/openapi.json post /api/v0/service-accounts/{serviceAccountId}/api-keys/{keyId}/rotate
openapi: 3.0.1
info:
  title: Factory Public API
  description: >-
    Public API for Factory platform. Requires authentication via the
    `Authorization: Bearer` header.
  version: 0.1.0
servers:
  - url: https://api.factory.ai/
    description: Production
security:
  - BearerAuth: []
paths:
  /api/v0/service-accounts/{serviceAccountId}/api-keys/{keyId}/rotate:
    post:
      tags:
        - Service Accounts
      summary: Rotate a service account API key
      description: >-
        DESTRUCTIVE: atomically revokes the existing key and issues a
        replacement that inherits its name, returning the new one-time key value
        (shown only once). The previous key stops authenticating the instant
        this call succeeds, so any client still using it will immediately start
        failing with 401. Update every consumer with the new value before
        rotating, or set `gracePeriodMinutes` to keep the old key valid for a
        short overlap window.
      operationId: rotateServiceAccountApiKey
      parameters:
        - name: serviceAccountId
          in: path
          required: true
          schema:
            type: string
            minLength: 1
            description: Service account ID
        - name: keyId
          in: path
          required: true
          schema:
            type: string
            minLength: 1
            description: API key ID
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RotateServiceAccountApiKeyRequestBody'
      responses:
        '200':
          description: Response for status 200
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey200ResponseBody'
        '400':
          description: Response for status 400
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey400ResponseBody'
        '401':
          description: Response for status 401
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey401ResponseBody'
        '403':
          description: Response for status 403
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey403ResponseBody'
        '404':
          description: Response for status 404
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey404ResponseBody'
        '409':
          description: Response for status 409
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey409ResponseBody'
        '500':
          description: Response for status 500
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RotateServiceAccountApiKey500ResponseBody'
components:
  schemas:
    RotateServiceAccountApiKeyRequestBody:
      type: object
      properties:
        expiresAt:
          type: integer
          exclusiveMinimum: true
          minimum: 0
        gracePeriodMinutes:
          type: integer
          minimum: 0
          maximum: 10
          description: >-
            How long (0-10 minutes) the rotated-from key stays valid after
            rotation. Omit or 0 revokes it immediately. Rejected with a 400 if
            the key would expire before the grace window ends (the grace period
            never extends a key lifetime).
      additionalProperties: false
    RotateServiceAccountApiKey200ResponseBody:
      type: object
      properties:
        apiKey:
          type: object
          properties:
            id:
              type: string
              minLength: 1
              description: API key ID
            value:
              type: string
              minLength: 1
              description: One-time presentation key value, returned only on creation
            fingerprint:
              type: string
              minLength: 1
              description: Non-reversible suffix for display
            name:
              type: string
              minLength: 1
              description: Human-readable name for the key
            expiresAt:
              type: number
              description: Unix epoch milliseconds when the key expires, if set
          required:
            - id
            - value
            - fingerprint
            - name
          additionalProperties: false
      required:
        - apiKey
      additionalProperties: false
    RotateServiceAccountApiKey400ResponseBody:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message
        status:
          type: number
          description: HTTP status code
        title:
          type: string
          description: HTTP status title
        metadata:
          type: object
          additionalProperties: {}
          description: Additional error metadata
      required:
        - detail
        - status
        - title
      additionalProperties: false
    RotateServiceAccountApiKey401ResponseBody:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message
        status:
          type: number
          description: HTTP status code
        title:
          type: string
          description: HTTP status title
        metadata:
          type: object
          additionalProperties: {}
          description: Additional error metadata
      required:
        - detail
        - status
        - title
      additionalProperties: false
    RotateServiceAccountApiKey403ResponseBody:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message
        status:
          type: number
          description: HTTP status code
        title:
          type: string
          description: HTTP status title
        metadata:
          type: object
          additionalProperties: {}
          description: Additional error metadata
      required:
        - detail
        - status
        - title
      additionalProperties: false
    RotateServiceAccountApiKey404ResponseBody:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message
        status:
          type: number
          description: HTTP status code
        title:
          type: string
          description: HTTP status title
        metadata:
          type: object
          additionalProperties: {}
          description: Additional error metadata
      required:
        - detail
        - status
        - title
      additionalProperties: false
    RotateServiceAccountApiKey409ResponseBody:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message
        status:
          type: number
          description: HTTP status code
        title:
          type: string
          description: HTTP status title
        metadata:
          type: object
          additionalProperties: {}
          description: Additional error metadata
      required:
        - detail
        - status
        - title
      additionalProperties: false
    RotateServiceAccountApiKey500ResponseBody:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message
        status:
          type: number
          description: HTTP status code
        title:
          type: string
          description: HTTP status title
        metadata:
          type: object
          additionalProperties: {}
          description: Additional error metadata
      required:
        - detail
        - status
        - title
      additionalProperties: false
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Factory API key or JWT token for authentication

````