[PR #13934] [MERGED] anthropic: add InputTokens to streaming response #14448

Closed
opened 2026-04-13 00:54:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13934
Author: @avukmirovich
Created: 1/27/2026
Status: Merged
Merged: 2/3/2026
Merged by: @ParthSareen

Base: mainHead: anthropic-prompt-tokens-metric


📝 Commits (2)

  • af9d9e0 anthropic: add InputTokens to streaming response
  • a546865 fix lint

📊 Changes

2 files changed (+22 additions, -1 deletions)

View changed files

📝 anthropic/anthropic.go (+3 -0)
📝 anthropic/anthropic_test.go (+19 -1)

📄 Description

This PR adds InputTokens field into Usage field of response for streaming request to /v1/messages endpoint.

Additional details.
I wrote tiny HTTP-proxy script to collect tokens usage from Ollama's responses. For requests to /v1/chat endpoints it works fine. But for streaming variant for /v1/messages endpoint there is no data about prompt tokens usage. Non-streaming variant works fine.

Before this PR, response contains next data:

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":62}}

In usage there is only output_tokens field.

After this PR, response will contain next data:

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{{"input_tokens":74,"output_tokens":62}}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13934 **Author:** [@avukmirovich](https://github.com/avukmirovich) **Created:** 1/27/2026 **Status:** ✅ Merged **Merged:** 2/3/2026 **Merged by:** [@ParthSareen](https://github.com/ParthSareen) **Base:** `main` ← **Head:** `anthropic-prompt-tokens-metric` --- ### 📝 Commits (2) - [`af9d9e0`](https://github.com/ollama/ollama/commit/af9d9e0160164842ce78db6d840dd282fead034d) anthropic: add InputTokens to streaming response - [`a546865`](https://github.com/ollama/ollama/commit/a5468654969c170d36ee184bc226025ecb2ddea0) fix lint ### 📊 Changes **2 files changed** (+22 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `anthropic/anthropic.go` (+3 -0) 📝 `anthropic/anthropic_test.go` (+19 -1) </details> ### 📄 Description This PR adds `InputTokens` field into `Usage` field of response for streaming request to `/v1/messages` endpoint. Additional details. I wrote tiny HTTP-proxy script to collect tokens usage from Ollama's responses. For requests to `/v1/chat` endpoints it works fine. But for streaming variant for `/v1/messages` endpoint there is no data about prompt tokens usage. Non-streaming variant works fine. Before this PR, response contains next data: ``` event: message_delta data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":62}} ``` In `usage` there is only `output_tokens` field. After this PR, response will contain next data: ``` event: message_delta data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{{"input_tokens":74,"output_tokens":62}} ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 00:54:27 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#14448