ការរក្សាទុក Prompt
ស្វ័យប្រវត្តិHosted open-weight model cache prompt prefix ដែលស្ទួនដោយស្វ័យប្រវត្តិ។ នៅពេល request ចាប់ផ្តើមដោយ system prompt, tools និងសារមុនៗដូចគ្នានឹង request ថ្មីៗលើ model តែមួយ prefix រួមនោះត្រូវបានអានពី cache ហើយគិតថ្លៃ 25% នៃតម្លៃ input របស់ model (10% លើ model Heavy Duty)។ មិនចាំបាច់បើកអ្វីទេ ហើយការសរសេរចូល cache គឺឥតគិតថ្លៃ។
របៀបដែលវាដំណើរការ
- Prefix តាមលំដាប់ — Prompt ត្រូវបានអានតាមលំដាប់៖ system prompt, tool definitions, រួចហើយទើបដល់សារ (messages)។ Cache ផ្គូផ្គងចាប់ពីការចាប់ផ្តើមនៃលំដាប់នោះ រហូតដល់ token ដំបូងដែលខុសគ្នា។
- អ្វីដែលរាប់ថាជា hit — Request ដែល prompt របស់វាចាប់ផ្តើមដោយមាតិកាដូចគ្នាទៅនឹង request ថ្មីៗ — ជាទូទៅគឺជាការសន្ទនាមុន ដែលមានសារថ្មីៗបន្ថែមនៅខាងក្រោម។ Prefix ដែលផ្គូផ្គងគ្នាគឺជា cached input; រាល់អ្វីៗបន្ទាប់ពីនោះគឺជា regular input។
- កម្រិតលម្អិត (Granularity) — cache រក្សា prompt ជា block ទំហំ 1,568 token ដូច្នេះ prompt ដែលខ្លីជាងប្រហែល 1,500 token មិនត្រូវបាន cache ទេ។ ចំនួន cached ក្នុងចម្លើយ គឺចំនួន input របស់អ្នកគុណនឹងភាគរយ cached នៃ prompt ហើយបង្គត់ចុះ។ វាមិនចាំបាច់ជាពហុគុណនៃទំហំ block ទេ។
- ដោយគ្មាន hit — request ដែលការចាប់ផ្តើមរបស់វាមិនមាននៅក្នុង cache ត្រូវបានគិតថ្លៃតាមតម្លៃ input ធម្មតា។ គ្មានអាយុកាលណាត្រូវបានផ្សព្វផ្សាយសម្រាប់ prompt ក្នុង cache ទេ ហើយ hit មិនត្រូវបានធានាទេ៖ សូមអាន
usageដើម្បីមើលអ្វីដែល request បានយកពី cache។ - គ្មានកុងតាក់ — request មិនចាំបាច់ជ្រើសចូល ហើយគ្មាន field ណាបិទ caching ទេ។
- Model ណាខ្លះ — រាល់ hosted open-weight id ទាំងអស់។ GET /v1/models រាយការណ៍ capabilities.prompt_caching: true និង pricing.cached_input_per_million_usd សម្រាប់ពួកវា។ Shannon models គិតថ្លៃក្នុងអត្រាតែមួយ។
មើល cache hit ក្នុងចម្លើយ
ផ្ញើ request ពីរដែលចាប់ផ្តើមដោយ system prompt វែងដូចគ្នា ហើយបោះពុម្ព usage នៃមួយៗ។ លេខទីមួយគឺ input នៃ request លេខទីពីរគឺផ្នែកនៃវាដែលអានពី 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 ការកំណត់ថ្លៃ
Cached input tokens គិតថ្លៃ 25% នៃអត្រា input របស់ model (10% លើ model Heavy Duty) បង្គត់ដល់ $0.001 ក្នុង 1M។ ការសរសេរចូល cache មិនអស់ថ្លៃបន្ថែមទេ ហើយ output ត្រូវបានគិតថ្លៃដូចធម្មតា។ អត្រា cached នៃ id នីមួយៗមាននៅក្នុងតារាង Models & pricing។ ម៉ូដែល និងតម្លៃ
input នៃការហៅមួយត្រូវបានគិតថ្លៃជា (input − cached) × តម្លៃ input + cached × តម្លៃ cached។ ចំនួន cached មិនដែលធំជាងចំនួន input ទេ។
| ម៉ូដែល | ការបញ្ចូល / 1M | Input ក្នុង cache / 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 រាយ input ក្នុង cache នៃការហៅនីមួយៗ។ token ដែលបានគិតថ្លៃ និងតម្លៃរបស់វារួមបញ្ចូលតម្លៃ cached រួចហើយ។ កូនសោ និងការប្រើប្រាស់
ចីឡូនៃការប្រើប្រាស់ (Usage fields)
| ចំណុចបញ្ចប់ | ការបញ្ចូលដែលបានរក្សាទុក | ការវែកញែក (Reasoning) |
|---|---|---|
/v1/chat/completions | usage.prompt_tokens_details.cached_tokens — ផ្នែកនៃ prompt_tokens | usage.completion_tokens_details.reasoning_tokens — ផ្នែកនៃ completion_tokens |
/v1/responses | usage.input_tokens_details.cached_tokens — ផ្នែកនៃ input_tokens | usage.output_tokens_details.reasoning_tokens — ផ្នែកនៃ output_tokens |
/v1/messages | usage.cache_read_input_tokens — រាយការណ៍ដាច់ដោយឡែក៖ input_tokens គឺជាផ្នែកដែលមិនបាន cache; cache_creation_input_tokens តែងតែស្មើ ០ | ការគិត (thinking) ត្រូវបានរាប់បញ្ចូលក្នុង 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
}
} ចម្លើយ stream មាន field ដូចគ្នាក្នុង usage ចុងក្រោយរបស់វា។ អ្នកមិនចាំបាច់សុំវាទេ៖
| ចំណុចបញ្ចប់ | កន្លែងដែល usage មកដល់ |
|---|---|
/v1/chat/completions | usage លើ chunk ចុងក្រោយមុន data: [DONE]។ វាត្រូវបានផ្ញើលើរាល់ stream។ |
/v1/responses | response.usage នៃ event response.completed។ |
/v1/messages | usage នៃ event message_delta។ usage នៃ message_start មានតែលេខសូន្យ។ |
វិធីទទួលបាន cache hits កាន់តែច្រើន
- រក្សា system prompt និង tool definitions ឱ្យនៅថេរ (stable) តាម byte ក្នុងពេលហៅ API នីមួយៗ។ ដាក់តម្លៃដែលផ្លាស់ប្តូរតាម call ដូចជា timestamps ឬ request ids នៅផ្នែកខាងចុងនៃសារចុងក្រោយ មិនមែននៅក្នុង system prompt នោះទេ។
- គ្រាន់តែបន្ថែម (append) ទៅក្នុង history។ ការកែសម្រួល, កាត់បន្ថយ ឬសង្ខេបសារមុនៗនឹងផ្លាស់ប្តូរ prefix ហើយរាល់អ្វីៗបន្ទាប់ពីការផ្លាស់ប្តូរដំបូងនឹងត្រូវបានគិតថ្លៃជា regular input។
- កុំផ្លាស់ប្តូរលំដាប់ tools, messages ឬ content blocks រវាងការហៅ API និងធ្វើការ serialize JSON (tool schemas, tool arguments និង results) តាមរបៀបតែមួយជានិច្ច។
- ប្រើ model id តែមួយសម្រាប់ការសន្ទនាមួយ ហើយផ្ញើការហៅបន្តឱ្យឆាប់បន្ទាប់ពីការហៅមុន។
API រក្សាការចាប់ផ្តើមនៃការសន្ទនាឱ្យនៅស្ថិតស្ថេរក្នុងករណីទាំងនេះ៖
- សារ
systemឬdeveloperដែលផ្ញើក្រោយក្នុងការសន្ទនា នៅទីតាំងរបស់វា។ វាមិនផ្លាស់ប្តូរការចាប់ផ្តើមរបស់ prompt ទេ ដូច្នេះវគ្គមុនវានៅតែ cache។ - អាគុយម៉ង់នៃការហៅ tool ក្នុងវគ្គ assistant មុនៗ ត្រូវបានប្រៀបធៀបតាមតម្លៃ។ លំដាប់ key និងចន្លោះនៃ JSON នោះមិនសំខាន់ទេ។
- endpoint ទាំងបីអានការសន្ទនាតាមរបៀបដូចគ្នា។ ការសន្ទនាដែលបន្តនៅ endpoint ផ្សេងរក្សា prefix រួមរបស់វា នៅពេលមាតិកាដូចគ្នា។
ចម្បែងនៃសំណើ (Request fields)
prompt_cache_key (Chat Completions និង Responses) និង cache_control នៅលើ Messages content blocks ត្រូវបានទទួលយក ដូច្នេះកូដ client ដែលមានស្រាប់ដំណើរការដោយគ្មានការផ្លាស់ប្តូរ។ វាមិនចាំបាច់មានទាំងពីរនោះទេ៖ ការធ្វើ caching គឺស្វ័យប្រវត្តិ និងដំណើរការដូចគ្នា បើគ្មានពួកវា។
| វាល | ផ្ញើទៅ | អ្វីដែលវាជា |
|---|---|---|
prompt_cache_key | /v1/chat/completions, /v1/responses | សោរកំណត់ផ្លូវ cache នៃ OpenAI API។ |
cache_control | /v1/messages | ចំណុចកំណត់ cache លើ block មាតិកា, block system ឬសារ នៃ Anthropic API។ |
stream_options | /v1/chat/completions | include_usage សុំ usage ពី OpenAI API លើ stream។ នៅទីនេះរាល់ stream បញ្ចប់ដោយ usage។ |
ការគណនា tokens
endpoint ឥតគិតថ្លៃពីរ គឺ POST /v1/tokenize និង POST /v1/messages/count_tokens រាប់ token នៃអត្ថបទ ឬនៃ request ទាំងមូលសម្រាប់ម៉ូដែល open-weight ដែលបង្ហោះ មុនពេលអ្នកផ្ញើវា។ ពួកវាមានទំព័រផ្ទាល់ខ្លួន៖ ការរាប់ token
