---
title: "Revoke Agent Api Key"
method: DELETE
path: "/api/agents/{agent_id}/api-key"
tags: ["agents"]
---

# Revoke Agent Api Key

`DELETE /api/agents/{agent_id}/api-key`

Soft-revoke the agent's active API key.

Idempotent: calling DELETE on an agent with no active key still
returns HTTP 200 with ``revoked=false``. This lets clients call
DELETE blindly without first getting it to check existence.

Args:
    agent_id: Path parameter.
    current_user: Resolved from JWT.
    db: SQLAlchemy session.

Returns:
    :class:`APIKeyRevokeResponse` with:
      - ``revoked=true, revoked_at=<now>`` if an active key was just revoked.
      - ``revoked=false, revoked_at=null`` if no active key existed.

Raises:
    HTTPException 401: missing or invalid JWT.
    HTTPException 404: agent missing / not owned.

Notes:
    Revoked rows stay in the table forever (we only flip ``revoked_at``).
    The audit trail of "when was a key created and when was it
    revoked" is the entire point of soft-delete here; hard-deleting
    would also lose the ability to answer "is this old hash one
    we issued?" during incident response.

## Path parameters

- `agent_id` integer, required

## Response `200`

Successful Response

- APIKeyRevokeResponse — Response model for ``DELETE /api/agents/{agent_id}/api-key``. The endpoint is idempotent and always returns HTTP 200 when the caller owns the agent. ``revoked`` distinguishes the two cases: - ``True``: there was an active key and this call flipped its ``revoked_at`` to now. - ``False``: no active key existed; the call was a safe no-op. ``revoked_at`` is ``None`` in this case.
  - `revoked` boolean, required — True if this call actually revoked an active key; False if no active key existed (idempotent no-op).
  - `revoked_at` string, date-time, nullable — Set to the UTC revocation timestamp when ``revoked`` is True; None when ``revoked`` is False.

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/xorbitsai/apis/xagent.md) · [All operations](https://skmtc.net/xorbitsai/apis/xagent/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/xorbitsai/xagent/versions/33e4ba4936ad/schema)
