A partire dal 29 aprile 2025, i modelli Gemini 1.5 Pro e Gemini 1.5 Flash non sono disponibili nei progetti che non li hanno mai utilizzati, inclusi i nuovi progetti. Per maggiori dettagli, vedi Versioni e ciclo di vita dei modelli.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Per eliminare una cache del contesto, devi disporre del relativo ID, dell'ID progetto Google Cloud a cui è associata la cache del contesto e della regione in cui è stata elaborata la richiesta dicreazione della cache del contesto. L'ID cache di una cache di contesto viene restituito quando crei la cache di contesto. Puoi anche ottenere l'ID cache di ogni cache di contesto associata
a un progetto utilizzando il
comando list cache di contesto.
Elimina esempio di cache del contesto
L'esempio seguente mostra come eliminare una cache del contesto.
Imposta le variabili di ambiente per utilizzare l'SDK Gen AI con Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values# with appropriate values for your project.exportGOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECTexportGOOGLE_CLOUD_LOCATION=us-central1exportGOOGLE_GENAI_USE_VERTEXAI=True
fromgoogleimportgenaiclient=genai.Client()# Delete content cache using name# E.g cache_name = 'projects/111111111111/locations/us-central1/cachedContents/1111111111111111111'client.caches.delete(name=cache_name)print("Deleted Cache",cache_name)# Example response# Deleted Cache projects/111111111111/locations/us-central1/cachedContents/1111111111111111111
Imposta le variabili di ambiente per utilizzare l'SDK Gen AI con Vertex AI:
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values# with appropriate values for your project.exportGOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECTexportGOOGLE_CLOUD_LOCATION=us-central1exportGOOGLE_GENAI_USE_VERTEXAI=True
import("context""fmt""io"genai"google.golang.org/genai")//deleteContentCacheshowshowtodeletecontentcache.funcdeleteContentCache(wio.Writer,cacheNamestring)error{ctx:=context.Background()client,err:=genai.NewClient(ctx, &genai.ClientConfig{HTTPOptions:genai.HTTPOptions{APIVersion:"v1"},})iferr!=nil{returnfmt.Errorf("failed to create genai client: %w",err)}_,err=client.Caches.Delete(ctx,cacheName, &genai.DeleteCachedContentConfig{})iferr!=nil{returnfmt.Errorf("failed to delete content cache: %w",err)}fmt.Fprintf(w,"Deleted cache %q\n",cacheName)//Exampleresponse://Deletedcache"projects/111111111111/locations/us-central1/cachedContents/1111111111111111111"returnnil}
REST
Di seguito viene mostrato come utilizzare REST per eliminare una cache del contesto associata a un progetto Google Cloud inviando una richiesta DELETE all'endpoint del modello del publisher.
Prima di utilizzare i dati della richiesta,
apporta le seguenti sostituzioni:
LOCATION: la regione in cui è stata elaborata la richiesta di
creazione della cache contestuale
e in cui è archiviato il contenuto memorizzato nella cache.
CACHE_ID: l'ID della cache del contesto da eliminare. L'ID cache del contesto viene restituito quando
crei la cache del contesto. Puoi anche trovare gli ID cache contestuale elencando le cache contestuali per un progetto Google Cloud utilizzando. Per ulteriori informazioni, vedi
Creare una cache contestuale e
Elencare le cache contestuali.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Delete a context cache\n\nTo delete a context cache, you need its cache ID, the Google Cloud project ID with\nwhich the context cache is associated, and the region where the request to\n[create the context cache](/vertex-ai/generative-ai/docs/context-cache/context-cache-create)\nwas processed. The cache ID of a context cache is returned when you create the\ncontext cache. You can also get the cache ID of each context cache associated\nwith a project using the\n[context cache list command](/vertex-ai/generative-ai/docs/context-cache/context-cache-getinfo#get-context-cache-list).\n\nDelete context cache example\n----------------------------\n\nThe following example shows you how to delete a context cache. \n\n### Python\n\n#### Install\n\n```\npip install --upgrade google-genai\n```\n\n\nTo learn more, see the\n[SDK reference documentation](https://googleapis.github.io/python-genai/).\n\n\nSet environment variables to use the Gen AI SDK with Vertex AI:\n\n```bash\n# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values\n# with appropriate values for your project.\nexport GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT\nexport GOOGLE_CLOUD_LOCATION=us-central1\nexport GOOGLE_GENAI_USE_VERTEXAI=True\n```\n\n\u003cbr /\u003e\n\n from google import genai\n\n client = genai.Client()\n # Delete content cache using name\n # E.g cache_name = 'projects/111111111111/locations/us-central1/cachedContents/1111111111111111111'\n client.caches.delete(name=cache_name)\n print(\"Deleted Cache\", cache_name)\n # Example response\n # Deleted Cache projects/111111111111/locations/us-central1/cachedContents/1111111111111111111\n\n### Go\n\nLearn how to install or update the [Go](/vertex-ai/generative-ai/docs/sdks/overview).\n\n\nTo learn more, see the\n[SDK reference documentation](https://pkg.go.dev/google.golang.org/genai).\n\n\nSet environment variables to use the Gen AI SDK with Vertex AI:\n\n```bash\n# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values\n# with appropriate values for your project.\nexport GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT\nexport GOOGLE_CLOUD_LOCATION=us-central1\nexport GOOGLE_GENAI_USE_VERTEXAI=True\n```\n\n\u003cbr /\u003e\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tgenai \"google.golang.org/genai\"\n )\n\n // deleteContentCache shows how to delete content cache.\n func deleteContentCache(w io.Writer, cacheName string) error {\n \tctx := context.Background()\n\n \tclient, err := genai.NewClient(ctx, &genai.ClientConfig{\n \t\tHTTPOptions: genai.HTTPOptions{APIVersion: \"v1\"},\n \t})\n \tif err != nil {\n \t\treturn fmt.Errorf(\"failed to create genai client: %w\", err)\n \t}\n\n \t_, err = client.Caches.Delete(ctx, cacheName, &genai.DeleteCachedContentConfig{})\n \tif err != nil {\n \t\treturn fmt.Errorf(\"failed to delete content cache: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Deleted cache %q\\n\", cacheName)\n\n \t// Example response:\n \t// Deleted cache \"projects/111111111111/locations/us-central1/cachedContents/1111111111111111111\"\n\n \treturn nil\n }\n\n### REST\n\n\nThe following shows how to use REST to delete a context cache associated with\na Google Cloud project by sending a DELETE request to the publisher model endpoint.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar class=\"edit\" scope=\"PROJECT_ID\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your [project ID](/resource-manager/docs/creating-managing-projects#identifiers).\n- \u003cvar class=\"edit\" scope=\"LOCATION\" translate=\"no\"\u003eLOCATION\u003c/var\u003e: The region where the request to [create the context cache](/vertex-ai/generative-ai/docs/context-cache/context-cache-create) was processed and where the cached content is stored.\n- \u003cvar class=\"edit\" scope=\"CACHE_ID\" translate=\"no\"\u003eCACHE_ID\u003c/var\u003e: The ID of the context cache to delete. The context cache ID is returned when you create the context cache. You can also find context cache IDs by listing the context caches for a Google Cloud project using. For more information, see [create a context cache](/vertex-ai/generative-ai/docs/context-cache/context-cache-create) and [list context caches](/vertex-ai/generative-ai/docs/context-cache/context-cache-getinfo#get-context-cache-list).\n\n\nHTTP method and URL:\n\n```\nDELETE https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cachedContents/CACHE_ID\n```\n\nTo send your request, choose one of these options: \n\n#### curl\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\ncurl -X DELETE \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n \"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cachedContents/CACHE_ID\"\n```\n\n#### PowerShell\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\" }\n\nInvoke-WebRequest `\n -Method DELETE `\n -Headers $headers `\n -Uri \"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/cachedContents/CACHE_ID\" | Select-Object -Expand Content\n```\n\nIf the delete operation succeeds, the response is empty:\n\n#### Response\n\n```\n{ }\n```\n\n### Example curl command\n\n LOCATION=\"us-central1\"\n PROJECT_ID=\"\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\"\n CACHE_ID=\"\u003cvar translate=\"no\"\u003eCACHE_ID\u003c/var\u003e\"\n\n curl \\\n -X DELETE \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/${CACHE_ID}\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- Learn how to [create a new context cache](/vertex-ai/generative-ai/docs/context-cache/context-cache-create).\n- Learn how to [get information about all context caches associated with a Google Cloud project](/vertex-ai/generative-ai/docs/context-cache/context-cache-getinfo)."]]