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

# Delete and Revoke an API Key

> Permanently revoke and delete an AgriBackup enterprise API key by ID. All requests using the deleted key will immediately fail with 401.

Use this endpoint to permanently revoke an API key that is no longer needed or that you suspect has been compromised. Once deleted, any request that includes the revoked key in its `Authorization` header will immediately receive a `401 Unauthorized` response — there is no grace period. This action is irreversible; if you need a replacement key with the same configuration, use the [Rotate Key](/sdks/enterprise-api-keys/rotate-an-api-key) endpoint instead, which deactivates the old key and issues a new one atomically.

**`DELETE /api/v1/enterprise/api-keys/{keyId}`**

## Path Parameters

<ParamField path="keyId" type="string" required>
  The unique identifier of the API key to permanently delete. Retrieve this value from the `id` field returned by the [List API Keys](/sdks/enterprise-api-keys/list-api-keys) or [Generate API Key](/sdks/enterprise-api-keys/generate-a-new-api-key) endpoints.

  **Example:** `key_a1b2c3d4e5f6`
</ParamField>

## Code Examples

<CodeGroup>
  ```python Python theme={null}
  import agribackup
  from agribackup.rest import ApiException

  configuration = agribackup.Configuration(host="https://live.agribackup.com/api/v1")
  configuration.api_key["ApiKeyAuth"] = "sk_live_YOUR_API_KEY"

  key_id = "key_a1b2c3d4e5f6"

  with agribackup.ApiClient(configuration) as api_client:
      try:
          api_instance = agribackup.EnterpriseAPIKeysApi(api_client)
          api_instance.delete_api_key(key_id=key_id)
          print(f"Key {key_id} has been permanently revoked.")
      except ApiException as e:
          print("Exception when calling API: %s\n" % e)
  ```

  ```javascript Node.js theme={null}
  import { AgriBackupClient } from "@agribackup/sdk";

  const client = new AgriBackupClient({
    apiKey: "sk_live_YOUR_API_KEY",
    baseUrl: "https://live.agribackup.com/api/v1",
  });

  async function deleteApiKey(keyId) {
    try {
      await client.keys.deleteApiKey(keyId);
      console.log(`Key ${keyId} has been permanently revoked.`);
    } catch (error) {
      console.error(error);
    }
  }

  deleteApiKey("key_a1b2c3d4e5f6");
  ```

  ```bash cURL theme={null}
  curl --request DELETE \
    --url https://live.agribackup.com/api/v1/enterprise/api-keys/key_a1b2c3d4e5f6 \
    --header "Authorization: Bearer sk_live_YOUR_API_KEY"
  ```
</CodeGroup>

## Response

A `200 OK` response confirms the key has been permanently revoked and deleted.

## Error Responses

| HTTP Status             | Error Code     | Description                                                                                             |
| ----------------------- | -------------- | ------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`      | `UNAUTHORIZED` | The `Authorization` header is absent or the bearer token is invalid.                                    |
| `403 Forbidden`         | `FORBIDDEN`    | The authenticated identity does not have permission to delete API keys for this organization.           |
| `404 Not Found`         | `NOT_FOUND`    | No API key with the provided `keyId` exists for this organization, or the key has already been deleted. |
| `429 Too Many Requests` | `RATE_LIMITED` | You have exceeded the hourly rate limit. Check `X-RateLimit-Reset` for your reset time.                 |

```json theme={null}
{
  "code": "NOT_FOUND",
  "message": "API key not found",
  "details": [
    {
      "code": "KEY_NOT_FOUND",
      "field": "keyId",
      "issue": "No active API key with ID 'key_a1b2c3d4e5f6' exists for this organization"
    }
  ]
}
```
