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

# Delete Sub-account API Key

> Deletes the API key identified by its ID for the specified sub-account.




## OpenAPI

````yaml /email-api/api-reference/openapi.yaml delete /sub-account/{handle}/api-key/{id}
openapi: 3.0.0
info:
  contact:
    email: support@mailchannels.com
    name: MailChannels Corporation
  description: >
    This is the API reference for Email API. Here, you'll find more detailed
    information on every endpoint, including parameters, response formats, and
    error codes.
  title: Email API
  version: 1.4.0
servers:
  - url: https://api.mailchannels.net/tx/v1
security: []
tags:
  - name: Send
  - name: DKIM
  - name: Metrics
  - name: Sub-accounts
  - name: Suppression
  - name: Webhooks
  - name: Usage
  - name: Custom Tracking
paths:
  /sub-account/{handle}/api-key/{id}:
    delete:
      tags:
        - Sub-accounts
      summary: Delete Sub-account API Key
      description: |
        Deletes the API key identified by its ID for the specified sub-account.
      parameters:
        - description: |
            Handle of the sub-account for which the API key should be deleted.
          in: path
          name: handle
          required: true
          schema:
            type: string
        - description: The ID of the API key to delete.
          in: path
          name: id
          required: true
          schema:
            type: integer
        - in: header
          name: X-Api-Key
          required: true
          schema:
            type: string
      responses:
        '204':
          description: |
            The API key was successfully deleted for the sub-account.
        '400':
          description: |
            Missing or invalid API key ID.
        '500':
          description: |
            An unexpected internal error occurred.
      x-codeSamples:
        - label: Node.js
          lang: javascript
          source: >-
            import { MailChannels } from "mailchannels-sdk";


            const { PARENT_API_KEY, SUB_ACCOUNT_HANDLE, API_KEY_ID } =
            process.env;

            if (!PARENT_API_KEY) throw new Error("Set PARENT_API_KEY (a
            parent-account API key) before running");

            if (!SUB_ACCOUNT_HANDLE) throw new Error("Set SUB_ACCOUNT_HANDLE");

            if (!API_KEY_ID) throw new Error("Set API_KEY_ID (the ID of the key
            to delete)");


            const mailchannels = new MailChannels(PARENT_API_KEY);


            const { success, error } = await
            mailchannels.subAccounts.deleteApiKey(
              SUB_ACCOUNT_HANDLE,
              Number(API_KEY_ID),
            );


            if (!success) {
              console.error("Delete sub-account API key failed:", error);
              process.exit(1);
            }

            console.log(`Deleted API key ${API_KEY_ID} for sub-account
            ${SUB_ACCOUNT_HANDLE}`);
        - label: Python
          lang: python
          source: |-
            import os
            import sys

            import mailchannels

            parent_api_key = os.environ.get("PARENT_API_KEY")
            handle = os.environ.get("SUB_ACCOUNT_HANDLE")
            key_id = os.environ.get("API_KEY_ID")
            if not parent_api_key:
                sys.exit("Set PARENT_API_KEY (a parent-account API key) before running")
            if not handle:
                sys.exit("Set SUB_ACCOUNT_HANDLE")
            if not key_id:
                sys.exit("Set API_KEY_ID (the id of the key to delete)")

            mailchannels.api_key = parent_api_key

            response = mailchannels.SubAccounts.ApiKeys.delete(handle, key_id)

            print(response)
        - label: PHP
          lang: php
          source: >-
            <?php


            require_once __DIR__ . '/vendor/autoload.php';


            use MailChannels\Client;


            $parent_api_key     = getenv('PARENT_API_KEY') or exit("Error:
            PARENT_API_KEY is not set\n");

            $sub_account_handle = getenv('SUB_ACCOUNT_HANDLE') or exit("Error:
            SUB_ACCOUNT_HANDLE is not set\n");

            $api_key_id         = getenv('API_KEY_ID') or exit("Error:
            API_KEY_ID is not set\n");


            $client = new Client(apiKey: $parent_api_key);


            $response =
            $client->subAccounts->apiKeys->delete($sub_account_handle,
            $api_key_id);


            print_r($response->toArray());

````