# Archive a credit unit

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Archives an `active` credit unit. Once archived, the credit unit can no longer be used to create grant configurations for items and grant configuration overrides for subscriptions. Any grants that were already configured for this credit unit will continue to be effective.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/credit_units/ai_tokens_001/archive_command \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = CreditUnit.Archive("ai_tokens_001").Request();

CreditUnit creditUnit = result.CreditUnit;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    creditunitAction "github.com/chargebee/chargebee-go/v3/actions/creditunit"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := creditunitAction.Archive("ai_tokens_001").Request()
    if err != nil {
        fmt.Println(err)
    } else {
        CreditUnit := res.CreditUnit
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.CreditUnitArchiveRequest{
    Id : "ai_tokens_001",
}
  res, err := client.CreditUnit.Archive(req)
      if err != nil {
        fmt.Println(err)
    } else {
        CreditUnit := res.CreditUnit
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = CreditUnit.archive("ai_tokens_001").request();

        CreditUnit creditUnit = result.creditUnit();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditUnit.CreditUnit;
import com.chargebee.v4.models.creditUnit.params.CreditUnitArchiveParams;
import com.chargebee.v4.models.creditUnit.responses.CreditUnitArchiveResponse;

public class CreditUnitArchive {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        CreditUnitArchiveResponse response = client.creditUnits().archive("ai_tokens_001");

        CreditUnit creditUnit = response.getCreditUnit();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.creditUnit.archive("ai_tokens_001");

    console.log(result);
    const creditUnit = result.credit_unit;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

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

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->creditUnit()->archive("ai_tokens_001");
$creditUnit = $result->credit_unit;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.CreditUnit.archive("ai_tokens_001")
credit_unit = response.credit_unit
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::CreditUnit.archive("ai_tokens_001")

credit_unit = result.credit_unit
```

## Sample Response

```json
{
  "credit_unit": {
    "id": "ai_tokens_001",
    "name": "AI tokens",
    "external_name": "AI tokens",
    "status": "archived",
    "resource_version": 1784633655000,
    "is_unlimited": false,
    "overdraft_amount": "1000",
    "created_at": 1784633586,
    "created_by": "sample.user@chargebee.com",
    "updated_at": 1784633655,
    "updated_by": "sample.user@chargebee.com"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/credit_units/{credit-unit-id}/archive_command

## Returns

- `credit_unit` (Credit unit object)
  Resource object representing credit unit
