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

# Update API Key

> Update the label or expiry of an API key.

Update an existing key's `name` or `expires_at`. Send only the fields you want
to change — you must include **at least one** of them, or the request is
rejected with `400`. The key's secret is never changed and is never returned, so
editing a label or expiry doesn't interrupt anything authenticating with the
key. A successful update returns `204 No Content`.

<RequestExample>
  ```bash cURL theme={null}
  curl -X PATCH https://api.byteport.com/v1/tokens/9b7e2c1a-4f3d-4a2b-8c1e-2d6f5a0b7c34 \
    -H "Authorization: Bearer $BYTEPORT_API_KEY" \
    -H "User-Agent: my-app/1.0" \
    -H "Content-Type: application/json" \
    -d '{
      "name":       "production-pipeline-v2",
      "expires_at": "2027-01-31T23:59:59Z"
    }'
  ```

  ```javascript JavaScript theme={null}
  const id = "9b7e2c1a-4f3d-4a2b-8c1e-2d6f5a0b7c34";
  await fetch(`https://api.byteport.com/v1/tokens/${id}`, {
    method: "PATCH",
    headers: {
      Authorization: `Bearer ${process.env.BYTEPORT_API_KEY}`,
      "User-Agent": "my-app/1.0",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ name: "production-pipeline-v2" }), // either field alone is fine
  });
  ```

  ```python Python theme={null}
  import os, requests

  key_id = "9b7e2c1a-4f3d-4a2b-8c1e-2d6f5a0b7c34"
  requests.patch(
      f"https://api.byteport.com/v1/tokens/{key_id}",
      headers={
          "Authorization": f"Bearer {os.environ['BYTEPORT_API_KEY']}",
          "User-Agent": "my-app/1.0",
      },
      json={"expires_at": "2027-01-31T23:59:59Z"},  # either field alone is fine
  )
  ```
</RequestExample>

<ResponseExample>
  ```text 204 No Content theme={null}
  (empty body)
  ```

  ```json 400 Bad Request theme={null}
  {
    "error": 400,
    "message": "at least one of name or expires_at is required"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml PATCH /v1/tokens/{id}
openapi: 3.1.0
info:
  title: Byteport API
  description: >-
    The Byteport API lets you move, share, and manage files across every storage
    location connected to your workspace through a single HTTP interface.
  version: 1.0.0
servers:
  - url: https://api.byteport.com
security:
  - bearerAuth: []
paths:
  /v1/tokens/{id}:
    patch:
      summary: Update API Key
      description: >-
        Update an existing key's label or expiry. Send only the fields you want
        to change; you must include **at least one** of `name` or `expires_at`
        (an empty body is rejected with `400`). The key's secret is unchanged
        and is never returned.
      parameters:
        - name: id
          in: path
          required: true
          description: Identifier of the API key to update (a UUID).
          schema:
            type: string
          example: 9b7e2c1a-4f3d-4a2b-8c1e-2d6f5a0b7c34
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              minProperties: 1
              description: Provide at least one of `name` or `expires_at`.
              properties:
                name:
                  type: string
                  description: >-
                    New label for the key. If supplied it must be non-empty
                    (`400` otherwise). Omit to leave the current label
                    unchanged.
                  example: production-pipeline-v2
                expires_at:
                  type: string
                  format: date-time
                  description: >-
                    New expiry timestamp (RFC 3339). Use this to extend,
                    shorten, or set an expiry on a previously non-expiring key.
                    Omit to leave the current expiry unchanged.
                  example: '2027-01-31T23:59:59Z'
      responses:
        '204':
          description: API key updated. The response body is empty.
        '400':
          $ref: '#/components/responses/Error'
        '401':
          $ref: '#/components/responses/Error'
        '404':
          $ref: '#/components/responses/Error'
components:
  responses:
    Error:
      description: Unexpected error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - error
        - message
      properties:
        error:
          type: integer
        message:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````