# Billing

Billing and usage information

Source: https://keyenv.dev/docs/api/billing/

Billing and usage information

## Get team usage

```http
GET /api/v1/teams/{teamId}/usage
```

Returns current usage statistics for a team

**Operation ID:** `getTeamUsage` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Usage statistics | `UsageStats` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `projects` | `integer` |  |
| `environments` | `integer` |  |
| `secrets` | `integer` |  |
| `members` | `integer` |  |

### Example

```bash
curl -X GET "https://api.keyenv.dev/api/v1/teams/{teamId}/usage" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```

## Get team limits

```http
GET /api/v1/teams/{teamId}/limits
```

Returns plan limits for a team

**Operation ID:** `getTeamLimits` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Plan limits | `PlanLimits` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `plan` | `enum (free, team, enterprise)` |  |
| `projects` | `integer` | Maximum number of projects (-1 for unlimited) |
| `environments_per_project` | `integer` |  |
| `secrets_per_environment` | `integer` |  |
| `members` | `integer` |  |

### Example

```bash
curl -X GET "https://api.keyenv.dev/api/v1/teams/{teamId}/limits" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```

## Get billing info

```http
GET /api/v1/teams/{teamId}/billing
```

Returns billing information including current plan and subscription status

**Operation ID:** `getTeamBilling` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Billing information | `BillingInfo` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `plan` | `enum (free, team, enterprise)` |  |
| `status` | `enum (active, canceled, past_due, trialing)` |  |
| `current_period_end` | `string (date-time)` |  |
| `cancel_at_period_end` | `boolean` |  |

### Example

```bash
curl -X GET "https://api.keyenv.dev/api/v1/teams/{teamId}/billing" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```

## Create checkout session

```http
POST /api/v1/teams/{teamId}/checkout
```

Creates a Stripe checkout session for upgrading the team's plan

**Operation ID:** `createCheckoutSession` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Request body

`application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `plan` | `enum (team, enterprise)` | yes |  |
| `success_url` | `string (uri)` | no |  |
| `cancel_url` | `string (uri)` | no |  |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Checkout session created | `object` |
| `400` | Invalid request | `Error` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `url` | `string (uri)` | URL to redirect the user to for checkout |

### Example

```bash
curl -X POST "https://api.keyenv.dev/api/v1/teams/{teamId}/checkout" \
  -H "Authorization: Bearer $KEYENV_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"plan":"team","success_url":"string","cancel_url":"string"}'
```

## Create billing portal session

```http
POST /api/v1/teams/{teamId}/portal
```

Creates a Stripe billing portal session for managing subscription

**Operation ID:** `createPortalSession` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Portal session created | `object` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `url` | `string (uri)` | URL to redirect the user to for the billing portal |

### Example

```bash
curl -X POST "https://api.keyenv.dev/api/v1/teams/{teamId}/portal" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```
