Prompt Caching & Batch Cost Optimization on API Store Hub
Slash repeated input token spend with cache_control on static system prompts while pairing Token and Request lanes to your workload.
Ready to ship production AI with one unified API key, VND billing, and multi-provider failover on API Store Hub?
Install command
| Language | Python |
|---|---|
| Runtime | Python 3.10+ / TypeScript, OpenAI & Anthropic SDK |
| Protocol | Anthropic (/v1/messages) & OpenAI (/v1/chat/completions) |
| Install command | pip install -U anthropic openai |
3-step quickstart setup
- Create an API key on API Store Hub: Sign in to the API Store Hub console, generate a key with prefix sk-ash-, and optionally attach daily or monthly spend caps.
- Install SDK & set Base URL: Install the official package and configure environment variables pointing to https://apistorehub.com for /v1/messages.
- Run inference with streaming & retry: Invoke claude-sonnet-5-5 with explicit timeout and jittered retries; every request logs tokens, TTFT, and exact cost.
Production-ready code sample
Python
import os
from openai import OpenAI
client = OpenAI(base_url="https://apistorehub.com/v1", api_key=os.environ["API_KEY"])
def route_task(prompt: str, complex_reasoning: bool) -> str:
model = "claude-sonnet-5-5" if complex_reasoning else "deepseek-v4-flash"
resp = client.chat.completions.create(
model=model,
max_tokens=1024 if complex_reasoning else 320,
messages=[
{"role": "system", "content": "Keep system prefix static for high cache hit rate."},
{"role": "user", "content": prompt},
],
)
return resp.choices[0].message.content or ""cURL
curl https://apistorehub.com/v1/messages \
-H "x-api-key: sk-ash-your_key" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-5-5","max_tokens":256,"system":[{"type":"text","text":"Static policy prefix...","cache_control":{"type":"ephemeral"}}],"messages":[{"role":"user","content":"Check rule 1"}]}'Recommended models with live pricing
| Model | Token price | Context & Endpoint |
|---|---|---|
| Claude Sonnet 5.5 | 7,700 ST / 1M tokens | 1M |
| DeepSeek V4 Flash | 1,500 ST / 1M tokens | 1M |
| DeepSeek V4 Pro | 3,600 ST / 1M tokens | 1M |
Production hardening checklist
- Place immutable instructions and reference docs at the top of the prompt and append dynamic user inputs last to maximize cache hits.
- Enable stream=true for long completions (> 500 tokens) to keep connections responsive and minimize time-to-first-token (TTFT).
- Never hard-code API keys in client bundles; load them from server environment variables and rotate keys periodically in API Store Hub.
- Configure exponential backoff with jitter for HTTP 429/502/529 and keep a secondary fallback model on the exact same API key.
Frequently asked questions
- Does integrating Prompt Caching & Cost Optimization with API Store Hub require rewriting existing calls?
- No. API Store Hub preserves native OpenAI (https://apistorehub.com/v1) and Anthropic Messages (https://apistorehub.com/v1/messages) schemas—just update the Base URL and sk-ash- API key.
- Can one API key handle streaming, function calling, and embeddings?
- Yes. A single API Store Hub key works across all 187 models, including SSE streaming, strict JSON Schema outputs, tool calling, and embeddings.
- How are billing and rate limits controlled?
- Every request is metered transparently by token or request in the API Store Hub console, never overdrafts your balance, and supports per-key spend caps.