Launch offer50% off up to $5,000, then 3% for lifeSee offer →

GUIDES · 7 MIN READ

Grok 4.5 Prompt Caching: How to Cut Your Token Bill Without Touching Your Code

Grok 4.5 bills cached input tokens at $0.50/M instead of $2/M, a 75% discount most teams never actually hit because of how they structure prompts. Here's how caching works and how to stack it with a discounted proxy.

RK

Ravi Kumar

Co-founder ·

Grok 4.5 Prompt Caching: How to Cut Your Token Bill Without Touching Your Code

Grok 4.5 Prompt Caching: How to Cut Your Token Bill Without Touching Your Code

Most teams calling the Grok 4.5 API are paying full price for tokens they've already sent once. xAI shipped prompt caching alongside Grok 4.5's $2/$6 per-million pricing, and cached input tokens bill at $0.50 per million instead of $2. That's a 75% discount on any token the model has seen before. Almost nobody is using it correctly, because it's invisible unless you go looking for it.

This post is a practical breakdown of what prompt caching does to a real Grok 4.5 bill, how to structure requests so the cache actually hits, and how to stack it with a discounted proxy so the savings compound instead of just sitting on top of list price.

What Prompt Caching Actually Does to Your Bill

Grok 4.5 launched on July 8 with a 500k token context window and a three-tier price for input tokens:

  • Standard input: $2.00 / million tokens
  • Cached input: $0.50 / million tokens
  • Output: $6.00 / million tokens

The cache isn't something you turn on. It's a side effect of how you structure your prompts. When you send a request, xAI's infrastructure checks whether the leading portion of your input (the prefix) matches a prefix it has served recently. If it does, that matched portion bills at the cached rate. Anything after the point where your prompt diverges from a previous call bills as standard input.

This means cache hits are a function of prompt structure, not a setting you flip. If your system prompt, tool definitions, and few-shot examples are byte-for-byte identical across calls and placed at the start of the request, they get cached. If you interleave variable content (a timestamp, a user ID, today's date) into the front of the prompt, you break the match and pay full price every time.

Why This Matters More at 500k Context

A 500k token context window is a gift and a trap. Teams building RAG pipelines or long-document agents will happily stuff 100k+ tokens of retrieved context into every call. Without caching, that's $0.20 per call just for context, before the model does anything. With caching, once that context has been sent once and reused within the cache TTL, it drops to $0.05 per call. On a workload doing thousands of calls a day against a shared knowledge base, that's not a rounding error, it's the difference between a sustainable feature and a line item that gets killed in a budget review.

When Caching Kicks In (and When It Doesn't)

Static System Prompts

Your system prompt, tool/function schemas, and any fixed instructions belong at the very top of the message array, in the exact same order and wording every single call. This is the easiest cache win available and most teams already do it by accident. The mistake is injecting dynamic values (current date, request ID, user tier) directly into the system prompt instead of passing them as a separate user-turn variable. One interpolated timestamp at the top of your prompt invalidates the cache for everything after it.

RAG and Long-Document Context

If you're retrieving chunks and prepending them to the prompt, order matters. Retrieval systems that re-rank or reorder chunks between calls will produce a different prefix every time, even if the underlying chunks are identical, because a reordered set is a different string. Pin your chunk ordering (by document ID, not by relevance score, which can shift between calls) if you want repeat queries against the same corpus to hit the cache.

Multi-Turn Agentic Loops

Agentic workflows that call the model repeatedly within a single task are the best case for caching, because each new call's prompt is the previous call's prompt plus one more turn appended at the end. The entire prior conversation stays a stable prefix. This is exactly the shape of coding agents and tool-calling loops, which is part of why xAI is leaning on Grok 4.5 for agentic work in the first place. If your agent framework rebuilds the message array from scratch each turn instead of appending, you're silently paying standard rates on a conversation that should be mostly cached.

Implementing Prompt Caching with the OpenAI SDK

You don't need a special caching API. Grok 4.5 caching works automatically based on prompt structure, whether you call xAI directly or through an OpenAI-compatible proxy like Grokified. The only code change to start using Grokified is the base URL and API key.

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_GROKIFIED_API_KEY",
    base_url="https://api.grokified.com/v1",
)

# Keep the system prompt and tool schema identical and first
# on every call in this session to maximize cache hits.
SYSTEM_PROMPT = "You are a code review assistant for a Python monorepo..."

def call_agent(conversation_history, new_user_turn):
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]
    messages.extend(conversation_history)          # stable prefix
    messages.append({"role": "user", "content": new_user_turn})  # new suffix

    response = client.chat.completions.create(
        model="grok-4.5",
        messages=messages,
    )
    return response.choices[0].message.content

Or with curl, for teams testing outside a full SDK integration:

curl https://api.grokified.com/v1/chat/completions \
  -H "Authorization: Bearer $GROKIFIED_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.5",
    "messages": [
      {"role": "system", "content": "You are a code review assistant..."},
      {"role": "user", "content": "Review this diff for null-pointer risks."}
    ]
  }'

That's the entire migration. Any OpenAI SDK, in any language, works against api.grokified.com/v1 by swapping the base URL and key. Nothing about your prompt structure needs to change for caching to keep working exactly as it did against the direct xAI endpoint.

Stacking Caching Savings with a Discounted Proxy

Caching cuts the rate you pay per cached token. It doesn't change the fact that you're still paying a rate. Grokified sells every Grok model at 50% off xAI's list price for your first $10,000 of usage (up to $5,000 saved), then 3% off for life after that, on top of whatever caching already saved you.

Here's what that looks like on a workload doing 50 million cached input tokens a month, on top of 20 million standard input tokens and 10 million output tokens, directly against xAI:

Token typeVolumeList rateList cost
Cached input50M$0.50/M$25.00
Standard input20M$2.00/M$40.00
Output10M$6.00/M$60.00
Total$125.00

Route the same traffic through Grokified during the discount window and the bill drops to roughly $62.50, before any additional volume discounts. That's caching and pricing arbitrage compounding instead of one canceling out the other. Neither one requires you to change models, rewrite prompts for a different vendor's format, or accept a worse model to save money. You keep Grok 4.5's coding and agentic performance and pay less for the exact same tokens.

Common Mistakes That Silently Kill Your Cache Hit Rate

  1. Timestamps or request IDs at the top of the prompt. Move them to the end of the user turn, not the system prompt.
  2. Non-deterministic retrieval ordering in RAG. Sort by a stable key, not a fluctuating relevance score.
  3. Rebuilding the message array instead of appending. Agent frameworks that reconstruct history from a database on every turn often introduce tiny formatting differences (whitespace, key ordering in JSON tool calls) that break prefix matching.
  4. Rotating system prompts per A/B test without isolating cache pools. If you're testing prompt variants, expect each variant to build its own cache independently, not share one.
  5. Assuming caching is free. It reduces the rate, it doesn't eliminate the charge. Budget for cached-rate tokens, not zero-cost tokens, when forecasting spend.

The Bottom Line

Prompt caching on Grok 4.5 is one of the highest-leverage, lowest-effort cost optimizations available right now, and it costs nothing to implement beyond disciplined prompt structuring. Most teams are leaving 75% of their input token cost on the table simply because their system prompt has a timestamp in it or their RAG pipeline reorders chunks between calls. Fix the structure, and the savings show up automatically on your next invoice.

If you're already spending real money on the Grok API, there's no reason to pay xAI list price to find out if caching works for your workload. Sign up at Grokified, get $5 in free credits with no subscription required, and swap one line of code (the base URL) to start saving 50% on top of whatever caching already gets you. Top up from $10 whenever you need more, and the discount keeps compounding on your first $10,000 of usage.

Get your Grokified API key →

Grok 4.5API PricingPrompt CachingLLM CostsDeveloper Tools
RK

Ravi Kumar

Co-founder, Grokified

Previously built billing infrastructure for two developer platforms. Writes about the unglamorous parts of running an API business.

Keep reading

All posts →