File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed
Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,12 @@ export interface AnthropicMessageDeltaEvent {
157157 stop_reason ?: AnthropicResponse [ "stop_reason" ]
158158 stop_sequence ?: string | null
159159 }
160- usage ?: { output_tokens : number }
160+ usage ?: {
161+ input_tokens ?: number
162+ output_tokens : number
163+ cache_creation_input_tokens ?: number
164+ cache_read_input_tokens ?: number
165+ }
161166}
162167
163168export interface AnthropicMessageStopEvent {
Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ export function translateChunkToAnthropicEvents(
4242 stop_reason : null ,
4343 stop_sequence : null ,
4444 usage : {
45- input_tokens : 1 ,
46- output_tokens : 1 , // Anthropic requires this to be > 0
45+ input_tokens : chunk . usage ?. prompt_tokens ?? 0 ,
46+ output_tokens : 0 , // Will be updated in message_delta when finished
4747 } ,
4848 } ,
4949 } )
@@ -152,7 +152,13 @@ export function translateChunkToAnthropicEvents(
152152 stop_sequence : null ,
153153 } ,
154154 usage : {
155- output_tokens : 1 ,
155+ input_tokens : chunk . usage ?. prompt_tokens ?? 0 ,
156+ output_tokens : chunk . usage ?. completion_tokens ?? 0 ,
157+ ...( chunk . usage ?. prompt_tokens_details ?. cached_tokens
158+ !== undefined && {
159+ cache_read_input_tokens :
160+ chunk . usage . prompt_tokens_details . cached_tokens ,
161+ } ) ,
156162 } ,
157163 } ,
158164 {
Original file line number Diff line number Diff line change @@ -55,6 +55,18 @@ export interface ChatCompletionChunk {
5555 model : string
5656 choices : Array < Choice >
5757 system_fingerprint ?: string
58+ usage ?: {
59+ prompt_tokens : number
60+ completion_tokens : number
61+ total_tokens : number
62+ prompt_tokens_details ?: {
63+ cached_tokens : number
64+ }
65+ completion_tokens_details ?: {
66+ accepted_prediction_tokens : number
67+ rejected_prediction_tokens : number
68+ }
69+ }
5870}
5971
6072interface Delta {
You can’t perform that action at this time.
0 commit comments