mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
[fix] Add cache token capture for Droid OpenAI endpoint
The _parseOpenAIUsageFromSSE method was not capturing cache-related tokens (cache_read_input_tokens, cache_creation_input_tokens) from OpenAI format responses, while the Anthropic endpoint correctly captured them. This fix adds extraction of: - cached_tokens from input_tokens_details - cache_creation_input_tokens from both input_tokens_details and top-level usage object This ensures proper cache statistics tracking and cost calculation for OpenAI models (like GPT-5/Codex) when using the Droid provider. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -737,6 +737,14 @@ class DroidRelayService {
|
||||
currentUsageData.output_tokens = 0
|
||||
}
|
||||
|
||||
// Capture cache tokens from OpenAI format
|
||||
currentUsageData.cache_read_input_tokens =
|
||||
data.usage.input_tokens_details?.cached_tokens || 0
|
||||
currentUsageData.cache_creation_input_tokens =
|
||||
data.usage.input_tokens_details?.cache_creation_input_tokens ||
|
||||
data.usage.cache_creation_input_tokens ||
|
||||
0
|
||||
|
||||
logger.debug('📊 Droid OpenAI usage:', currentUsageData)
|
||||
}
|
||||
|
||||
@@ -758,6 +766,14 @@ class DroidRelayService {
|
||||
currentUsageData.output_tokens = 0
|
||||
}
|
||||
|
||||
// Capture cache tokens from OpenAI Response API format
|
||||
currentUsageData.cache_read_input_tokens =
|
||||
usage.input_tokens_details?.cached_tokens || 0
|
||||
currentUsageData.cache_creation_input_tokens =
|
||||
usage.input_tokens_details?.cache_creation_input_tokens ||
|
||||
usage.cache_creation_input_tokens ||
|
||||
0
|
||||
|
||||
logger.debug('📊 Droid OpenAI response usage:', currentUsageData)
|
||||
}
|
||||
} catch (parseError) {
|
||||
|
||||
Reference in New Issue
Block a user