mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 10:10:56 -07:00
feat(billing): implement G1 AI credits overage flow with billing telemetry (#18590)
This commit is contained in:
@@ -28,12 +28,14 @@ import type {
|
||||
} from '@google/genai';
|
||||
import { GenerateContentResponse } from '@google/genai';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
import type { Credits } from './types.js';
|
||||
|
||||
export interface CAGenerateContentRequest {
|
||||
model: string;
|
||||
project?: string;
|
||||
user_prompt_id?: string;
|
||||
request: VertexGenerateContentRequest;
|
||||
enabled_credit_types?: string[];
|
||||
}
|
||||
|
||||
interface VertexGenerateContentRequest {
|
||||
@@ -75,6 +77,8 @@ interface VertexGenerationConfig {
|
||||
export interface CaGenerateContentResponse {
|
||||
response?: VertexGenerateContentResponse;
|
||||
traceId?: string;
|
||||
consumedCredits?: Credits[];
|
||||
remainingCredits?: Credits[];
|
||||
}
|
||||
|
||||
interface VertexGenerateContentResponse {
|
||||
@@ -127,12 +131,14 @@ export function toGenerateContentRequest(
|
||||
userPromptId: string,
|
||||
project?: string,
|
||||
sessionId?: string,
|
||||
enabledCreditTypes?: string[],
|
||||
): CAGenerateContentRequest {
|
||||
return {
|
||||
model: req.model,
|
||||
project,
|
||||
user_prompt_id: userPromptId,
|
||||
request: toVertexGenerateContentRequest(req, sessionId),
|
||||
enabled_credit_types: enabledCreditTypes,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -305,3 +311,16 @@ function toVertexGenerationConfig(
|
||||
thinkingConfig: config.thinkingConfig,
|
||||
};
|
||||
}
|
||||
|
||||
export function fromGenerateContentResponseUsage(
|
||||
metadata?: GenerateContentResponseUsageMetadata,
|
||||
): GenerateContentResponseUsageMetadata | undefined {
|
||||
if (!metadata) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
promptTokenCount: metadata.promptTokenCount,
|
||||
candidatesTokenCount: metadata.candidatesTokenCount,
|
||||
totalTokenCount: metadata.totalTokenCount,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user