Skip to content

Commit 6a37ada

Browse files
committed
feat: update usage structure in message events and chat completion types
1 parent d391aad commit 6a37ada

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/routes/messages/anthropic-types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ 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+
}
161164
}
162165

163166
export interface AnthropicMessageStopEvent {

src/routes/messages/stream-translation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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,8 @@ 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,
156157
},
157158
},
158159
{

src/services/copilot/create-chat-completions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ 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+
}
5866
}
5967

6068
interface Delta {

0 commit comments

Comments
 (0)