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

# Update an API key

> Changes the name, expiry, spending limit or active flag of an API key. Fields left out are unchanged.



## OpenAPI

````yaml /api-reference/cloud-platform-openapi.json patch /v1/workspaces/{workspace_id}/api-keys/{key_id}
openapi: 3.1.0
info:
  description: Account, organization, workspace and billing routes of NEAR AI Cloud.
  title: NEAR AI Cloud Platform API
  version: '5'
servers:
  - url: https://cloud-platform.near.ai
    description: NEAR AI Cloud Platform
security: []
paths:
  /v1/workspaces/{workspace_id}/api-keys/{key_id}:
    patch:
      tags:
        - API keys
      summary: Update an API key
      description: >-
        Changes the name, expiry, spending limit or active flag of an API key.
        Fields left out are unchanged.
      operationId: update_api_key
      parameters:
        - description: The workspace id (a UUID).
          in: path
          name: workspace_id
          required: true
          schema:
            type: string
        - description: The API key id (a UUID).
          in: path
          name: key_id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateApiKeyRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyResponse'
          description: The updated key.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: The request is invalid.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Missing or invalid credential.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: The caller is not allowed to do this.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: The resource does not exist.
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: The request conflicts with existing data.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Internal error.
      security:
        - session: []
components:
  schemas:
    UpdateApiKeyRequest:
      description: >-
        Request to update an API key. Every field is optional; omitted fields
        are unchanged.
      properties:
        expires_at:
          description: New expiry time.
          format: date-time
          type:
            - string
            - 'null'
        is_active:
          description: Set false to disable the key, true to enable it.
          type:
            - boolean
            - 'null'
        name:
          description: New name, 1 to 255 characters.
          type:
            - string
            - 'null'
        spendLimit:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/DecimalPriceRequest'
              description: New spending limit.
      type: object
    ApiKeyResponse:
      description: An API key.
      properties:
        created_at:
          format: date-time
          type: string
        created_by_user_id:
          description: The user who created the key.
          type: string
        deleted_at:
          format: date-time
          type:
            - string
            - 'null'
        expires_at:
          description: When the key stops working, if it expires.
          format: date-time
          type:
            - string
            - 'null'
        id:
          description: The key's id (a UUID).
          type: string
        is_active:
          description: Whether the key can be used.
          type: boolean
        key:
          description: >-
            The full secret key, beginning with `sk-`. It is returned only in
            the response that

            creates the key and cannot be retrieved again; store it securely.
          type:
            - string
            - 'null'
        key_prefix:
          description: The first characters of the key, for recognizing it.
          type: string
        last_used_at:
          description: When the key was last used, if ever.
          format: date-time
          type:
            - string
            - 'null'
        name:
          description: The key's name.
          type:
            - string
            - 'null'
        spend_limit:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/DecimalPrice'
              description: The spending limit, if one is set.
        usage:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/DecimalPrice'
              description: Spend so far, where reported.
        workspace_id:
          description: The workspace the key belongs to.
          type: string
      required:
        - id
        - key_prefix
        - workspace_id
        - created_by_user_id
        - created_at
        - is_active
      type: object
    ErrorResponse:
      description: The body of every error answer on the user routes.
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      required:
        - error
      type: object
    DecimalPriceRequest:
      description: 'A price in the request: nano-dollars, scale 9.'
      properties:
        amount:
          description: >-
            Amount in nano-dollars (scale 9). For example, $1.00 = 1000000000
            nano-dollars.
          format: int64
          type: integer
        currency:
          description: Currency code, for example `USD`.
          type: string
      required:
        - amount
        - currency
      type: object
    DecimalPrice:
      description: A price in a response.
      properties:
        amount:
          description: The amount in units of 10^-`scale` of the currency.
          format: int64
          type: integer
        currency:
          description: Currency code, for example `USD`.
          type: string
        scale:
          description: Number of decimal places in `amount`; 9 means nano-dollars.
          format: int64
          type: integer
      required:
        - amount
        - scale
        - currency
      type: object
    ErrorDetail:
      properties:
        code:
          type:
            - string
            - 'null'
        message:
          type: string
        param:
          type:
            - string
            - 'null'
        type:
          type: string
      required:
        - message
        - type
      type: object
  securitySchemes:
    session:
      bearerFormat: Session token
      description: 'Session token from signing in, sent as `Authorization: Bearer <token>`.'
      scheme: bearer
      type: http

````

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