-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
According to the OpenRouter Usage Accounting documentation, the usage object in API responses should include cost and cost_details fields:
The usage response includes detailed cost information:
cost: The total amount charged to your accountcost_details.upstream_inference_cost: The actual cost charged by the upstream AI provider
However, the SDK's ChatGenerationTokenUsage type only includes token-related fields and does not expose the cost information.
Current SDK type definition
// From @openrouter/sdk/esm/models/chatgenerationtokenusage.d.ts
export type ChatGenerationTokenUsage = {
completionTokens: number;
promptTokens: number;
totalTokens: number;
completionTokensDetails?: CompletionTokensDetails | null | undefined;
promptTokensDetails?: PromptTokensDetails | null | undefined;
};Expected type definition
export type ChatGenerationTokenUsage = {
completionTokens: number;
promptTokens: number;
totalTokens: number;
completionTokensDetails?: CompletionTokensDetails | null | undefined;
promptTokensDetails?: PromptTokensDetails | null | undefined;
cost?: number | null | undefined;
costDetails?: {
upstreamInferenceCost?: number | null | undefined;
} | undefined;
};Steps to reproduce
- Install @openrouter/sdk@0.5.1
- Make a chat completion request (streaming or non-streaming)
- Access response.usage or the final streaming chunk's usage
- Observe that cost and cost_details are not available on the typed object
Actual API response
The raw API response includes cost data:
{
"usage": {
"completion_tokens": 68,
"prompt_tokens": 515,
"total_tokens": 583,
"completion_tokens_details": {
"reasoning_tokens": 0
},
"prompt_tokens_details": {
"cached_tokens": 159
},
"cost": 0.00123,
"cost_details": {
"upstream_inference_cost": null
}
}
}Environment
- SDK version: 0.5.1
- Node.js version: 25.6.0
Additional context
The OpenResponsesUsage type in the SDK does include cost and costDetails fields, but ChatGenerationTokenUsage (used for chat completions) does not.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels