[GH-ISSUE #24804] issue: Prompt Caching Not Working Consistently with Grok #107398

Closed
opened 2026-05-18 06:12:08 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @mysteryx93 on GitHub (May 16, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/24804

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.9.5

Ollama Version (if applicable)

No response

Operating System

Garuda Linux

Browser (if applicable)

Firedragon

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

With Grok model, prompt should use the prompt cache to reduce token costs. In response Info, cached_tokens should be high for consecutive requests within 5 minutes.

Actual Behavior

cache_tokens stays 64 or 128 or other such values, billing me the message history at full cost on every request. Sometimes it caches, often it doesn't. Leaving temperature and top_p to default values seems to help; it's worse with custom values.

Steps to Reproduce

  1. Add Connection to xAI (https://api.x.ai/v1)
  2. Use model grok-4.3
  3. Set temperature=.57 and top_p=0.84
  4. Enable Usage display on model
  5. Send multiple prompts and check cached_tokens

Logs & Screenshots

I think the issue has been diagnosed here:
Grok prompt caching likely misses xAI server-affinity header
https://github.com/NousResearch/hermes-agent/issues/22705

Additional Information

I'm pretty sure server-affinity header is the issue, since it works but inconsistent. It depends what servers the request gets routed to.

Originally created by @mysteryx93 on GitHub (May 16, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/24804 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.9.5 ### Ollama Version (if applicable) _No response_ ### Operating System Garuda Linux ### Browser (if applicable) Firedragon ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior With Grok model, prompt should use the prompt cache to reduce token costs. In response Info, `cached_tokens` should be high for consecutive requests within 5 minutes. ### Actual Behavior `cache_tokens` stays 64 or 128 or other such values, billing me the message history at full cost on every request. Sometimes it caches, often it doesn't. Leaving temperature and top_p to default values seems to help; it's worse with custom values. ### Steps to Reproduce 1. Add Connection to xAI (https://api.x.ai/v1) 2. Use model `grok-4.3` 3. Set `temperature=.57` and `top_p=0.84` 4. Enable `Usage` display on model 5. Send multiple prompts and check `cached_tokens` ### Logs & Screenshots I think the issue has been diagnosed here: Grok prompt caching likely misses xAI server-affinity header https://github.com/NousResearch/hermes-agent/issues/22705 ### Additional Information I'm pretty sure server-affinity header is the issue, since it works but inconsistent. It depends what servers the request gets routed to.
GiteaMirror added the bug label 2026-05-18 06:12:08 -05:00
Author
Owner

@owui-terminator[bot] commented on GitHub (May 16, 2026):

🔍 Related Issues Found

I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions:

  1. 🟣 #22791 issue: Open WebUI API: incomplete / dropped output with latest Grok models via /api/v1/chat/completions, while older Grok and OpenAI models work
    This is the closest Grok/xAI-related issue in Open WebUI. It also concerns latest Grok models behaving inconsistently through Open WebUI’s chat completions path, so it may share the same provider-specific request handling or routing behavior.
    by Patrick-0815 · bug

  2. 🟣 #12058 issue: Cached tokens out of nowhere
    This issue is about unexpected cached token behavior and inflated token usage, which overlaps with the core symptom here even though it was reported with a different backend. It’s relevant as a prior caching-related bug in Open WebUI.
    by davidvpe · bug


💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead.

This comment was generated automatically. React with 👍 if helpful, 👎 if not.

<!-- gh-comment-id:4465439653 --> @owui-terminator[bot] commented on GitHub (May 16, 2026): <!-- terminator-bot:related-issues-reply --> 🔍 **Related Issues Found** I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions: 1. 🟣 [#22791](https://github.com/open-webui/open-webui/issues/22791) **issue: Open WebUI API: incomplete / dropped output with latest Grok models via /api/v1/chat/completions, while older Grok and OpenAI models work** *This is the closest Grok/xAI-related issue in Open WebUI. It also concerns latest Grok models behaving inconsistently through Open WebUI’s chat completions path, so it may share the same provider-specific request handling or routing behavior.* *by Patrick-0815 · `bug`* 2. 🟣 [#12058](https://github.com/open-webui/open-webui/issues/12058) **issue: Cached tokens out of nowhere** *This issue is about unexpected cached token behavior and inflated token usage, which overlaps with the core symptom here even though it was reported with a different backend. It’s relevant as a prior caching-related bug in Open WebUI.* *by davidvpe · `bug`* --- 💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead. *This comment was generated automatically.* React with 👍 if helpful, 👎 if not.
Author
Owner

@mysteryx93 commented on GitHub (May 16, 2026):

Here is a diagnostic and fix that was implemented in another project
https://github.com/NousResearch/hermes-agent/pull/22809

<!-- gh-comment-id:4465493613 --> @mysteryx93 commented on GitHub (May 16, 2026): Here is a diagnostic and fix that was implemented in another project https://github.com/NousResearch/hermes-agent/pull/22809
Author
Owner

@Classic298 commented on GitHub (May 16, 2026):

very likely provider or config issue.

Even on providers where caching works, sometimes you still get a cache miss due to location differences.

Open WebUI is fully chat completions standard conform - if you get cache misses, then that's an upstream issue of either the provider or the provider demanding special headers that open webui doesn't send (i.e. you forgot to configure).

Also check if grok even does caching if you do off-default temperature and top p values. Many providers nowadays will refuse to do reasoning or answer at all with off-default values

<!-- gh-comment-id:4466366203 --> @Classic298 commented on GitHub (May 16, 2026): very likely provider or config issue. Even on providers where caching works, sometimes you still get a cache miss due to location differences. Open WebUI is fully chat completions standard conform - if you get cache misses, then that's an upstream issue of either the provider or the provider demanding special headers that open webui doesn't send (i.e. you forgot to configure). Also check if grok even does caching if you do off-default temperature and top p values. Many providers nowadays will refuse to do reasoning or answer at all with off-default values
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#107398