Caching prompt
NA-EME SITE N'onwe yaHosted open-weight models na-echekwa prompt prefixes a na-emeghachi na cache n'onwe ha. Mgbe request malitere na otu system prompt, tools na ozi gara aga dị ka request na nso nso a na otu model ahụ, a na-agụ shared prefix ahụ site na cache ma na-akwụ ụgwọ ya na 25% nke ọnụahịa input nke model ahụ (10% na Heavy Duty models). Ọ dịghị ihe ị ga-enyocha, ma ide na cache bụ n'efu.
Otu ọ na-arụ ọrụ
- Prefix, n'usoro — A na-agụ prompt n'usoro: system prompt, tool definitions, mgbe ahụ ka a gụọ messages. Cache na-eme match site na mmalize sequence ahụ ruo na token mbunye nke dị iche.
- Ihe a na-agụ dịka hit — Request nke prompt ya malitere na content nke gaghara — nke na-abụkarị turn mbunye nke conversation ahụ na messages ọhụrụ a gbakwunyele. Prefix a match-rị bụ cached input; ihe niile ndị gbasoro ya bụ regular input.
- Ọkwa nkewa — Cache na-ejide prompt n'ime blocks nke tokens 1,568, yabụ a naghị echekwa prompt dị mkpụmkpụ karịa tokens 1,500 ma ọ bụ ihe ruru ya. Ọnụọgụ cached n'ime azịza bụ ọnụọgụ input gị nke e jiri òkè cached nke prompt mụbaa, wedata ala. Ọ bụghị mgbe niile ka ọ bụ ọtụtụ nke nha block.
- Na-enweghị hit — A na-akwụ ụgwọ request nke mmalite ya na-adịghị na cache n'ọnụego input nkịtị. A naghị ebipụta oge ndụ maka prompts echekwara ma hit abụghị ihe e kwere nkwa: gụọ
usageka ị hụ ihe request weere na cache. - Enweghị switch — Request anaghị abanye, enweghịkwa field na-agbanyụ caching.
- Mbee models — Every hosted open-weight id. GET /v1/models na-akọwa capabilities.prompt_caching: true na pricing.cached_input_per_million_usd maka ha. Shannon models na-akwụ ụgwọ ọnụgoเดียว.
Hụ cache hit n'ime azịza
Zipu requests abụọ malitere na otu system prompt ogologo ma bipụta usage nke ọ bụla. Nọmba mbụ bụ input nke request, nke abụọ bụ akụkụ ya e sitere na cache gụọ.
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 Ugolu
Cached input tokens na-akwụ ụgwọ na 25% nke ọnụahịa input nke model ahụ (10% na Heavy Duty models), a gbatịrị ya ruo $0.001 kwa 1M. Ide na cache adịghị efu ego ọzọ, ma output na-akwụ ụgwọ dị ka ọ na-adị. Ọnụahịa cached nke id ọ bụla dị na tebụl Models & pricing. Models & ọnụahịa
A na-akwụ ụgwọ input nke oku dị ka (input − cached) × input rate + cached × cached rate. Ọnụọgụ cached anaghị agafe ọnụọgụ input.
| Model | Ntinye / 1M | Ntinye e debere / 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 na-edepụta cached input nke oku ọ bụla. Tokens e kwụrụ ụgwọ ya na ọnụahịa ya agụnyela cached rate. Igodo & Ojiji
Mpụzụ ojiji
| Endpoint | Input echebara | Ịtụgharị uche |
|---|---|---|
/v1/chat/completions | usage.prompt_tokens_details.cached_tokens — akụkụ nke prompt_tokens | usage.completion_tokens_details.reasoning_tokens — akụkụ nke completion_tokens |
/v1/responses | usage.input_tokens_details.cached_tokens — akụkụ nke input_tokens | usage.output_tokens_details.reasoning_tokens — akụkụ nke output_tokens |
/v1/messages | usage.cache_read_input_tokens — a kọwara ғаra: input_tokens bụ akụkụ anaghị akọpụ; cache_creation_input_tokens bụ mgbe niile 0 | a na-agụ thinking n'ime 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
}
} Azịza a na-eme streaming na-ebu otu fields n'ime usage ikpeazụ ya. Ọ dịghị mkpa ka ị rịọ ya:
| Endpoint | Ebe usage na-abịa |
|---|---|
/v1/chat/completions | usage na chunk ikpeazụ tupu data: [DONE]. A na-ezipu ya na stream ọ bụla. |
/v1/responses | response.usage nke response.completed event. |
/v1/messages | usage nke message_delta event. usage nke message_start nwere efu. |
Otu esi nweta cache hits ndịzi
- Mechie system prompt na tool definitions ka ha ghọzie byte-for-byte n'ime calls. Debe values nke call kachaa dịka timestamps ma ọ bụ request ids n'ikpeazụ nke message kachaa, ọ bụghị n'ime system prompt.
- Gbakwunye naanị na history. Ime editing, trimming ma ọ bụ summarising na turns mbunye na-agbanwe prefix, own ihe niile gbasoro mgbanwe mbunye ahụ a na-akwụ ụgwọ ya dịka regular input.
- Atụla tools, messages ma ọ bụ content blocks n'usoro iche n'etiti calls, ma mee serialise JSON (tool schemas, tool arguments na results) n'otu ụzọ mgbe niile.
- Nọgide na otu model id maka mkparịta ụka, ma zipu oku na-esote n'oge na-adịghị anya mgbe nke gara aga gasịrị.
API na-edebe mmalite mkparịta ụka kwụsiri ike n'ikpe ndị a:
- Ozi
systemma ọ bụdevelopere zigara mgbe e mesịrị n'ime mkparịta ụka na-anọgide n'ọnọdụ ya. Ọ naghị agbanwe mmalite nke prompt, yabụ turns tupu ya na-anọgide n'ime cache. - A na-atụnyere arguments nke oku tool n'ime assistant turns gara aga site na uru. Usoro key na oghere nke JSON ahụ adịghị eme ihe.
- Endpoints atọ ahụ na-agụ mkparịta ụka n'otu ụzọ. Mkparịta ụka e jiri n'endpoint ọzọ na-ejigide shared prefix ya mgbe ọdịnaya bụ otu.
Fields a rịọrọ
A nabatara prompt_cache_key (Chat Completions na Responses) na cache_control na Messages content blocks, n'ihi nke ahụ, koodu client dịbe anya agaghị agbanwe. Ọ bụghịkwa na ha dị mkpa: caching abụrụla automatik ma na-arụ ọrụ nke ahụ n'enweghị ha.
| Field | Ezigara na | Ihe ọ bụ |
|---|---|---|
prompt_cache_key | /v1/chat/completions, /v1/responses | Cache routing key nke OpenAI API. |
cache_control | /v1/messages | Cache breakpoint n'elu content block, system block ma ọ bụ ozi nke Anthropic API. |
stream_options | /v1/chat/completions | include_usage na-arịọ OpenAI API usage na stream. Ebe a stream ọ bụla na-agwụ na usage. |
Ịgụnume tokens
Endpoints abụọ n'efu, POST /v1/tokenize na POST /v1/messages/count_tokens, na-agụ tokens nke text ma ọ bụ nke request dum maka hosted open-weight models tupu i zipu ya. Ha nwere peeji nke ha: Ịgụ tokens
