> 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
> - v1: https://docs.paid.ai/v-1/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.

# Get customer-unit cap (by external customer id)

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

Returns the cap in force on this customer unit for one credits currency, with usage in the current period when available. Select the currency with `creditsCurrencyId`; it may be omitted only when the organization has exactly one credits currency, which is then used and echoed back. `404` when the customer or the unit does not exist, or the unit has no cap in force for that currency. The usage figures are advisory: other spend may land between this read and the next burn. Addresses the customer by your external customer id.

Reference: https://docs.paid.ai/api-reference/api-reference/customers/get-customer-unit-cap-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.

### Query parameters

- `creditsCurrencyId` (string, optional) — The credits currency to read. Omit it only when the organization has exactly one credits currency, which is then used; otherwise it is required.

## Response

### 200

200

- `externalCustomerUnitId` (string, required) — Your own id for the unit (its `externalId`), the identifier the unit and cap routes take.
- `customerId` (string, required) — The Paid display id of the customer the unit belongs to.
- `creditsCurrencyId` (string, required) — The credits currency this response is about: the requested `creditsCurrencyId`, or the organization's only credits currency when it was omitted.
- `policy` (CustomerUnitCapPolicy, required) — The cap version in force now.
- `currentPeriod` (CustomerUnitCapCurrentPeriod, required) — Usage in the current period, when the returned version is in force now and usage is available; otherwise `null`.

## 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)

### 500 Internal Server Error

500

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

## Types

### CustomerUnitCapPolicy

The cap version in force now.

- `amount` (double, required) — The cap, in credits of the currency. JSON number; exact within ±2^53.
- `frequency` (enum, required) — Monthly UTC periods, with boundaries defined by `schedule`.
  - Allowed values: `MONTHLY`
- `schedule` (CustomerUnitCapSchedule, required) — Monthly UTC boundaries: an anchored day, or the first of each calendar month.
- `effectiveFrom` (datetime, required) — When this cap version started applying. The schedule independently defines its spend window.
- `effectiveUntil` (datetime, required, nullable) — When this cap version stopped applying (exclusive). `null` while it is open.
- `createdAt` (datetime, required) — When this cap version was set.
- `source` (string, required) — Where this cap version was set from.

### CustomerUnitCapCurrentPeriod

Usage in the current period, when the returned version is in force now and usage is available; otherwise `null`.

- `window` (CustomerUnitCapPeriod, required)
- `used` (double, required) — Credits of this currency spent by this unit and its descendants during the window. JSON number; exact within ±2^53.
- `remaining` (double, required) — `amount - used`; negative once the cap is exceeded. Advisory: spend may land between this read and the next burn.

### CustomerUnitCapSchedule

Monthly UTC boundaries: an anchored day, or the first of each calendar month.

### CustomerUnitCapPeriod

- `start` (datetime, required) — Inclusive start of the period, UTC.
- `end` (datetime, required) — Exclusive end of the period, UTC.

## Examples

**Response**

```json
{
  "externalCustomerUnitId": "tenant-a",
  "customerId": "cus_abc123",
  "creditsCurrencyId": "7f4f5d4c-55e9-4d5b-a3e7-c9eb3d2d01bf",
  "policy": {
    "amount": 10000,
    "frequency": "MONTHLY",
    "schedule": {
      "type": "ANCHORED",
      "anchorDay": 15
    },
    "effectiveFrom": "2024-01-15T09:30:00Z",
    "effectiveUntil": "2024-01-15T09:30:00Z",
    "createdAt": "2024-01-15T09:30:00Z",
    "source": "api"
  },
  "currentPeriod": {
    "window": {
      "start": "2024-01-15T09:30:00Z",
      "end": "2024-01-15T09:30:00Z"
    },
    "used": 1.1,
    "remaining": 1.1
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/tenant-a/cap"

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

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

print(response.json())
```

```javascript
const url = 'https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/tenant-a/cap';
const options = {method: 'GET', 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/tenant-a/cap"

	req, _ := http.NewRequest("GET", 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/tenant-a/cap")

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

request = Net::HTTP::Get.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.get("https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/tenant-a/cap")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.agentpaid.io/api/v2/customers/external/customer_123/customer-units/tenant-a/cap', [
  '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/tenant-a/cap");
var request = new RestRequest(Method.GET);
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/tenant-a/cap")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
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()
```