跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt

Use this file to discover all available pages before exploring further.

概览

TokenLab 自动管理缓存以优化性能并降低成本。虽然没有公开的端点来清除缓存条目,但您可以通过请求级控制完全掌控缓存行为。 本页是 request-side cache 指南。 如需严格的 API 参考页面,请参见:

绕过缓存

要获取不使用缓存的新鲜响应,请在请求中使用 cache_control 参数:
curl -X POST "https://api.tokenlab.sh/v1/chat/completions" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}],
    "cache_control": {"type": "no_cache"}
  }'

缓存控制选项

类型效果
no_cache跳过缓存查找和写入,始终获取新鲜响应
no_store不将此响应存储在缓存中
response_only仅使用精确匹配缓存(跳过语义匹配)
semantic_only仅使用语义缓存(跳过精确匹配)

缓存反馈

如果您收到错误的缓存响应,可以进行举报: 请使用当前组织下缓存命中的 request/cache entry 标识;任意 ID 会被拒绝。
curl -X POST "https://api.tokenlab.sh/v1/cache/feedback" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "cache_entry_id": "req_1234567890",
    "feedback_type": "wrong_answer",
    "description": "Response was outdated"
  }'
当缓存条目收到足够的负面反馈时,它将自动失效。

使用场景

在开发过程中,使用 cache_control: {"type": "no_cache"} 以确保获取新鲜的 API 响应。
对于股票价格或天气等实时数据,请始终使用 no_cache 以获取当前信息。
在调试意外响应时,使用 no_cache 以排除缓存结果。
有关缓存的更多详细信息,请参阅 缓存指南