Use Autoclass

Overview

This page shows you how to enable, disable, and check the status of theAutoclass feature, which is set on a bucket in Cloud Storage.

Required roles

To get the permissions that you need to set and manage Autoclass on a bucket,ask your administrator to grant you the Storage Admin (roles/storage.admin)IAM role on the bucket. Thispredefined role containsthe permissions required to set and manage Autoclass on a bucket. To see theexact permissions that are required, expand theRequired permissionssection:

Required permissions

  • storage.buckets.get
  • storage.buckets.list
    • This permission is only required for using the Google Cloud consoleto perform the tasks on this page.
  • storage.buckets.update

You can also get these permissions withcustom roles.

For information about granting roles on buckets, seeSet and manage IAM policies on buckets.

Set Autoclass for a bucket

To set Autoclass for a bucket, complete the following instructions:

Console

Note: Autoclass can also be enabled in theChoose a default storage classfor your data when youcreate the bucket.
  1. In the Google Cloud console, go to the Cloud StorageBuckets page.

    Go to Buckets

  2. In the list of buckets, click the name of the desired bucket.

  3. In theBucket details page, click theConfiguration tab.

  4. Click theEdit icon()forDefault storage class.

  5. In the overlay window, selectAutoclass to enable Autoclass. Todisable Autoclass, selectSet a default class, and then select adefault storage class for the bucket.

  6. ClickConfirm.

  7. To switch the terminal storage class for a bucket that has Autoclassenabled, click theEdit icon()forIncluded classes, and clickConfirm in the overlay windowthat appears.

Command line

Note: Autoclass can also be enabled when youcreate the bucket, byusing the--enable-autoclass flag.

Use thegcloud storage buckets update command with theappropriate flags:

gcloud storage buckets update gs://BUCKET_NAME --default-storage-class=DEFAULT_CLASSAUTOCLASS_FLAG

Where:

  • BUCKET_NAME is the name of the relevantbucket. For example,my-bucket.

  • DEFAULT_CLASS sets the storage classmetadata for the bucket. When enabling Autoclass,STANDARD isthe only valid value and is required if the bucket currently usesa different storage class.

  • AUTOCLASS_FLAG is one of the following:

    • --enable-autoclass to enable Autoclass.
    • --no-enable-autoclass to disable Autoclass.
    • --autoclass-terminal-storage-class=CLASSto set the terminal storage class for Autoclass.CLASScan be eitherNEARLINE orARCHIVE. When using this flag on abucket with Autoclass disabled, also include the--enable-autoclassflag in the command.

If successful, the response looks similar to the following example:

Updating gs://my-bucket/...  Completed 1

Client libraries

C++

For more information, see theCloud StorageC++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

namespacegcs=::google::cloud::storage;[](gcs::Clientclient,std::stringconst&bucket_name,boolenabled){autometadata=client.PatchBucket(bucket_name,gcs::BucketMetadataPatchBuilder().SetAutoclass(gcs::BucketAutoclass{enabled}));if(!metadata)throwgoogle::cloud::Status(std::move(metadata).status());std::cout <<"The autoclass configuration for bucket " <<bucket_name            <<" was successfully updated.";if(!metadata->has_autoclass()){std::cout <<" The bucket no longer has an autoclass configuration.\n";return;}std::cout <<" The new configuration is " <<metadata->autoclass() <<"\n";}

C#

For more information, see theCloud StorageC# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

usingGoogle.Cloud.Storage.V1;usingGoogle.Apis.Storage.v1.Data;usingstaticGoogle.Apis.Storage.v1.Data.Bucket;usingSystem;publicclassSetAutoclassSample{publicBucketSetAutoclass(stringbucketName){varstorage=StorageClient.Create();varbucket=storage.GetBucket(bucketName);bucket.Autoclass=newAutoclassData{Enabled=true,TerminalStorageClass="ARCHIVE"};storage.PatchBucket(bucket);Console.WriteLine($"Autoclass enabled is set to {bucket.Autoclass.Enabled} for {bucketName} at {bucket.Autoclass.ToggleTimeDateTimeOffset}.");Console.WriteLine($"Autoclass terminal storage class is {bucket.Autoclass.TerminalStorageClass}.");returnbucket;}}

Go

For more information, see theCloud StorageGo API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""io""time""cloud.google.com/go/storage")// setAutoclass sets the Autoclass configuration for a bucket.funcsetAutoclass(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"// To update the configuration for Autoclass.TerminalStorageClass,// Autoclass.Enabled must also be set to true.// To disable autoclass on the bucket, set to an empty &Autoclass{}.enabled:=trueterminalStorageClass:="ARCHIVE"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()bucket:=client.Bucket(bucketName)bucketAttrsToUpdate:=storage.BucketAttrsToUpdate{Autoclass:&storage.Autoclass{Enabled:enabled,TerminalStorageClass:terminalStorageClass,},}if_,err:=bucket.Update(ctx,bucketAttrsToUpdate);err!=nil{returnfmt.Errorf("Bucket(%q).Update: %w",bucketName,err)}fmt.Fprintf(w,"Autoclass enabled was set to %v on bucket %q \n",bucketAttrsToUpdate.Autoclass.Enabled,bucketName)fmt.Fprintf(w,"Autoclass terminal storage class was last updated to %v at %v",bucketAttrsToUpdate.Autoclass.TerminalStorageClass,bucketAttrsToUpdate.Autoclass.TerminalStorageClassUpdateTime)returnnil}

Java

For more information, see theCloud StorageJava API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.storage.Bucket;importcom.google.cloud.storage.BucketInfo.Autoclass;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.Storage.BucketTargetOption;importcom.google.cloud.storage.StorageClass;importcom.google.cloud.storage.StorageOptions;publicclassSetBucketAutoclass{publicstaticvoidsetBucketAutoclass(StringprojectId,StringbucketName,StorageClassstorageClass)throwsException{// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";// The storage class that objects in an Autoclass bucket eventually transition to if not read// for a certain length of time// StorageClass storageClass = StorageClass.ARCHIVE;// Configure the Autoclass setting for a bucket.// Note:  terminal_storage_class field is optional and defaults to NEARLINE if not otherwise// specified. Valid terminal_storage_class values are NEARLINE and ARCHIVE.booleanenabled=true;try(Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService()){Bucketbucket=storage.get(bucketName);BuckettoUpdate=bucket.toBuilder().setAutoclass(Autoclass.newBuilder().setEnabled(enabled).setTerminalStorageClass(storageClass).build()).build();Bucketupdated=storage.update(toUpdate,BucketTargetOption.metagenerationMatch());System.out.println("Autoclass for bucket "+bucketName+" was "+(updated.getAutoclass().getEnabled()?"enabled.":"disabled."));System.out.println("Autoclass terminal storage class is "+updated.getAutoclass().getTerminalStorageClass().toString());}}}

Node.js

For more information, see theCloud StorageNode.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// The terminal storage class to be set on your GCS bucket. Valid values are NEARLINE and ARCHIVE.// const terminalStorageClass = 'NEARLINE';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctionsetAutoclass(){// Configure the Autoclass setting for a bucket.// terminalStorageClass field is optional and defaults to NEARLINE if not otherwise specified.// Valid terminalStorageClass values are NEARLINE and ARCHIVE.const[metadata]=awaitstorage.bucket(bucketName).setMetadata({autoclass:{enabled:toggle,terminalStorageClass,},});console.log(`Autoclass terminal storage class is${metadata.autoclass.terminalStorageClass}.`);}setAutoclass().catch(console.error);

PHP

For more information, see theCloud StoragePHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

use Google\Cloud\Storage\StorageClient;/** * Updates an existing bucket with provided autoclass config. * * @param string $bucketName The name of your Cloud Storage bucket (e.g. 'my-bucket'). * @param bool $autoclassStatus If true, enables Autoclass. Disables otherwise. * @param string $terminalStorageClass This field is optional and defaults to `NEARLINE`. *        Valid values are `NEARLINE` and `ARCHIVE`. */function set_bucket_autoclass(    string $bucketName,    bool $autoclassStatus,    string $terminalStorageClass): void {    $storage = new StorageClient();    $bucket = $storage->bucket($bucketName);    $bucket->update([        'autoclass' => [            'enabled' => $autoclassStatus,            'terminalStorageClass' => $terminalStorageClass        ],    ]);    $info = $bucket->info();    printf(        'Updated bucket %s with autoclass set to %s.' . PHP_EOL,        $info['name'],        $autoclassStatus ? 'true' : 'false'    );    printf(        'Autoclass terminal storage class is %s.' . PHP_EOL,        $info['autoclass']['terminalStorageClass']    );}

Python

For more information, see theCloud StoragePython API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

fromgoogle.cloudimportstoragedefset_autoclass(bucket_name):"""Configure the Autoclass setting for a bucket.    terminal_storage_class field is optional and defaults to NEARLINE if not otherwise specified.    Valid terminal_storage_class values are NEARLINE and ARCHIVE.    """# The ID of your GCS bucket# bucket_name = "my-bucket"# Enable Autoclass for a bucket. Set enabled to false to disable Autoclass.# Set Autoclass.TerminalStorageClass, valid values are NEARLINE and ARCHIVE.enabled=Trueterminal_storage_class="ARCHIVE"storage_client=storage.Client()bucket=storage_client.bucket(bucket_name)bucket.autoclass_enabled=enabledbucket.autoclass_terminal_storage_class=terminal_storage_classbucket.patch()print(f"Autoclass enabled is set to{bucket.autoclass_enabled} for{bucket.name} at{bucket.autoclass_toggle_time}.")print(f"Autoclass terminal storage class is{bucket.autoclass_terminal_storage_class}.")returnbucket

Ruby

For more information, see theCloud StorageRuby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

require"google/cloud/storage"### This is a snippet for showcasing how to set the autoclass# configuration of a bucket.## @param bucket_name [String] The ID of your GCS bucket (e.g. "your-unique-bucket-name")# @param toggle [Boolean] if true, enables Autoclass; if false, disables Autoclass#defset_autoclassbucket_name:,toggle:,terminal_storage_class:nil# Initialize clientstorage=Google::Cloud::Storage.new# Fetch the GCS bucketbucket=storage.bucketbucket_name# Update the autoclass configurationbucket.update_autoclass({enabled:toggle,terminal_storage_class:terminal_storage_class})terminal_class_update_time=bucket.autoclass_terminal_storage_class_update_time# Get autoclass config of the bucketputs"Bucket#{bucket.name} has autoclass config set to#{bucket.autoclass_enabled}."puts"Bucket#{bucket.name} has autoclass toggle time set to#{bucket.autoclass_toggle_time}."puts"Bucket#{bucket.name} has autoclass terminal storage class set to#{bucket.autoclass_terminal_storage_class}."puts"Bucket#{bucket.name} has autoclass terminal storage class update time set to#{terminal_class_update_time}."end

REST APIs

JSON API

Note: Autoclass can also be enabled when youcreate the bucket, byusing theautoclass property.
  1. Have gcloud CLIinstalled and initialized, which lets you generate an access token for theAuthorization header.

  2. Create a JSON file that contains the following information:

    {"storageClass":"DEFAULT_CLASS","autoclass":{"enabled":BOOLEAN,"terminalStorageClass":TERMINAL_CLASS}}

    Where:

  3. UsecURL to call the JSON API with aPATCH Bucket request:

    curl -X PATCH --data-binary @JSON_FILE_NAME \-H "Authorization: Bearer $(gcloud auth print-access-token)" \-H "Content-Type: application/json" \"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=autoclass"

    Where:

    • JSON_FILE_NAME is the path for the JSONfile that you created in Step 2.
    • BUCKET_NAME is the name of the relevantbucket. For example,my-bucket.

XML API

This feature cannot be managed through the XML API. Use theGoogle Cloud console or another tool instead.

View a bucket's Autoclass status

To view the Autoclass status for an individual bucket:

Console

  1. In the Google Cloud console, go to the Cloud StorageBuckets page.

    Go to Buckets

  2. Click the name of the bucket whose status you want to check.

  3. Click theConfiguration tab.

  4. The status for Autoclass is displayed in theDefault storage classfield.

    If Autoclass is enabled, the field readsManaged with Autoclass,and theIncluded classes field displays the storage classes thatobjects can transition between.

Command line

Use thegcloud storage buckets describe command with the--format flag:

gcloud storage buckets describe gs://BUCKET_NAME --format="default(autoclass)"

WhereBUCKET_NAME is the name of the bucketwhose status you want to view. For example,my-bucket.

If successful, the response looks similar to the following example:

autoclass:enabled:trueterminalStorageClass:ARCHIVEterminalStorageClassUpdateTime:'2023-02-10T16:11:02.384000+00:00'toggleTime:'2022-11-09T16:01:40.775000+00:00'

Client libraries

C++

For more information, see theCloud StorageC++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

namespacegcs=::google::cloud::storage;[](gcs::Clientclient,std::stringconst&bucket_name){autometadata=client.GetBucketMetadata(bucket_name);if(!metadata)throwgoogle::cloud::Status(std::move(metadata).status());if(!metadata->has_autoclass()){std::cout <<"The bucket " <<metadata->name() <<" does not have an"              <<" autoclass configuration.\n";return;}std::cout <<"Autoclass is "            <<(metadata->autoclass().enabled?"enabled":"disabled")            <<" for bucket " <<metadata->name() <<". "            <<" The bucket's full autoclass configuration is "            <<metadata->autoclass() <<"\n";}

C#

For more information, see theCloud StorageC# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

usingGoogle.Cloud.Storage.V1;usingSystem;usingstaticGoogle.Apis.Storage.v1.Data.Bucket;publicclassGetAutoclassSample{publicAutoclassDataGetAutoclass(stringbucketName){varstorage=StorageClient.Create();varbucket=storage.GetBucket(bucketName);Console.WriteLine($"Autoclass enabled is set to {bucket.Autoclass.Enabled} for {bucketName} at {bucket.Autoclass.ToggleTimeDateTimeOffset}.");Console.WriteLine($"Autoclass terminal storage class is set to {bucket.Autoclass.TerminalStorageClass} for {bucketName} at {bucket.Autoclass.TerminalStorageClassUpdateTimeDateTimeOffset}.");returnbucket.Autoclass;}}

Go

For more information, see theCloud StorageGo API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""io""time""cloud.google.com/go/storage")// getAutoclass gets the Autoclass configuration for a bucket.// See https://cloud.google.com/storage/docs/using-autoclass for more information.funcgetAutoclass(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()attrs,err:=client.Bucket(bucketName).Attrs(ctx)iferr!=nil{returnfmt.Errorf("Bucket(%q).Attrs: %w",bucketName,err)}fmt.Fprintf(w,"Autoclass enabled was set to %v on bucket %q at %v",attrs.Autoclass.Enabled,bucketName,attrs.Autoclass.ToggleTime)fmt.Fprintf(w,"Autoclass terminal storage class was last updated to %v at %v",attrs.Autoclass.TerminalStorageClass,attrs.Autoclass.TerminalStorageClassUpdateTime)returnnil}

Java

For more information, see theCloud StorageJava API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.storage.BucketInfo.Autoclass;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageClass;importcom.google.cloud.storage.StorageOptions;importjava.time.OffsetDateTime;publicclassGetBucketAutoclass{publicstaticvoidgetBucketAutoclass(StringprojectId,StringbucketName){// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();Autoclassautoclass=storage.get(bucketName).getAutoclass();Stringstatus=autoclass.getEnabled()?"enabled":"disabled";StringtoggleTime=autoclass.getToggleTime().toString();StorageClassterminalStorageClass=autoclass.getTerminalStorageClass();OffsetDateTimeterminalStorageClassUpdateTime=autoclass.getTerminalStorageClassUpdateTime();System.out.println("Autoclass is currently "+status+" for bucket "+bucketName+" and was last changed at "+toggleTime+". The terminal storage class is set to be "+terminalStorageClass.name()+" last updated at "+terminalStorageClassUpdateTime.toString());}}

Node.js

For more information, see theCloud StorageNode.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctiongetAutoclass(){const[metadata]=awaitstorage.bucket(bucketName).getMetadata();console.log(`Autoclass is${metadata.autoclass.enabled?'enabled':'disabled'} for${metadata.name} at${metadata.autoclass.toggleTime}. Autoclass terminal storage class is last updated to${metadata.autoclass.terminalStorageClass} at${metadata.autoclass.terminalStorageClassUpdateTime}.`);}getAutoclass().catch(console.error);

PHP

For more information, see theCloud StoragePHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

use Google\Cloud\Storage\StorageClient;/** * Print a bucket autoclass configuration. * * @param string $bucketName The name of your Cloud Storage bucket (e.g. 'my-bucket'). */function get_bucket_autoclass(string $bucketName): void{    $storage = new StorageClient();    $bucket = $storage->bucket($bucketName);    $info = $bucket->info();    if (isset($info['autoclass'])) {        printf('Bucket %s has autoclass enabled: %s' . PHP_EOL,            $bucketName,            $info['autoclass']['enabled']        );        printf('Bucket %s has autoclass toggle time: %s' . PHP_EOL,            $bucketName,            $info['autoclass']['toggleTime']        );        printf(            'Autoclass terminal storage class is set to %s for %s at %s.' . PHP_EOL,            $info['autoclass']['terminalStorageClass'],            $info['name'],            $info['autoclass']['terminalStorageClassUpdateTime'],        );    }}

Python

For more information, see theCloud StoragePython API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

fromgoogle.cloudimportstoragedefget_autoclass(bucket_name):"""Get the Autoclass setting for a bucket."""# The ID of your GCS bucket# bucket_name = "my-bucket"storage_client=storage.Client()bucket=storage_client.get_bucket(bucket_name)autoclass_enabled=bucket.autoclass_enabledautoclass_toggle_time=bucket.autoclass_toggle_timeterminal_storage_class=bucket.autoclass_terminal_storage_classtsc_update_time=bucket.autoclass_terminal_storage_class_update_timeprint(f"Autoclass enabled is set to{autoclass_enabled} for{bucket.name} at{autoclass_toggle_time}.")print(f"Autoclass terminal storage class is set to{terminal_storage_class} for{bucket.name} at{tsc_update_time}.")returnbucket

Ruby

For more information, see theCloud StorageRuby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

require"google/cloud/storage"### This is a snippet for showcasing how to access the autoclass# configuration of a bucket.## @param bucket_name [String] The ID of your GCS bucket (e.g. "your-unique-bucket-name")#defget_autoclassbucket_name:# Initialize clientstorage=Google::Cloud::Storage.new# Fetch the GCS bucketbucket=storage.bucketbucket_nameterminal_class_update_time=bucket.autoclass_terminal_storage_class_update_time# Get autoclass config of the bucketputs"Bucket#{bucket.name} has autoclass config set to#{bucket.autoclass_enabled}."puts"Bucket#{bucket.name} has autoclass toggle time set to#{bucket.autoclass_toggle_time}."puts"Bucket#{bucket.name} has autoclass terminal storage class set to#{bucket.autoclass_terminal_storage_class}."puts"Bucket#{bucket.name} has autoclass terminal storage class update time set to#{terminal_class_update_time}."end

REST APIs

JSON API

  1. Have gcloud CLIinstalled and initialized, which lets you generate an access token for theAuthorization header.

  2. UsecURL to call the JSON API with aGET Bucket request that includes theautoclass field:

    curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=autoclass"

    WhereBUCKET_NAME is the name of therelevant bucket. For example,my-bucket.

    If the bucket has Autoclass enabled, the response looks like thefollowing example:

    {"autoclass":{"enabled":"BOOLEAN","toggleTime":"DATETIME","terminalStorageClass":"STORAGE_CLASS","terminalStorageClassUpdateTime":"DATETIME"},}

XML API

This feature cannot be managed through the XML API. Use theGoogle Cloud console or another tool instead.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.