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

# Rotate API key for service user

> Rotate an API key for a service user.

Creates a new key. By default revokes the old key; set revoke_current=false
for graceful rollover where both keys remain active temporarily.
Returns 404 if the key is not found, 400 if the key is not active, and 409
while static service user keys are disabled for the enterprise, unless the
service user backs SCIM or an active Outpost.

## Permissions

Requires a [service user](/api-reference/v3/service-users/members-service-users) or [personal access token](/api-reference/personal-access-tokens) with the `ManageAccountServiceUsers` permission at the enterprise level.


## OpenAPI

````yaml v3-openapi.yaml POST /v3beta1/enterprise/service-users/{service_user_id}/api-keys/{api_key_id}/rotate
openapi: 3.1.0
info:
  description: Devin v3 API with Service User authentication and RBAC
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3beta1/enterprise/service-users/{service_user_id}/api-keys/{api_key_id}/rotate:
    post:
      tags:
        - service_user_api_keys
      summary: Rotate API key for service user
      description: >-
        Rotate an API key for a service user.


        Creates a new key. By default revokes the old key; set
        revoke_current=false

        for graceful rollover where both keys remain active temporarily.

        Returns 404 if the key is not found, 400 if the key is not active, and
        409

        while static service user keys are disabled for the enterprise, unless
        the

        service user backs SCIM or an active Outpost.
      operationId: >-
        handle_rotate_service_user_api_key_v3beta1_enterprise_service_users__service_user_id__api_keys__api_key_id__rotate_post
      parameters:
        - description: 'Service user ID (prefix: service-user-)'
          in: path
          name: service_user_id
          required: true
          schema:
            example: service-user-abc123def456
            title: Service User Id
            type: string
        - in: path
          name: api_key_id
          required: true
          schema:
            title: Api Key Id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RotateApiKeyRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyWithTokenResponse'
          description: Successful Response
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Forbidden
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Not Found
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Conflict
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Unprocessable Content
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Too Many Requests
components:
  schemas:
    RotateApiKeyRequest:
      properties:
        new_key_expires_at:
          anyOf:
            - type: integer
            - type: 'null'
          description: >-
            Optional expiration for the new key as a UNIX timestamp in seconds.
            Null for no expiration.
          title: New Key Expires At
        revoke_current:
          default: true
          description: >-
            Whether to revoke the current key. Set to False for graceful
            rollover.
          title: Revoke Current
          type: boolean
      title: RotateApiKeyRequest
      type: object
    ApiKeyWithTokenResponse:
      description: >-
        Shared response model for API key creation/rotation (includes one-time
        token).
      properties:
        api_key_id:
          title: Api Key Id
          type: string
        api_key_name:
          title: Api Key Name
          type: string
        token:
          description: >-
            The raw API token. This is only shown once at creation/rotation
            time.
          title: Token
          type: string
      required:
        - api_key_id
        - api_key_name
        - token
      title: ApiKeyWithTokenResponse
      type: object
    ProblemDetail:
      description: >-
        RFC 9457 application/problem+json error body for the v3 API.


        detail is retained from the legacy {"detail": ...} body for back-compat;
        the

        other members are additive. errors carries field-level validation
        failures

        (422 only).
      properties:
        detail:
          anyOf:
            - type: string
            - type: 'null'
          description: A human-readable explanation specific to this occurrence.
          title: Detail
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Machine-readable code for blocked-action refusals (e.g.
            "user_frozen", "migrated_session").
          title: Error Code
        errors:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          description: Field-level validation errors (422 responses only).
          title: Errors
        instance:
          anyOf:
            - type: string
            - type: 'null'
          description: A URI reference (the request path) for this occurrence.
          title: Instance
        status:
          description: The HTTP status code.
          title: Status
          type: integer
        title:
          description: A short, human-readable summary of the problem type.
          title: Title
          type: string
        type:
          default: about:blank
          description: A URI reference identifying the problem type.
          title: Type
          type: string
      required:
        - title
        - status
      title: ProblemDetail
      type: object
  securitySchemes:
    bearerAuth:
      description: 'Service User credential (prefix: cog_)'
      scheme: bearer
      type: http

````

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