Commit graph

17437 commits

Author SHA1 Message Date
Claude
c98e8decd4
fix: correct cache-token accounting and stream_options handling in Anthropic-compat usage
Adversarial review of the previous commit surfaced three defects:

- Cached tokens were double counted: OpenAI's prompt_tokens includes
  cached tokens while Anthropic's input_tokens excludes them (total
  input = input_tokens + cache_creation_input_tokens +
  cache_read_input_tokens). The converter passed the inclusive count
  through as input_tokens while also emitting the cache fields, so a
  {prompt_tokens: 1000, cached_tokens: 800} response claimed 1800 input
  tokens to Anthropic clients. Cache counts are now subtracted whenever
  the input count is derived from prompt_tokens; an Anthropic-native
  input_tokens key is taken as already exclusive.
- A model with stream_response=Off flips the stream flag after the
  payload conversion injected stream_options, and upstreams like OpenAI
  and vLLM reject stream:false requests carrying stream_options with
  HTTP 400. The OpenAI router now drops stream_options from any
  non-streaming payload before sending; this also covers the
  pre-existing variant where the web UI sends stream_options for models
  with the usage capability enabled.
- The streaming usage capture lacked the null/zero hardening the
  non-streaming path already had: explicit null token values leaked
  JSON null into message_delta usage (breaking schema-validating
  Anthropic SDK clients), and a reported 0 (e.g. Ollama omitting
  prompt_eval_count for KV-cached prompts) clobbered the pre-counted
  input_tokens. Both paths now share one hardened extraction helper
  that treats missing/null/0 counts as unreported.

Ref: https://github.com/open-webui/docs/issues/1328

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0119K4sbiCAFKq9rFaS6i5ij
2026-07-21 15:02:45 +00:00
Claude
3e80c10e91
fix: preserve upstream token usage in Anthropic-compatible Messages API
The /api/v1/messages compatibility endpoint dropped most token statistics
reported by the upstream model:

- Streaming requests never asked OpenAI-compatible upstreams for usage,
  so the final message_delta always reported output_tokens: 0. The
  converted payload now sets stream_options.include_usage, which Azure
  connections already gate by API version and the Ollama conversion
  drops harmlessly.
- The final message_delta now carries the full upstream-reported usage
  (input_tokens plus cache statistics) instead of only output_tokens,
  matching Anthropic's MessageDeltaUsage shape.
- Non-streaming responses preferred the locally pre-counted input_tokens
  over the upstream-reported value; the local count is now only a
  fallback when the upstream reports nothing.
- Cache statistics reported in OpenAI form
  (prompt_tokens_details.cached_tokens) are now mapped to
  cache_read_input_tokens in both streaming and non-streaming responses.

Ref: https://github.com/open-webui/docs/issues/1328

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0119K4sbiCAFKq9rFaS6i5ij
2026-07-21 14:41:22 +00:00
Timothy Jaeryang Baek
86efecd9ad refac 2026-07-20 22:45:50 -04:00
Timothy Jaeryang Baek
8631dc83dc refac 2026-07-20 22:27:13 -04:00
Timothy Jaeryang Baek
6940297486 refac 2026-07-20 22:27:09 -04:00
Timothy Jaeryang Baek
49e57f4e7e chore: format 2026-07-20 22:11:42 -04:00
Timothy Jaeryang Baek
4a42543fc3 refac 2026-07-20 22:11:16 -04:00
Timothy Jaeryang Baek
e88d2e053c refac 2026-07-20 22:10:11 -04:00
Timothy Jaeryang Baek
704d07e9a2 refac 2026-07-20 22:04:39 -04:00
Timothy Jaeryang Baek
bc8d24c951 refac 2026-07-20 22:03:31 -04:00
Timothy Jaeryang Baek
1428a4ddce refac 2026-07-20 21:44:12 -04:00
Timothy Jaeryang Baek
0c7ddbdb4f refac 2026-07-20 19:49:34 -04:00
Timothy Jaeryang Baek
2fcb36267f refac
Some checks are pending
Python CI / Ruff Format (3.11) (push) Waiting to run
Python CI / Ruff Format (3.12) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args: free_disk:false name:main suffix:]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Waiting to run
Create and publish Docker images with specific build args / notify-helm-charts (push) Blocked by required conditions
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Waiting to run
Create and publish Docker images with specific build args / copy-to-dockerhub (, main) (push) Blocked by required conditions
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args: free_disk:false name:main suffix:]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Waiting to run
Create and publish Docker images with specific build args / merge (map[name:cuda suffix:-cuda]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge (map[name:cuda126 suffix:-cuda126]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge (map[name:main suffix:]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge (map[name:slim suffix:-slim]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda, cuda) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda126, cuda126) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-ollama, ollama) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-slim, slim) (push) Blocked by required conditions
Frontend Build / Unit Tests (push) Waiting to run
Frontend Build / Format & Build (push) Waiting to run
Create and publish Docker images with specific build args / merge (map[name:ollama suffix:-ollama]) (push) Blocked by required conditions
2026-07-20 01:33:53 -04:00
Timothy Jaeryang Baek
af9a315ac3 refac 2026-07-20 01:33:47 -04:00
Timothy Jaeryang Baek
6e5efc1f75 refac 2026-07-20 01:21:15 -04:00
Timothy Jaeryang Baek
4da2ff2655 refac 2026-07-20 00:25:37 -04:00
Timothy Jaeryang Baek
d3ea51fd46 refac 2026-07-20 00:23:01 -04:00
Timothy Jaeryang Baek
2dbdba1f91 refac
Some checks failed
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args: free_disk:false name:main suffix:]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args: free_disk:false name:main suffix:]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Has been cancelled
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Has been cancelled
Frontend Build / Unit Tests (push) Has been cancelled
Frontend Build / Format & Build (push) Has been cancelled
Create and publish Docker images with specific build args / notify-helm-charts (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (, main) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda, cuda) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:cuda suffix:-cuda]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:cuda126 suffix:-cuda126]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:main suffix:]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:ollama suffix:-ollama]) (push) Has been cancelled
Create and publish Docker images with specific build args / merge (map[name:slim suffix:-slim]) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda126, cuda126) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-ollama, ollama) (push) Has been cancelled
Create and publish Docker images with specific build args / copy-to-dockerhub (-slim, slim) (push) Has been cancelled
2026-07-17 23:39:49 -04:00
Timothy Jaeryang Baek
1a32d92d08 refac
Some checks failed
Create and publish Docker images with specific build args / merge (map[name:main suffix:]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge (map[name:ollama suffix:-ollama]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge (map[name:slim suffix:-slim]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / notify-helm-charts (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (, main) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda, cuda) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-cuda126, cuda126) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-ollama, ollama) (push) Blocked by required conditions
Create and publish Docker images with specific build args / copy-to-dockerhub (-slim, slim) (push) Blocked by required conditions
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args: free_disk:false name:main suffix:]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/amd64 runner:ubuntu-latest], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args: free_disk:false name:main suffix:]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true USE_CUDA_VER=cu126 free_disk:true name:cuda126 suffix:-cuda126]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_CUDA=true free_disk:true name:cuda suffix:-cuda]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_OLLAMA=true free_disk:false name:ollama suffix:-ollama]) (push) Waiting to run
Create and publish Docker images with specific build args / build (map[arch:linux/arm64 runner:ubuntu-24.04-arm], map[build_args:USE_SLIM=true free_disk:false name:slim suffix:-slim]) (push) Waiting to run
Create and publish Docker images with specific build args / merge (map[name:cuda suffix:-cuda]) (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge (map[name:cuda126 suffix:-cuda126]) (push) Blocked by required conditions
Frontend Build / Format & Build (push) Waiting to run
Frontend Build / Unit Tests (push) Waiting to run
Python CI / Ruff Format (3.11) (push) Has been cancelled
Python CI / Ruff Format (3.12) (push) Has been cancelled
2026-07-17 06:50:16 -04:00
Timothy Jaeryang Baek
b2f7ecd83a refac 2026-07-17 06:45:00 -04:00
Timothy Jaeryang Baek
59c75f569b refac 2026-07-17 06:38:10 -04:00
Timothy Jaeryang Baek
f192657dc9 refac 2026-07-17 06:35:24 -04:00
Timothy Jaeryang Baek
9281adc564 refac 2026-07-17 06:34:17 -04:00
Timothy Jaeryang Baek
fd07e3a8e3 refac 2026-07-17 06:30:04 -04:00
Timothy Jaeryang Baek
f3a3550784 refac 2026-07-17 06:29:19 -04:00
Timothy Jaeryang Baek
890bfd0d97 refac 2026-07-17 06:28:07 -04:00
Timothy Jaeryang Baek
ff49217206 refac 2026-07-17 06:22:15 -04:00
Timothy Jaeryang Baek
1bf05ebc7d refac 2026-07-17 06:06:23 -04:00
Timothy Jaeryang Baek
cda5bdb9d4 refac 2026-07-17 05:51:39 -04:00
Timothy Jaeryang Baek
ea2e3d0afc refac 2026-07-17 05:48:41 -04:00
Timothy Jaeryang Baek
437c06c479 refac 2026-07-17 05:46:09 -04:00
Timothy Jaeryang Baek
d027a32ed1 refac 2026-07-17 05:40:40 -04:00
Timothy Jaeryang Baek
21e180182a refac 2026-07-17 05:34:00 -04:00
Timothy Jaeryang Baek
2d83c7438c refac 2026-07-17 05:32:50 -04:00
Timothy Jaeryang Baek
d0bea60581 refac 2026-07-17 05:31:32 -04:00
Timothy Jaeryang Baek
421da67446 refac 2026-07-17 05:15:09 -04:00
Timothy Jaeryang Baek
6fcb38fe2e refac 2026-07-17 05:12:16 -04:00
Timothy Jaeryang Baek
5424ac5891 refac 2026-07-17 05:09:29 -04:00
Timothy Jaeryang Baek
3316ba76aa refac 2026-07-17 04:54:44 -04:00
Timothy Jaeryang Baek
e5e2cd7876 refac 2026-07-17 04:48:21 -04:00
Timothy Jaeryang Baek
56f2cb5302 refac 2026-07-17 04:11:11 -04:00
Timothy Jaeryang Baek
a213355785 refac 2026-07-17 04:09:33 -04:00
Timothy Jaeryang Baek
ab519e40d9 refac 2026-07-17 03:41:51 -04:00
Timothy Jaeryang Baek
af8cc6c91a refac 2026-07-17 03:40:28 -04:00
Timothy Jaeryang Baek
88c6b8bc5c refac 2026-07-17 03:30:44 -04:00
Timothy Jaeryang Baek
203953faa2 refac 2026-07-17 03:28:45 -04:00
Timothy Jaeryang Baek
741ce0c239 refac 2026-07-17 03:24:55 -04:00
Timothy Jaeryang Baek
a6fcc61a16 refac 2026-07-17 00:55:24 -04:00
Timothy Jaeryang Baek
ce44b90eae refac 2026-07-17 00:54:13 -04:00
Timothy Jaeryang Baek
27d7eafcd9 refac 2026-07-17 00:16:01 -04:00