I-Prompt caching
IZIKHATHAIimodeli ze-open-weight ezibanjelwe zigcina ngokwazo kukheshi iimaphambili ze-prompt eziphindaphindwayo. Xa isicelo siqala ngeprompt yenkqubo efanayo, izixhobo nemiyalezo yangaphambili njengesicelo sakutshanje kwimodeli enye, loo maphambili abelanayo afundwa kukheshi aze afakwe ngama-25% eexabiso legalelo lemodeli (10% kumodeli ze-Heavy Duty). Akukho nto ifuna ukuvulwa, kwaye ukubhala kukheshi kuyasimahla.
Isebenza njani
- Prefix, ngokulandelana — I-prompt ifundwa ngokulandelana: i-system prompt, i-tool definitions, emva koko imiyalezo. I-cache ihambelana ukusuka ekuqaleni kwelo sequence kuye kwi-token yokuqala efana nengafaniyo.
- Yintoni eyathathwa njenge-hit — I-request whose prompt iqala ngokuqukumbela okufanayo ne-request yakuqhula — ngokuhlala yinyanga yokuqala yengxoxo efanayo kunye nemiyalezo emitsha eyongeziweyo. I-prefix efanayo yi-cached input; yonke into emva koko yi-regular input.
- Ubuncwane — I-cache ibamba i-prompt kwiibloko ezingama-1,568 yee-token, ngoko i-prompt emfutshane kune-1,500 yee-token ngokuqikelelwa ayigcinwa. Inani le-cached kwimpendulo lelakho inani le-input lixhaswe yinxalenye egcinwe ye-prompt, lijikelwe ezantsi. Ayisoloko iphindaphindwa kobungakanani beebloko.
- Ngaphandle kwe-hit — Isicelo ekungekho ngqalelo yaso kwi-cache sihlawulwa kwireyithi eqhelekileyo ye-input. Akukho xesha lokuhlala lupapashiweyo lwee-prompt ezigcinwe kwaye i-hit ayiqinisekisiwe: funda i-
usageukubona oko isicelo sikuthathe kwi-cache. - Akukho sitshintshi — Isicelo asikhethi ukungena, kwaye akukho ntsimi icima i-caching.
- Zeziphi i-models — Yonke i-hosted open-weight id. I-GET /v1/models ibika i-capabilities.prompt_caching: true kunye ne-pricing.cached_input_per_million_usd kuzo. I-Shannon models ibhalwa ngemvuzo enye efanayo.
Bona i-cache hit kwimpendulo
Thumela izicelo ezimbini eziqala nge-system prompt ende efanayo uze uprinte ukusetyenziswa kwesinye ngasinye. Inani lokuqala yi-input yesicelo, lesibini yinxalenye yayo efundwe kwi-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 import { readFileSync } from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ apiKey: "YOUR_API_KEY", baseURL: "https://api.shannon-ai.com/v1" });
const handbook = readFileSync("handbook.txt", "utf8"); // a long text that stays the same
async function ask(question) {
const response = await client.chat.completions.create({
model: "Kimi-K3-uncensored-3BIT-REAP",
messages: [
{ role: "system", content: handbook },
{ role: "user", content: question },
],
});
const usage = response.usage;
console.log(usage.prompt_tokens, usage.prompt_tokens_details.cached_tokens);
}
await ask("What is the refund policy?");
await ask("Who approves travel?"); // same start: read the second number # handbook.txt is a long text that stays the same. jq builds the JSON body from it
# and prints the usage object of the reply. Run it twice with different questions.
jq -Rs '{
model: "Kimi-K3-uncensored-3BIT-REAP",
messages: [
{role: "system", content: .},
{role: "user", content: "What is the refund policy?"}
]
}' handbook.txt \
| curl -s https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d @- \
| jq .usage Amaxabiso
Amathokheni egalelo agcinwe kukheshi afakwa ngama-25% omgangatho wegalelo wemodeli (10% kumodeli ze-Heavy Duty), kujikeleziswe ukuya ku-$0.001 nge-1M. Ukubhala kukheshi akubizi nto ongezelelweyo, kwaye okuphumayo kufakwa njengesiqhelo. Umgangatho wekheshi we-id nganye usetafileni ye-Models & pricing. Iimodeli namaxabiso
I-input yobizo iyahlawulwa njenge (input − cached) × ireyithi ye-input + cached × ireyithi ye-cached. Inani le-cached alikho likhulu kuneli le-input.
| Imodeli | I-input / 1M | I-input egcinwe / 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 |
Igosa lokusetyenziswa lidwelisa i-input egcinwe yobizo ngalunye. Ii-token zalo ezibhiliweyo nexabiso sele zibandakanya ireyithi ye-cached. Izitshixo nokusetyenziswa
Amacandelo okusetyenziswa
| Endpoint | I-input e-cached | Ukuqiqa |
|---|---|---|
/v1/chat/completions | usage.prompt_tokens_details.cached_tokens — inxalenye ye-prompt_tokens | usage.completion_tokens_details.reasoning_tokens — inxalenye ye-completion_tokens |
/v1/responses | usage.input_tokens_details.cached_tokens — inxalenye ye-input_tokens | usage.output_tokens_details.reasoning_tokens — inxalenye ye-output_tokens |
/v1/messages | usage.cache_read_input_tokens — ibikwa ngokwamaqela: i-input_tokens yinxalenye engacachiyelelo; i-cache_creation_input_tokens ihlala i-0 | ukucinga kubalwa kwi-output_tokens |
{
"usage": {
"prompt_tokens": 20000,
"completion_tokens": 812,
"total_tokens": 20812,
"prompt_tokens_details": {
"cached_tokens": 18000
},
"completion_tokens_details": {
"reasoning_tokens": 604
}
}
} {
"usage": {
"input_tokens": 20000,
"input_tokens_details": {
"cached_tokens": 18000
},
"output_tokens": 812,
"output_tokens_details": {
"reasoning_tokens": 604
},
"total_tokens": 20812
}
} {
"usage": {
"input_tokens": 2000,
"cache_read_input_tokens": 18000,
"cache_creation_input_tokens": 0,
"output_tokens": 812
}
} Impendulo ekwi-stream ithwala iintsimi ezifanayo kwi-usage yayo yokugqibela. Akufuneki uyicele:
| Endpoint | Apho ukusetyenziswa kufika khona |
|---|---|
/v1/chat/completions | I-usage kwi-chunk yokugqibela phambi kwe-data: [DONE]. Ithunyelwa kuyo yonke i-stream. |
/v1/responses | I-response.usage yesiganeko se-response.completed. |
/v1/messages | I-usage yesiganeko se-message_delta. I-usage ye-message_start ibamba ii-zero. |
Ukufumana i-cache hits ezinqabileyo
- Gcina i-system prompt kunye ne-tool definitions zingatshintshwa byte-for-byte phakathi kwe-calls. Faka i-values ezifana ne-timestamps okanye i-request ids ekugqibeleni komyalezo wokugqibela, hayi kwi-system prompt.
- Yongeza kuphela kwimbali (history). Ukulungisa, ukunciphisa okanye ukufupha imiyalezo yangaphambili kutshintsha i-prefix, kwaye yonke into emva koku kutshintshwa ibhalwa njenge-regular input.
- Ungatshintshi indlela ekuhlelwe ngayo i-tools, imiyalezo okanye i-content blocks phakathi kwe-calls, kwaye i-serialise i-JSON (tool schemas, tool arguments kunye ne-results) ngendlela efanayo rhoqo.
- Hlala kwi-id yemodeli enye kwincoko, uze uthumele ubizo olulandelayo kwakamsinya emva kwolwangaphambili.
I-API igcina ukuqala kwencoko kuzinzile kwezi meko:
- Umyalezo we-
systemokanye we-developerothunyelwe kamva kwincoko uhlala kwindawo yawo. Awutshintshi ukuqala kwe-prompt, ngoko iminyaka ephambi kwawo ihlala igcinwe. - Ii-argument zobizo lwee-tool kwiminyaka yangaphambili ye-assistant ziqhathaniswa ngexabiso. Ulandelelwano lwezitshixo nesithuba se-JSON leyo azibalulekanga.
- Ii-endpoint ezintathu zifunda incoko ngendlela enye. Incoko iqhubekile kwenye i-endpoint igcina i-prefix yayo ekwabelwana ngayo xa umxholo ufana.
Iifields zezicelo
i-prompt_cache_key (Chat Completions and Responses) kunye ne-cache_control kwiblocks zokuqukumbela kwe-Messages zamkelekile, ngoko ke ikhowudi yomsebenzi ekho ihamba ngaphandle kwenguqu.
| Intsimi | Ithunyelwe ku | Yintoni |
|---|---|---|
prompt_cache_key | /v1/chat/completions, /v1/responses | Isitshixo sokuhambisa i-cache se-OpenAI API. |
cache_control | /v1/messages | Indawo yokwahlula ye-cache kwi-block yomxholo, kwi-block ye-system okanye kumyalezo we-Anthropic API. |
stream_options | /v1/chat/completions | I-include_usage icela ukusetyenziswa kwi-OpenAI API kwi-stream. Apha yonke i-stream iphela ngokusetyenziswa. |
Ukubala ama-tokens
Ii-endpoint ezimbini zasimahla, i-POST /v1/tokenize ne-POST /v1/messages/count_tokens, zibala ii-token zombhalo okanye zesicelo sonke seemodeli ze-open-weight ezisingathiweyo phambi kokuba usithumele. Zinephepha lazo: Ukubala ii-token
