@cavi-ai/api-client/providers/gemini
Package subpath: ./providers/gemini
buildGeminiBatchInlineEntries
Kind: function
/** Build inline batch request entries keyed by customId. */
export declare function buildGeminiBatchInlineEntries(requests: RuntimeBatchRequest[], defaultModel?: string): {
model: string;
entries: GeminiBatchInlineEntry[];
};buildGeminiBatchInputJsonl
Kind: function
/** Build JSONL for file-based batch submission. */
export declare function buildGeminiBatchInputJsonl(requests: RuntimeBatchRequest[], defaultModel?: string): {
model: string;
jsonl: string;
};buildGeminiRequestBody
Kind: function
/**
* Build the Gemini request body from the universal run-start body. Full role
* fidelity: `system`-role array messages and `instructions` both feed
* `systemInstruction`; `assistant`->`model`, everything else->`user`. Throws
* ValidationFailed if no model is resolvable.
*/
export declare function buildGeminiRequestBody(body: RuntimeRunStartBody, defaultModel?: string): {
model: string;
payload: Record<string, unknown>;
};createGeminiProviderModule
Kind: function
export declare function createGeminiProviderModule(config: GeminiApiClientOptions): RuntimeProviderModule;estimateGeminiBatchInlineBytes
Kind: function
export declare function estimateGeminiBatchInlineBytes(entries: GeminiBatchInlineEntry[]): number;flattenGeminiUsageMetadata
Kind: function
/**
* Flatten Gemini `usageMetadata` into a flat numeric record. usageMetadata is a
* flat object of token counts (promptTokenCount, candidatesTokenCount,
* totalTokenCount, cachedContentTokenCount?); newer responses add nested
* `*Details` arrays which are not named counts and are ignored. The core
* `normalizeRuntimeUsage` already aliases the Gemini keys.
*/
export declare function flattenGeminiUsageMetadata(value: unknown): Record<string, number> | undefined;GEMINI_API_BASE_URL
Kind: variable
export declare const GEMINI_API_BASE_URL = "https://generativelanguage.googleapis.com";GEMINI_API_VERSION
Kind: variable
export declare const GEMINI_API_VERSION = "v1beta";GEMINI_BATCH_INLINE_MAX_BYTES
Kind: variable
export declare const GEMINI_BATCH_INLINE_MAX_BYTES: number;GEMINI_FILES_UPLOAD_PATH
Kind: variable
export declare const GEMINI_FILES_UPLOAD_PATH = "/upload/v1beta/files";GEMINI_RUNTIME_SUPPORT
Kind: variable
export declare const GEMINI_RUNTIME_SUPPORT: Readonly<{
runs: true;
streaming: true;
batch: true;
}>;GeminiApiClient
Kind: class
export declare class GeminiApiClient extends BaseHttpApiClient implements RuntimeClient {
readonly request: HttpApiTransport;
private readonly defaultModel?;
private readonly files;
constructor(options: GeminiApiClientOptions);
getRuntimeCapabilities(): Promise<RuntimeCapabilities>;
startRun(body: RuntimeRunStartBody): Promise<RuntimeRunStatus>;
streamRun(body: RuntimeRunStartBody, handlers: RunEventStreamHandlers, options?: {
signal?: AbortSignal;
}): Promise<void>;
getRun(_runId: string): Promise<RuntimeRunStatus>;
cancelRun(_runId: string): Promise<{
status: string;
}>;
submitBatch(requests: RuntimeBatchRequest[]): Promise<RuntimeBatchStatus>;
getBatch(batchId: string): Promise<RuntimeBatchStatus>;
cancelBatch(batchId: string): Promise<RuntimeBatchStatus>;
getBatchResults(batchId: string): Promise<RuntimeBatchResult[]>;
private readBatchModel;
private stateless;
}GeminiApiClientOptions
Kind: type
export type GeminiApiClientOptions = {
/** Gemini Developer API (AI Studio) key. Keep backend-owned; do not embed in browsers/mobile. */
apiKey: string;
/** Default model when a run does not specify one. No id ships by default. */
defaultModel?: string;
baseUrl?: string;
fetchImpl?: typeof fetch;
onTrace?: HttpApiClientOptions["onTrace"];
};geminiBatchCancelPath
Kind: function
export declare function geminiBatchCancelPath(batchId: string): string;geminiBatchGenerateContentPath
Kind: function
export declare function geminiBatchGenerateContentPath(model: string): string;geminiBatchPath
Kind: function
export declare function geminiBatchPath(batchId: string): string;geminiFileDownloadPath
Kind: function
export declare function geminiFileDownloadPath(fileName: string): string;GeminiFileObject
Kind: type
export type GeminiFileObject = {
name: string;
} & Record<string, unknown>;geminiFilePath
Kind: function
export declare function geminiFilePath(fileName: string): string;GeminiFilesClient
Kind: class
/** Gemini Files API client (resumable upload + download). */
export declare class GeminiFilesClient extends BaseHttpApiClient {
readonly request: HttpApiTransport;
private readonly uploadFetch;
constructor(options: GeminiFilesClientOptions);
/** Upload text content via Google's resumable upload protocol. */
uploadFile(content: string, options?: {
displayName?: string;
mimeType?: string;
}): Promise<GeminiFileObject>;
/** Download raw file content (batch output JSONL). */
downloadFile(fileName: string): Promise<string>;
retrieveFile(fileName: string): Promise<GeminiFileObject>;
deleteFile(fileName: string): Promise<Record<string, unknown>>;
}GeminiFilesClientOptions
Kind: type
export type GeminiFilesClientOptions = {
/** Gemini Developer API (AI Studio) key. Keep backend-owned. */
apiKey: string;
baseUrl?: string;
fetchImpl?: typeof fetch;
onTrace?: HttpApiClientOptions["onTrace"];
defaultTimeoutMs?: number;
};geminiGenerateContentPath
Kind: function
export declare function geminiGenerateContentPath(model: string): string;GeminiGenerateContentResponse
Kind: type
export type GeminiGenerateContentResponse = {
candidates?: GeminiCandidate[];
promptFeedback?: {
blockReason?: string;
};
usageMetadata?: Record<string, unknown>;
modelVersion?: string;
};geminiStreamGenerateContentPath
Kind: function
export declare function geminiStreamGenerateContentPath(model: string): string;mapGeminiBatch
Kind: function
/** Map a Gemini batch job object to canonical batch status. */
export declare function mapGeminiBatch(raw: unknown): RuntimeBatchStatus;mapGeminiGenerateContentToRunStatus
Kind: function
/** Map a Gemini generateContent response to the universal run status. */
export declare function mapGeminiGenerateContentToRunStatus(model: string, response: GeminiGenerateContentResponse): RuntimeRunStatus;mapGeminiStreamChunk
Kind: function
/** Map one Gemini SSE chunk to a MESSAGE_DELTA, or null when it carries no text. */
export declare function mapGeminiStreamChunk(sse: SseMessage, runId: string): RunStreamEvent | null;normalizeGeminiBatchName
Kind: function
export declare function normalizeGeminiBatchName(batchId: string): string;parseGeminiBatchOutputJsonl
Kind: function
/** Parse file-based batch result JSONL. */
export declare function parseGeminiBatchOutputJsonl(jsonlText: string, model: string, mapResponse?: (response: GeminiGenerateContentResponse) => RuntimeRunStatus, options?: ParseGeminiBatchResultsOptions): RuntimeBatchResult[];ParseGeminiBatchResultsOptions
Kind: type
export type ParseGeminiBatchResultsOptions = {
malformedLine?: "skip" | "throw";
};parseGeminiInlineBatchResults
Kind: function
/** Parse inline batch responses from a GET batch payload. */
export declare function parseGeminiInlineBatchResults(raw: unknown, model: string, mapResponse?: (response: GeminiGenerateContentResponse) => RuntimeRunStatus): RuntimeBatchResult[];readGeminiBatchResponsesFile
Kind: function
export declare function readGeminiBatchResponsesFile(raw: unknown): string | undefined;readGeminiFinishReason
Kind: function
/** Return the first candidate's finishReason, if the chunk is terminal. */
export declare function readGeminiFinishReason(sse: SseMessage): string | null;readGeminiStreamUsage
Kind: function
/** Extract the flat usageMetadata numbers from a chunk, if present. */
export declare function readGeminiStreamUsage(sse: SseMessage): Record<string, number> | null;resolveGeminiBatchModel
Kind: function
/** Resolve one model for the whole batch; throws when models disagree or are missing. */
export declare function resolveGeminiBatchModel(requests: RuntimeBatchRequest[], defaultModel?: string): string;