Cached Contents
对较长且会重复使用的上下文,可以先创建缓存,再在生成请求中引用缓存名称。
创建缓存
POST /v1beta/cachedContents
bash
curl https://api.layso.ai/v1beta/cachedContents \
-H "x-goog-api-key: $LAYSO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "models/gemini-model-id",
"contents": [{"parts": [{"text": "需要重复使用的长上下文"}]}],
"ttl": "3600s"
}'使用缓存
在 Generate Content 请求中加入 cachedContent 字段,值为创建缓存后返回的 name。
