refactor: remove cache tokens from ExtraTokenTypes (#25118)

Fixes: https://github.com/coder/aibridge/issues/243

> Generated with [Coder Agents](https://coder.com/agents)
This commit is contained in:
Marcin Tojek
2026-05-18 11:30:19 +02:00
committed by GitHub
parent 0770428a5c
commit 38772bdb7c
9 changed files with 0 additions and 33 deletions
@@ -123,7 +123,6 @@ func (i *BlockingInterception) ProcessRequest(w http.ResponseWriter, r *http.Req
CacheReadInputTokens: lastUsage.PromptTokensDetails.CachedTokens,
ExtraTokenTypes: map[string]int64{
"prompt_audio": lastUsage.PromptTokensDetails.AudioTokens,
"prompt_cached": lastUsage.PromptTokensDetails.CachedTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"completion_accepted_prediction": lastUsage.CompletionTokensDetails.AcceptedPredictionTokens,
"completion_rejected_prediction": lastUsage.CompletionTokensDetails.RejectedPredictionTokens,
"completion_audio": lastUsage.CompletionTokensDetails.AudioTokens,
@@ -273,7 +273,6 @@ func (i *StreamingInterception) ProcessRequest(w http.ResponseWriter, r *http.Re
CacheReadInputTokens: lastUsage.PromptTokensDetails.CachedTokens,
ExtraTokenTypes: map[string]int64{
"prompt_audio": lastUsage.PromptTokensDetails.AudioTokens,
"prompt_cached": lastUsage.PromptTokensDetails.CachedTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"completion_accepted_prediction": lastUsage.CompletionTokensDetails.AcceptedPredictionTokens,
"completion_rejected_prediction": lastUsage.CompletionTokensDetails.RejectedPredictionTokens,
"completion_audio": lastUsage.CompletionTokensDetails.AudioTokens,
-2
View File
@@ -146,8 +146,6 @@ func (i *BlockingInterception) ProcessRequest(w http.ResponseWriter, r *http.Req
CacheWriteInputTokens: resp.Usage.CacheCreationInputTokens,
ExtraTokenTypes: map[string]int64{
"web_search_requests": resp.Usage.ServerToolUse.WebSearchRequests,
"cache_creation_input": resp.Usage.CacheCreationInputTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"cache_read_input": resp.Usage.CacheReadInputTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"cache_ephemeral_1h_input": resp.Usage.CacheCreation.Ephemeral1hInputTokens,
"cache_ephemeral_5m_input": resp.Usage.CacheCreation.Ephemeral5mInputTokens,
},
-2
View File
@@ -266,8 +266,6 @@ newStream:
CacheWriteInputTokens: start.Message.Usage.CacheCreationInputTokens,
ExtraTokenTypes: map[string]int64{
"web_search_requests": start.Message.Usage.ServerToolUse.WebSearchRequests,
"cache_creation_input": start.Message.Usage.CacheCreationInputTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"cache_read_input": start.Message.Usage.CacheReadInputTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"cache_ephemeral_1h_input": start.Message.Usage.CacheCreation.Ephemeral1hInputTokens,
"cache_ephemeral_5m_input": start.Message.Usage.CacheCreation.Ephemeral5mInputTokens,
},
-1
View File
@@ -387,7 +387,6 @@ func (i *responsesInterceptionBase) recordTokenUsage(ctx context.Context, respon
Output: usage.OutputTokens,
CacheReadInputTokens: usage.InputTokensDetails.CachedTokens,
ExtraTokenTypes: map[string]int64{
"input_cached": usage.InputTokensDetails.CachedTokens, // TODO: remove from ExtraTokenTypes (https://github.com/coder/aibridge/issues/243)
"output_reasoning": usage.OutputTokensDetails.ReasoningTokens,
"total_tokens": usage.TotalTokens,
},
@@ -312,7 +312,6 @@ func TestRecordTokenUsage(t *testing.T) {
Output: 20,
CacheReadInputTokens: 5,
ExtraTokenTypes: map[string]int64{
"input_cached": 5,
"output_reasoning": 5,
"total_tokens": 30,
},
@@ -298,7 +298,6 @@ func TestMetrics_TokenUseCount(t *testing.T) {
"output": 44,
"cache_read_input_tokens": 11904,
"cache_write_input_tokens": 0,
"input_cached": 11904,
"output_reasoning": 0,
"total_tokens": 12077,
},
@@ -315,8 +314,6 @@ func TestMetrics_TokenUseCount(t *testing.T) {
"output": 66,
"cache_read_input_tokens": 13993,
"cache_write_input_tokens": 22,
"cache_read_input": 13993,
"cache_creation_input": 22,
},
},
{
@@ -330,7 +327,6 @@ func TestMetrics_TokenUseCount(t *testing.T) {
"output": 200,
"cache_read_input_tokens": 0,
"cache_write_input_tokens": 0,
"prompt_cached": 0,
"completion_reasoning": 0,
"completion_accepted_prediction": 0,
"completion_rejected_prediction": 0,
@@ -57,7 +57,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 11,
Output: 18,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 29,
},
@@ -82,7 +81,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 58,
Output: 18,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 76,
},
@@ -100,7 +98,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Output: 44,
CacheReadInputTokens: 11904,
ExtraTokenTypes: map[string]int64{
"input_cached": 11904,
"output_reasoning": 0,
"total_tokens": 12077,
},
@@ -124,7 +121,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 64,
Output: 148,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 128,
"total_tokens": 212,
},
@@ -141,7 +137,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 48,
Output: 116,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 164,
},
@@ -158,7 +153,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 43,
Output: 129,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 172,
},
@@ -176,7 +170,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 11,
Output: 18,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 29,
},
@@ -195,7 +188,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 4006,
Output: 13,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 4019,
},
@@ -221,7 +213,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 58,
Output: 18,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 76,
},
@@ -240,7 +231,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Output: 54,
CacheReadInputTokens: 15744,
ExtraTokenTypes: map[string]int64{
"input_cached": 15744,
"output_reasoning": 0,
"total_tokens": 16963,
},
@@ -265,7 +255,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 64,
Output: 340,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 320,
"total_tokens": 404,
},
@@ -291,7 +280,6 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
Input: 43,
Output: 182,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 225,
},
@@ -764,7 +752,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Output: 75,
CacheReadInputTokens: 6144,
ExtraTokenTypes: map[string]int64{
"input_cached": 6144,
"output_reasoning": 25,
"total_tokens": 6446,
},
@@ -775,7 +762,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Output: 231,
CacheReadInputTokens: 6144,
ExtraTokenTypes: map[string]int64{
"input_cached": 6144,
"output_reasoning": 43,
"total_tokens": 6987,
},
@@ -798,7 +784,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Output: 119,
CacheReadInputTokens: 6144,
ExtraTokenTypes: map[string]int64{
"input_cached": 6144,
"output_reasoning": 70,
"total_tokens": 6496,
},
@@ -809,7 +794,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Output: 144,
CacheReadInputTokens: 6144,
ExtraTokenTypes: map[string]int64{
"input_cached": 6144,
"output_reasoning": 28,
"total_tokens": 6683,
},
@@ -829,7 +813,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Input: 6269, // 6269 input - 0 cached
Output: 18,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 6287,
},
@@ -840,7 +823,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Output: 182,
CacheReadInputTokens: 6144,
ExtraTokenTypes: map[string]int64{
"input_cached": 6144,
"output_reasoning": 0,
"total_tokens": 6645,
},
@@ -864,7 +846,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Input: 6280, // 6280 input - 0 cached
Output: 30,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 6310,
},
@@ -874,7 +855,6 @@ func TestResponsesInjectedTool(t *testing.T) {
Input: 6346, // 6346 input - 0 cached
Output: 56,
ExtraTokenTypes: map[string]int64{
"input_cached": 0,
"output_reasoning": 0,
"total_tokens": 6402,
},
@@ -271,7 +271,6 @@ func TestIntegration(t *testing.T) {
require.Len(t, tokens, 1)
require.EqualValues(t, tokens[0].InputTokens, 45)
require.EqualValues(t, tokens[0].OutputTokens, 15)
require.EqualValues(t, gjson.Get(string(tokens[0].Metadata.RawMessage), "prompt_cached").Int(), 15)
require.EqualValues(t, 15, tokens[0].CacheReadInputTokens)
tools, err := db.GetAIBridgeToolUsagesByInterceptionID(ctx, interceptions[0].ID)