Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env bash2# STATUS: LIVE_VERIFIED — executed 2026-09-18 (exit 0 in 0.4s) — ACCOUNT_RESTRICTED path taken (free tier)3# Explicit caching lifecycle: create (~5k tokens, ttl 120s) -> generateContent with cachedContent -> get -> patch ttl -> delete. On the free tier creation fails with 429 TotalCachedContentStorageTokensPerModelFreeTier limit=0 (ACCOUNT_RESTRICTED) and the script exits 0 after printing the error.4# Run: bash examples/gemini/context-caching/cache_lifecycle.sh (key injected from .env by scripts/lib.sh `gemini` wrapper; never printed)5set -eo pipefail6source "$(dirname "$0")/../../../scripts/lib.sh"; out="$(mktemp)"; trap 'rm -f "$out"' EXIT7MODEL="gemini-3.5-flash"8FILLER=$(python3 -c 'print(" ".join(f"Section {i}: The Atlas reference corpus documents the public API surface of large language model providers, including endpoints, parameters, streaming events, objects, errors and pricing, verified experimentally." for i in range(1,121)))')9printf '{"model":"models/%s","displayName":"atlas-example","ttl":"120s","systemInstruction":{"parts":[{"text":"Answer with one word."}]},"contents":[{"role":"user","parts":[{"text":"%s"}]}]}' "$MODEL" "$FILLER" > "$out.req"10gemini POST /v1beta/cachedContents -d @"$out.req" > "$out"; rm -f "$out.req"; mask < "$out" | head -c 500; echo; echo "HTTP $GEMINI_STATUS"11log_request gemini POST /v1beta/cachedContents "$GEMINI_STATUS" 0.0015 "example context-caching/cache_lifecycle.sh create"12if [ "$GEMINI_STATUS" != "200" ]; then echo "ACCOUNT_RESTRICTED: explicit caching not available on this tier (see docs/gemini/context-caching.md)"; exit 0; fi13NAME=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["name"])' "$out")14gemini POST "/v1beta/models/$MODEL:generateContent" -d "{\"contents\":[{\"role\":\"user\",\"parts\":[{\"text\":\"Reply with OK.\"}]}],\"cachedContent\":\"$NAME\",\"generationConfig\":{\"maxOutputTokens\":8}}" > "$out"; mask < "$out" | python3 -c 'import json,sys; print(json.load(sys.stdin)["usageMetadata"])'15log_request gemini POST "/v1beta/models/{model}:generateContent" "$GEMINI_STATUS" 0.0001 "example cache use"16gemini GET "/v1beta/$NAME" > "$out"; log_request gemini GET "/v1beta/cachedContents/{id}" "$GEMINI_STATUS" 0 "example cache get"17gemini PATCH "/v1beta/$NAME" -d '{"ttl":"300s"}' > "$out"; mask < "$out" | head -c 300; echo; log_request gemini PATCH "/v1beta/cachedContents/{id}" "$GEMINI_STATUS" 0 "example cache patch"18gemini DELETE "/v1beta/$NAME" > "$out"; echo "delete HTTP $GEMINI_STATUS"; log_request gemini DELETE "/v1beta/cachedContents/{id}" "$GEMINI_STATUS" 0 "example cache delete"19