컨텍스트를 삭제하려면 캐시 ID, 컨텍스트 캐시가 연결된 Google Cloud 프로젝트 ID, 컨텍스트 캐시 만들기 요청이 처리된 리전이 필요합니다. 컨텍스트 캐시의 캐시 ID는 컨텍스트 캐시를 만들 때 반환됩니다. 컨텍스트 캐시 목록 명령어를 사용하여 프로젝트와 연결된 각 컨텍스트 캐시의 캐시 ID를 가져올 수도 있습니다.
# 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-central1
exportGOOGLE_GENAI_USE_VERTEXAI=True
fromgoogleimportgenaifromgoogle.genai.typesimportHttpOptionsclient=genai.Client(http_options=HttpOptions(api_version="v1beta1"))# 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
REST
다음에서는 REST를 사용하여 DELETE 요청을 게시자 모델 엔드포인트에 보내 Google Cloud 프로젝트와 연결된 컨텍스트 캐시를 삭제하는 방법을 보여줍니다.
CACHE_ID: 삭제할 컨텍스트 캐시의 ID. 컨텍스트 캐시를 만들 때 컨텍스트 캐시 ID가 반환됩니다. 또한 다음을 사용하여 Google Cloud 프로젝트의 컨텍스트 캐시를 나열해 컨텍스트 캐시 ID를 찾을 수도 있습니다. 자세한 내용은 컨텍스트 캐시 만들기 및 컨텍스트 캐시 나열을 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 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)."]]