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

# Delete a Tunnel

> Deletes a tunnel. A tunnel that a route names as its next hop cannot be deleted; delete those routes first. Connected tunnel processes are disconnected and cannot reconnect with the tunnel's token.



## OpenAPI

````yaml /openapi/source/external/netapps/netapps.json delete /tunnels/{id}
openapi: 3.1.0
info:
  version: 2.0.0
  title: Telnyx API
  x-latency-category: responsive
  x-endpoint-cost: light
  description: SIP trunking, SMS, MMS, Call Control and Telephony Data Services.
  license:
    name: MIT
    identifier: MIT
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
    description: Version 2.0.0 of the Telnyx API
security:
  - bearerAuth: []
tags:
  - name: Networks
    description: Network operations
  - name: Public Internet Gateways
    description: Public Internet Gateway operations
  - name: WireGuard Interfaces
    description: WireGuard Interface operations
  - name: Tunnels
    description: >-
      Tunnels connect a Network to hosts behind a tunnel process within the
      user's network.
  - name: Network Routes
    description: Routes on a Network that send a CIDR to a next hop, such as a tunnel.
  - name: Tailscale Subnet Routers
    description: Tailscale Subnet Router operations
  - name: Virtual Cross Connects
    description: Virtual Cross Connect operations
  - name: Regions
    description: Regions
  - name: Global IPs
    description: Global IPs
paths:
  /tunnels/{id}:
    delete:
      tags:
        - Tunnels
      summary: Delete a Tunnel
      description: >-
        Deletes a tunnel. A tunnel that a route names as its next hop cannot be
        deleted; delete those routes first. Connected tunnel processes are
        disconnected and cannot reconnect with the tunnel's token.
      operationId: DeleteTunnel
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the tunnel.
          schema:
            type: string
            format: uuid
            example: 62d438d2-8a51-4c5e-9d0c-1f6b2a7e4c39
      responses:
        '204':
          description: Deleted.
        '404':
          description: 'Not found: no tunnel with this id exists on the account.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              example:
                errors:
                  - code: '10020'
                    title: Resource not found
                    detail: 'get tunnel: not found'
        '409':
          description: >-
            Conflict: one or more routes name the tunnel as their next hop.
            `detail` and `meta.route_ids` list them.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              example:
                errors:
                  - code: '10021'
                    title: Resource conflict
                    detail: >-
                      tunnel 62d438d2-8a51-4c5e-9d0c-1f6b2a7e4c39 is the next
                      hop of 1 route; delete it first:
                      e8a2c5d0-3f7b-4a19-b6d2-9c1e0f8a7b53
                    meta:
                      route_ids:
                        - e8a2c5d0-3f7b-4a19-b6d2-9c1e0f8a7b53
        default:
          $ref: '#/components/responses/GenericErrorResponse'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Telnyx from 'telnyx';

            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });

            await client.tunnels.delete('id');
        - lang: Python
          source: |
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            client.tunnels.delete(
                "id",
            )
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\terr := client.Tunnels.Delete(\n\t\tcontext.TODO(),\n\t\t\"id\",\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n}\n"
        - lang: Java
          source: |-
            package com.telnyx.sdk.example;

            import com.telnyx.sdk.client.TelnyxClient;
            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    client.tunnels().delete("id");
                }
            }
        - lang: Ruby
          source: |-
            require "telnyx"

            telnyx = Telnyx::Client.new(api_key: "My API Key")

            response = telnyx.tunnels.delete("id")

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


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $response = $client->tunnels->delete(
                'id',
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx tunnels delete \
              --api-key 'My API Key' \
              --id 62d438d2-8a51-4c5e-9d0c-1f6b2a7e4c39
components:
  schemas:
    Errors:
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Error'
      type: object
    Error:
      required:
        - code
        - title
      properties:
        code:
          type: string
        title:
          type: string
        detail:
          type: string
        source:
          type: object
          properties:
            pointer:
              description: JSON pointer (RFC6901) to the offending entity.
              type: string
            parameter:
              description: Indicates which query parameter caused the error.
              type: string
        meta:
          type: object
          additionalProperties: true
      type: object
  responses:
    GenericErrorResponse:
      description: Unexpected error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Errors'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````