> This page is for version v2 (default).
> For other versions, use one of these documentation indexes:
> - v2 (default): https://docs.paid.ai/v-2/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.paid.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.paid.ai/_mcp/server.

# Delete a customer unit (by external customer id)

DELETE https://api.agentpaid.io/api/v2/customers/external/{externalId}/customer-units/{externalCustomerUnitId}

Soft-deletes a unit: it stays readable with `status: DELETED` and cannot be reactivated. Spend history that references it is kept, and signals that keep naming it are still attributed to it. `409` while the unit has ACTIVE children or a cap in force or scheduled; the root follows the same rules, and once it is deleted a new root can be created. Addresses the customer by your external customer id.

Reference: https://docs.paid.ai/api-reference/api-reference/customers/delete-customer-unit-by-external-id

## Authentication

- `Authorization` header (bearer token, required) — API Key authentication using Bearer token

## Request

### Path parameters

- `externalId` (string, required) — Customer ID from your system, stored on Paid as the customer's `externalId`.
- `externalCustomerUnitId` (string, required) — Your own id for the unit (its `externalId`), unique within this customer.

## Response

### 200

200

- `id` (string, required) — Paid's id for the unit (`cu_…`), unique within the organization and stable across renames of the customer. For reference only: no unit route accepts it, and routes and signals name a unit by its `externalId`.
- `externalId` (string, required) — Your own id for the unit, unique within the customer; the identifier every unit route takes.
- `customerId` (string, required, nullable) — Paid's id of the customer the unit belongs to (`cus_…`). `null` only for a legacy customer that has no Paid id; `customerExternalId` still names it.
- `customerExternalId` (string, required, nullable) — Your external id of that customer, when it has one.
- `name` (string, required) — Display name. Never used to address the unit.
- `externalType` (string, required, nullable) — Your structural vocabulary for the unit.
- `status` (enum, required) — ACTIVE, or DELETED after a soft delete (one-way).
  - Allowed values: `ACTIVE`, `DELETED`
- `parentExternalId` (string, required, nullable) — `externalId` of the parent unit; `null` only on the customer's root unit.
- `isRoot` (boolean, required) — Whether this unit is the customer's root: the one unit without a parent. Derived from the missing parent, not stored. At most one active root per customer; the root cannot be moved, and once deleted a new root can be created.
- `billable` (boolean, required) — The unit's own setting, as last created or updated: `false` marks it, and every unit under it, non-billable. Always `true` on the root. `effectiveBillable` says whether the unit is billable once its ancestors are counted. Usage on a non-billable unit is still recorded but not billed: it burns no credits, adds nothing to invoices or overage, and counts toward no cap, on a price whose usage comes from a meter (read from your events when the invoice closes) too. A meter's derived signal, and a correlation-window meter's window, follow the source event they take their unit from (the window's closing event, else its opening event): they are not billed when that event was not. Usage is still billed when it is sent with a customer API key, and on cost-plus pricing, which bills from costs that carry no unit. Only signals sent to `/api/v2/signals` that resolve to an active unit, by its key or through an alias on it, can be non-billable, and a change applies to signals received afterwards.
- `effectiveBillable` (boolean, required) — Read-only. Whether the unit is billable in effect: `false` when the unit or any unit above it has `billable: false`. A unit cannot make itself billable under a non-billable ancestor, and moving a unit under one makes it non-billable.
- `metadata` (map from string to any, required, nullable)
- `createdAt` (datetime, required)
- `updatedAt` (datetime, required)

## Errors

### 400 Bad Request Error

400

- `error` (string, required)
- `code` (string, optional)
- `details` (string, optional)

### 403 Forbidden Error

403

- `error` (string, required)
- `code` (string, optional)
- `details` (string, optional)

### 404 Not Found Error

404

- `error` (string, required)
- `code` (string, optional)
- `details` (string, optional)

### 409 Conflict Error

409

- `error` (string, required)
- `code` (string, optional)
- `details` (string, optional)

### 500 Internal Server Error

500

- `error` (string, required)
- `code` (string, optional)
- `details` (string, optional)

## Examples

**Response**

```json
{
  "id": "cu_7f3k2m9x",
  "externalId": "team-research",
  "customerId": "cus_abc123",
  "customerExternalId": "acme",
  "name": "Research team",
  "externalType": "string",
  "status": "ACTIVE",
  "parentExternalId": "dept-rnd",
  "isRoot": true,
  "billable": true,
  "effectiveBillable": true,
  "metadata": {},
  "createdAt": "2024-01-15T09:30:00Z",
  "updatedAt": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research"

headers = {"Authorization": "Bearer <token>"}

response = requests.delete(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research';
const options = {method: 'DELETE', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research"

	req, _ := http.NewRequest("DELETE", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.delete("https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('DELETE', 'https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research");
var request = new RestRequest(Method.DELETE);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/team-research")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "DELETE"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```