Bridge by Wekoya / Docs / Chat

Context caches

Updated

Ask many questions about one long thing (a handbook, a contract, a video) without paying for it in full each time. Store it once as a cache, then name the cache in chat requests: its tokens are billed at the cached rate, a fraction of the input rate. Works on Gemini models.

curl https://wekoya-api.wekoya.tech/v1/caches \
  -H "Authorization: Bearer $WEKOYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-flash-lite",
    "ttl_seconds": 3600,
    "messages": [
      { "role": "system", "content": "Answer questions about this handbook. Cite the clause." },
      { "role": "user", "content": "<the whole handbook, or a PDF, video or audio file>" }
    ]
  }'

# {
#   "id": "cache_3857a1d3-…",
#   "model": "gemini-3.5-flash-lite",
#   "tokens": 9914,
#   "expires_at": "2026-10-09T17:12:21Z",
#   "wekoya": { "cost": 19.14, "currency": "NGN", "hours_paid": 1 }
# }
reply = client.chat.completions.create(
    model="gemini-3.5-flash-lite",  # the cache's model, or "auto"
    messages=[{"role": "user", "content": "What does clause 17 say?"}],
    extra_body={"cache": "cache_3857a1d3-…"},
)

print(reply.choices[0].message.content)
print(reply.usage.prompt_tokens_details.cached_tokens)  # 9914, at the cached rate
# Keep it longer (pays only for hours not already paid)
curl -X PATCH https://wekoya-api.wekoya.tech/v1/caches/cache_3857a1d3-… \
  -H "Authorization: Bearer $WEKOYA_API_KEY" -H "Content-Type: application/json" \
  -d '{ "ttl_seconds": 7200 }'

# List, read, delete
curl https://wekoya-api.wekoya.tech/v1/caches -H "Authorization: Bearer $WEKOYA_API_KEY"
curl -X DELETE https://wekoya-api.wekoya.tech/v1/caches/cache_3857a1d3-… -H "Authorization: Bearer $WEKOYA_API_KEY"