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

# Update a credential

> Replace the payload of an existing credential.

Args:
    credential_id (`str`): The credential to update.
    body (`UpdateCredentialRequest`): New credential payload.
    user_id (`str`): Injected authenticated user ID.
    storage (`StorageBase`): Injected storage backend.

Returns:
    `CredentialRecord`: The updated credential record.

Raises:
    `HTTPException`: 404 if the credential does not exist or does not
        belong to the authenticated user.



## OpenAPI

````yaml /versions/2.0.2/en/deploy/openapi.json patch /credential/{credential_id}
openapi: 3.1.0
info:
  title: AgentScope
  version: 2.0.1
servers: []
security: []
paths:
  /credential/{credential_id}:
    patch:
      tags:
        - credential
      summary: Update a credential
      description: |-
        Replace the payload of an existing credential.

        Args:
            credential_id (`str`): The credential to update.
            body (`UpdateCredentialRequest`): New credential payload.
            user_id (`str`): Injected authenticated user ID.
            storage (`StorageBase`): Injected storage backend.

        Returns:
            `CredentialRecord`: The updated credential record.

        Raises:
            `HTTPException`: 404 if the credential does not exist or does not
                belong to the authenticated user.
      operationId: update_credential_credential__credential_id__patch
      parameters:
        - name: credential_id
          in: path
          required: true
          schema:
            type: string
            title: Credential Id
        - name: x-user-id
          in: header
          required: true
          schema:
            type: string
            description: >-
              Caller's user ID. Temporary header-based identity; will be
              replaced by JWT auth.
            title: X-User-Id
          description: >-
            Caller's user ID. Temporary header-based identity; will be replaced
            by JWT auth.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCredentialRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CredentialRecord'
        '404':
          description: Not found
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    UpdateCredentialRequest:
      properties:
        data:
          additionalProperties: true
          type: object
          title: Data
          description: New credential payload.
      type: object
      required:
        - data
      title: UpdateCredentialRequest
      description: Request body for updating an existing credential.
    CredentialRecord:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the credential.
        updated_at:
          type: string
          format: date-time
          title: Updated At
        created_at:
          type: string
          format: date-time
          title: Created At
        user_id:
          type: string
          title: User Id
        data:
          additionalProperties: true
          type: object
          title: Data
      type: object
      required:
        - data
      title: CredentialRecord
      description: The credential model used for storing credentials.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````