Method: projects.locations.cachedContents.delete

Deletes cached content

Endpoint

delete https://aiplatform.googleapis.com/v1beta1/{name}

Path parameters

name string

Required. The resource name referring to the cached content

Request body

The request body must be empty.

Example request

C#


using Google.Cloud.AIPlatform.V1Beta1;
using System;
using System.Threading.Tasks;

public class DeleteContextCache
{
    public async Task Delete(CachedContentName name)
    {
        var client = await new GenAiCacheServiceClientBuilder
        {
            Endpoint = "us-central1-aiplatform.googleapis.com"
        }.BuildAsync();

        await client.DeleteCachedContentAsync(name);
        Console.WriteLine($"Deleted cache: {name}");
    }
}

Go

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/vertexai/genai"
)

// deleteContextCache shows how to delete a cached content
// contentName is the ID of the cached content
func deleteContextCache(w io.Writer, contentName string, projectID, location string) error {
	// location := "us-central1"
	ctx := context.Background()

	client, err := genai.NewClient(ctx, projectID, location)
	if err != nil {
		return fmt.Errorf("unable to create client: %w", err)
	}
	defer client.Close()

	err = client.DeleteCachedContent(ctx, contentName)
	if err != nil {
		return fmt.Errorf("DeleteCachedContent: %w", err)
	}
	fmt.Fprintf(w, "Deleted cached content %q", contentName)
	return nil
}

Python

import vertexai

from vertexai.preview import caching

# TODO(developer): Update and un-comment below lines
# PROJECT_ID = "your-project-id"
# cache_id = "your-cache-id"

vertexai.init(project=PROJECT_ID, location="us-central1")

cached_content = caching.CachedContent(cached_content_name=cache_id)
cached_content.delete()

Response body

If successful, the response body is empty.