# Update a credit unit

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


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

Updates an existing credit unit.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/credit_units/ai_tokens_001 \
     -u {site_api_key}:\
     -d name="AI tokens" \
     -d external_name="AI Tokens"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = CreditUnit.Update("ai_tokens_001")
		.Name("AI tokens")
		.ExternalName("AI Tokens")
		.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"
    "github.com/chargebee/chargebee-go/v3/models/creditunit"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := creditunitAction.Update("ai_tokens_001", &creditunit.UpdateRequestParams{
        Name : "AI tokens",
        ExternalName : "AI Tokens",
    }).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.CreditUnitUpdateRequest{
    Name : "AI tokens",
    ExternalName : "AI Tokens",
}
  res, err := client.CreditUnit.Update("ai_tokens_001", 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.update("ai_tokens_001")
            .name("AI tokens")
            .externalName("AI Tokens")
            .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.CreditUnitUpdateParams;
import com.chargebee.v4.models.creditUnit.responses.CreditUnitUpdateResponse;

public class CreditUnitUpdate {

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

        CreditUnitUpdateParams params = CreditUnitUpdateParams.builder()
            .name("AI tokens")
            .externalName("AI Tokens")
            .build();

        CreditUnitUpdateResponse response = client
            .creditUnits()
            .update("ai_tokens_001", params);

        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.update("ai_tokens_001", {
        name: "AI tokens",
        external_name: "AI Tokens"
    });

    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()->update("ai_tokens_001", [
    "name" => "AI tokens",
    "external_name" => "AI Tokens"
]);
$creditUnit = $result->credit_unit;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.CreditUnit.update("ai_tokens_001",
    cb_client.CreditUnit.UpdateParams(
        name="AI tokens",
        external_name="AI Tokens"
    )
)
credit_unit = response.credit_unit
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::CreditUnit.update("ai_tokens_001",{
  :name => "AI tokens",
  :external_name => "AI Tokens"
})

credit_unit = result.credit_unit
```

## Sample Response

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

## URL Format

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

## Input Parameters

- `name` (optional, string, max chars=50)
  Updated internal display name for the credit unit. Must be unique across the site.

- `external_name` (optional, string, max chars=50)
  Updated customer-facing display name for the credit unit. Must be unique across the site. At least one of `name` or `external_name` should be provided. Only credit units with the `active` status can be updated.

## Returns

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