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

# Rotate spend key

> Rotate the raw secret for an existing spend key while preserving key settings and usage. The new raw key is returned once in the response. Requires a merchant secret key (aks_live_* / aks_test_*).



## OpenAPI

````yaml /openapi.json post /spend_keys/{id}/rotate
openapi: 3.0.0
info:
  title: Lava API
  description: >-
    Lava API enables businesses to implement usage-based billing for AI
    services. This API allows tracking, managing, and billing for third-party AI
    API usage through a forwarding system.
  version: 1.0.0
  contact:
    name: Lava support
    url: https://www.lava.so/contact
servers:
  - url: https://api.lava.so/v1/
    description: Lava API v1
security: []
tags:
  - name: Authentication
  - name: Core Endpoints
  - name: Models
  - name: Services
  - name: Requests
  - name: Wallet
  - name: Payment Methods
  - name: Spend Keys
  - name: Usage
  - name: Checkout Sessions
  - name: Customers
  - name: Plans
  - name: Subscriptions
  - name: Meters
  - name: Webhooks
  - name: Secret Keys
  - name: Credit Bundles
  - name: Gateway Settings
  - name: Skills
  - name: News Data
  - name: Search
  - name: Enrich
paths:
  /spend_keys/{id}/rotate:
    post:
      tags:
        - Spend Keys
      summary: Rotate spend key
      description: >-
        Rotate the raw secret for an existing spend key while preserving key
        settings and usage. The new raw key is returned once in the response.
        Requires a merchant secret key (aks_live_* / aks_test_*).
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: Spend key ID
      responses:
        '200':
          description: Spend key rotated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SpendKeyCreated'
        '404':
          description: Spend key not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Spend key was rotated concurrently; retry request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - Auth: []
components:
  schemas:
    SpendKeyCreated:
      allOf:
        - $ref: '#/components/schemas/SpendKey'
        - type: object
          properties:
            key:
              type: string
              description: The raw spend key (shown once)
          required:
            - key
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable error message describing what went wrong
              example: Invalid authentication credentials
            code:
              type: string
              description: Machine-readable error code describing what went wrong
              example: forward_token_json_invalid
            status:
              type: integer
              description: HTTP status code of the error
              example: 400
            issues:
              type: array
              items:
                type: object
                properties:
                  path:
                    type: array
                    items:
                      type: string
                    description: Path to the field that caused the validation error
                  message:
                    type: string
                    description: Error message describing the validation issue
                required:
                  - path
                  - message
              description: >-
                Optional array of specific validation issues with their paths
                and messages
              example:
                - path:
                    - model
                  message: 'Missing required field: model'
                - path:
                    - messages
                    - '0'
                    - content
                  message: Invalid message content format
          required:
            - message
            - code
            - status
      required:
        - error
    SpendKey:
      type: object
      properties:
        spend_key_id:
          type: string
        key_preview:
          type: string
          description: Masked key preview (e.g., lava_sk_a1b2c3d4****)
        name:
          type: string
        status:
          type: string
          enum:
            - active
            - paused
        request_shape:
          type: string
          enum:
            - openai
            - anthropic
          description: Request format this key accepts
        wallet_id:
          type: string
        allowed_models:
          type: array
          items:
            type: string
          nullable: true
        allowed_providers:
          type: array
          items:
            type: string
          nullable: true
        spend_limit:
          type: object
          nullable: true
          properties:
            amount:
              type: string
              description: Decimal amount in USD
            cycle:
              type: string
              enum:
                - daily
                - weekly
                - monthly
                - total
        current_spend:
          type: string
          description: Current spend in this cycle (decimal string)
        total_spend:
          type: string
          description: >-
            Total spend tracked for this key across completed/current cycles
            (decimal string)
        request_limit:
          type: object
          nullable: true
          properties:
            count:
              type: integer
              minimum: 1
              maximum: 10000000
            cycle:
              type: string
              enum:
                - daily
                - weekly
                - monthly
                - total
        current_requests:
          type: integer
          minimum: 0
          description: Current request count in this cycle
        total_requests:
          type: integer
          minimum: 0
          description: >-
            Total request count tracked for this key across completed/current
            cycles
        rate_limit:
          type: object
          nullable: true
          properties:
            rpm:
              type: integer
              minimum: 1
            burst:
              type: integer
              minimum: 1
              nullable: true
          required:
            - rpm
        expires_at:
          type: string
          format: date-time
          nullable: true
        last_used_at:
          type: string
          format: date-time
          nullable: true
        created_at:
          type: string
          format: date-time
      required:
        - spend_key_id
        - key_preview
        - name
        - status
        - request_shape
        - wallet_id
        - current_spend
        - total_spend
        - current_requests
        - total_requests
        - created_at
  securitySchemes:
    Auth:
      type: http
      scheme: bearer
      description: >-
        Bearer token authentication used for standard API calls. Format: 'Bearer
        YOUR_API_KEY'

````