Skip to content

Commit 1cccb9f

Browse files
authored
fix: Added missing costDetails property (#107)
1 parent 95be785 commit 1cccb9f

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

src/chat/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ export class OpenRouterChatLanguageModel implements LanguageModelV2 {
328328
response.usage?.completion_tokens_details?.reasoning_tokens ??
329329
0,
330330
},
331+
costDetails: {
332+
upstreamInferenceCost:
333+
response.usage?.cost_details?.upstream_inference_cost ?? 0,
334+
},
331335
},
332336
},
333337
},

src/chat/schemas.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const OpenRouterChatCompletionBaseResponseSchema = z.object({
2121
.nullish(),
2222
total_tokens: z.number(),
2323
cost: z.number().optional(),
24+
cost_details: z
25+
.object({
26+
upstream_inference_cost: z.number().nullish(),
27+
})
28+
.nullish(),
2429
})
2530
.nullish(),
2631
});

src/schemas/error-response.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
2-
import { z } from "zod/v4";
1+
import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
2+
import { z } from 'zod/v4';
33

44
export const OpenRouterErrorResponseSchema = z.object({
55
error: z.object({

src/schemas/reasoning-details.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { z } from "zod/v4";
1+
import { z } from 'zod/v4';
22

33
export enum ReasoningDetailType {
4-
Summary = "reasoning.summary",
5-
Encrypted = "reasoning.encrypted",
6-
Text = "reasoning.text",
4+
Summary = 'reasoning.summary',
5+
Encrypted = 'reasoning.encrypted',
6+
Text = 'reasoning.text',
77
}
88

99
export const ReasoningDetailSummarySchema = z.object({

src/tests/usage-accounting.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ describe('OpenRouter Usage Accounting', () => {
3737
},
3838
total_tokens: 30,
3939
cost: 0.0015,
40+
cost_details: {
41+
upstream_inference_cost: 19,
42+
},
4043
}
4144
: undefined,
4245
};
@@ -165,6 +168,9 @@ describe('OpenRouter Usage Accounting', () => {
165168
completionTokens: 20,
166169
totalTokens: 30,
167170
cost: 0.0015,
171+
costDetails: {
172+
upstreamInferenceCost: 19,
173+
},
168174
promptTokensDetails: {
169175
cachedTokens: 5,
170176
},

src/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ export type OpenRouterUsageAccounting = {
6464
};
6565
totalTokens: number;
6666
cost?: number;
67+
costDetails: {
68+
upstreamInferenceCost: number;
69+
};
6770
};

0 commit comments

Comments
 (0)