Tlola ho ea ho litaba
Caching ea Prompt

Caching ea Prompt

KE AUTOMATIC

Limohlala tse bulehileng tsa boima tse amohetsoeng li boloka ka cache ka bo eona li-prefix tsa prompt tse pheta-phetoang. Ha kopo e qala ka system prompt e tšoanang, lisebelisoa le melaetsa ea pejana joaloka kopo ea haufinyane mohlaleng o le mong, prefix eo e arolelanoang e baloa ho cache 'me e lefisoa ka 25% ea theko ea kenyelletso ea mohlala (10% ho limohlala tsa Heavy Duty). Ha ho letho le lokelang ho kengoa, 'me ho ngola ho cache ke mahala.

Mokhoa oa tšebetso

  • Prefix, ka tatso — Prompt e baloa ka tatso: system prompt, tool definitions, ebe ke melaetsa. Cache e lekisa ho tloha qalong ea sequence eo ho fihla ho token ea pele e fapalaneng.
  • Se queleloa hit — Request eo prompt ea eona e qalang ka content e tšoanang le request ea morao-rao — hangata ke turn ea feta ea conversation e tšoanang ka melaetsa e mecha e eketsitsoeng. Prefix e lekang ke cached input; tsohle ka morao oa eona ke regular input.
  • Botlenya ba cache — Cache e boloka prompt ka li-block tsa tokens tse 1,568, kahoo prompt e khutšoanyane ho feta tokens tse ka bang 1,500 ha e cache-oe. Palo ea cached karabong ke palo ea hau ea input e atolositsoeng ka karolo ea cached ea prompt, e fokotsoeng ho tse fokolang. Ha e ame e le palo e atolositsoeng ea boholo ba block.
  • Ntle le hit — Kopo eo qalo ea eona e seng ho cache e lefisoa ka input rate e tloaelehileng. Ha ho nako ea bophelo e phatlalalitsoeng bakeng sa li-prompt tse cached mme hit ha e tiisetsoe: bala usage ho bona seo kopo e se nkileng ho cache.
  • Ha ho switch — Kopo ha e kenelle, mme ha ho field e tima caching.
  • Models lifelesso — Hosted open-weight id e mong’a. GET /v1/models e rapela capabilities.prompt_caching: true le pricing.cached_input_per_million_usd bakeng sa tsona. Shannon models li betala rate e le nngwe.

Bona cache hit karabong

Romela likopo tse peli tse qalang ka system prompt e telele e tšoanang mme u gatisetse usage ea e 'ngoe le e 'ngoe. Nomoro ea pele ke input ea kopo, ea bobeli ke karolo ea eona e baloang ho cache.

from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.shannon-ai.com/v1")

handbook = open("handbook.txt").read()  # a long text that stays the same


def ask(question):
    response = client.chat.completions.create(
        model="Kimi-K3-uncensored-3BIT-REAP",
        messages=[
            {"role": "system", "content": handbook},
            {"role": "user", "content": question},
        ],
    )
    usage = response.usage
    print(usage.prompt_tokens, usage.prompt_tokens_details.cached_tokens)


ask("What is the refund policy?")
ask("Who approves travel?")  # same start: read the second number

Theko

Matokene a kenyelletso a bolokiloeng ka cache a lefisoa ka 25% ea sekhahla sa kenyelletso sa mohlala (10% ho limohlala tsa Heavy Duty), se ntlafalitsoeng ho $0.001 ka 1M. Ho ngola ho cache ha ho bitse letho le leng, 'me tlhahiso e lefisoa joalo ka mehla. Sekhahla sa cache sa id e 'ngoe le e 'ngoe se tafoleng ea Models & pricing. Li-model le litheko

Input ea kopo e lefisoa e le (input − cached) × input rate + cached × cached rate. Palo ea cached ha e ka ke ea feta palo ea input.

Model Kenyo / 1M Input e cached / 1M
DeepSeek-V4-Pro-0813-uncensored-3BIT-REAP $1.76 $0.44
GLM-5.2-uncensored-3BIT-REAP $1.47 $0.368
Kimi-K3-uncensored-3BIT-REAP $3.67 $0.918
Nemotron3Ultra-uncensored-3BIT-REAP $0.86 $0.215
MiniMax-M3-uncensored-3BIT-REAP $0.62 $0.155
DeepSeek-V4-Flash-0731-uncensored-W4A16-AUTOROUND-REAP $0.44 $0.11
Kimi-K2.6-uncensored-W4A16-AUTOROUND-REAP $1.11 $0.278
Laguna-S-2.1-uncensored-W4A16-AUTOROUND-REAP $0.41 $0.103
inkling-uncensored-W4A16-AUTOROUND-REAP $1.65 $0.413
MiMo-V2.5-Pro-uncensored-W4A4 $0.79 $0.198
MiMo-V2.5-uncensored-W4A4 $0.45 $0.113
Hy3-uncensored-W4A4 $0.44 $0.11
DeepSeek-V4.1-Flash-1017-uncensored-W4A4 $0.46 $0.115
GLM-5.3-uncensored-W4A4 $1.63 $0.408
GLM-5.3-Flash-uncensored-W4A4 $0.44 $0.11
MiMo-V2.6-Pro-uncensored-W4A4 $0.79 $0.198
MiMo-V2.6-Flash-uncensored-W4A4 $0.45 $0.113
MiniMax-M3.1-Flash-uncensored-W4A4 $0.46 $0.115
Qwen3.8-2.4T-uncensored-W4A4 $2.55 $0.638
Qwen3.8-Flash-uncensored-W4A4 $0.46 $0.115
Hunyuan-4-Preview-uncensored-W4A4 $1.23 $0.308
Step-5-Preview-uncensored-W4A4 $1.42 $0.355
LongCat-2.0-uncensored-W4A4 $1.14 $0.285
Ling-3.1-Flash-uncensored-W4A4 $0.38 $0.095
Nemotron-3.5-Super-uncensored-W4A4 $0.46 $0.115
Muse-Spark-Open-uncensored-W4A4 $1.70 $0.425
Beam-1.0-uncensored-W4A4 $0.75 $0.188
Nex-N2.5-Pro-uncensored-W4A4 $0.38 $0.095
Kimi-K3.1-Pro-uncensored-NVFP4 $4.02 $0.402
GLM-5.3-uncensored-FP8 $6.22 $0.622
DeepSeek-V4.1-Flash-1017-uncensored-FP8 $2.08 $0.208
Kimi-K3-uncensored-NVFP4 $5.15 $0.515
MiMo-V2.6-Pro-uncensored-NVFP4 $2.26 $0.226
Qwen3.8-2.4T-uncensored-NVFP4 $4.02 $0.402
LongCat-2.0-uncensored-NVFP4 $2.61 $0.261

Usage log e thathamisa input e cached ea kopo e 'ngoe le e 'ngoe. Tokens tse lefisitsoeng le theko ea eona li se li kenyelletsa cached rate. Linotlolo le tšebeliso

Fields tsa tšebeliso

Endpoint Input e cached Ho nahana
/v1/chat/completions usage.prompt_tokens_details.cached_tokens — karolo ea prompt_tokens usage.completion_tokens_details.reasoning_tokens — karolo ea completion_tokens
/v1/responses usage.input_tokens_details.cached_tokens — karolo ea input_tokens usage.output_tokens_details.reasoning_tokens — karolo ea output_tokens
/v1/messages usage.cache_read_input_tokens — e rapeloa ka setala: input_tokens ke karolo e sa cached-oeng; cache_creation_input_tokens ke 0 kamehla thinking e baloa ho output_tokens
{
  "usage": {
    "prompt_tokens": 20000,
    "completion_tokens": 812,
    "total_tokens": 20812,
    "prompt_tokens_details": {
      "cached_tokens": 18000
    },
    "completion_tokens_details": {
      "reasoning_tokens": 604
    }
  }
}

Karabo ea stream e nka li-field tse tšoanang usage ea eona ea ho qetela. Ha u hloke ho e kopa:

Endpoint Moo usage e fihlang teng
/v1/chat/completions usage ho chunk ea ho qetela pele ho data: [DONE]. E romeloa ho stream e 'ngoe le e 'ngoe.
/v1/responses response.usage ea event ea response.completed.
/v1/messages usage ea event ea message_delta. usage ea message_start e na le li-zero.

Ho fumana cache hits tse ngata

  • Boloka system prompt le tool definitions li tšoana byte-ka-byte pakeng tsa likhoapolo. Beha values tsa call ka’ng joalo ka timestamps kapa request ids qetellong ea melaetsa e morao, eseng ho system prompt.
  • Eketsa feela ho history. Ho fetola, ho fokotsa kapa ho summarize turns tsa pele ho fetola prefix, ebile tsohle ka morao oa pheto ea pele li betaloa e le regular input.
  • u se fetole tatso ea tools, melaetsa kapa content blocks pakeng tsa likhoapolo, ebile serialise JSON (tool schemas, tool arguments le results) ka mokhoa o tšoanang kamehla.
  • Lula ho id e le 'ngoe ea model moqoqong, mme u romele kopo e latelang kapele ka mor'a e fetileng.

API e boloka qalo ea moqoqo e tsitsitse maemong ana:

  • Molaetsa oa system kapa developer o romeloang hamorao moqoqong o lula sebakeng sa oona. Ha o fetole qalo ea prompt, kahoo liphetoho tse o fetileng li lula li cached.
  • Li-argument tsa likopo tsa tool liphetohong tse fetileng tsa assistant li bapisoa ka boleng. Tatellano ea li-key le sebaka sa JSON eo ha li bohlokoa.
  • Li-endpoint tse tharo li bala moqoqo ka tsela e tšoanang. Moqoqo o tsoelang pele ho endpoint e 'ngoe o boloka prefix ea oona e arolelanoang ha litaba li tšoana.

Fields tsa kopo

prompt_cache_key (Chat Completions le Responses) le cache_control ho Message content blocks li ammehiloe, kahoo code ea client e seng elahlehile e sebetsa ntle le liphetwo. Ha ho na le eona ea hlokang: caching ke ea automatiki ’me e sebetsa ka tsela e tšoanang ntle le tsona.

Lebala E rometsoe ho Ke eng
prompt_cache_key /v1/chat/completions, /v1/responses Cache routing key ea OpenAI API.
cache_control /v1/messages Cache breakpoint ho content block, block ea system kapa molaetsa oa Anthropic API.
stream_options /v1/chat/completions include_usage e kopa OpenAI API usage ho stream. Mona stream e 'ngoe le e 'ngoe e fela ka usage.

Ho bala tokens

Li-endpoint tse peli tsa mahala, POST /v1/tokenize le POST /v1/messages/count_tokens, li bala tokens tsa mongolo kapa tsa kopo eohle bakeng sa li-model tse hosted tsa open-weight pele u e romela. Li na le leqephe la tsona: Ho bala tokens

SHANNON Pontšo ea lenaneo la NVIDIA Inception SHANNON LAB LLC ke setho sa lenaneo la NVIDIA Inception.

Kgetha puo ya hao

Dipuo tsohle di lekana. Kgetha eo o batlang ho e sebedisa ha o bala.

Yuropa

Middle East le Afrika Leboea

Asia Boroa

Asia Boroa-Botjhabela

Asia Botjhabela

Asia e Bohareng le Caucasus

Afrika

Oceania

Lipuo tse Entsoeng le tsa Khale