New:Socket for Asana Is Now Available.Learn more
Get Started

@ai-sdk/google

Package Overview
Dependencies
Maintainers
3
Versions
641
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/google - npm Package Compare versions

Comparing version
4.0.53
to
4.0.54
+50
src/transcription/google-transcription-model-options.ts
import { z } from 'zod/v4';
export type GoogleTranscriptionModelId =
| 'gemini-3.5-transcribe'
| 'gemini-3.5-transcribe-live'
| (string & {});
/**
* Speech recognition options shared by unary (`gemini-3.5-transcribe`) and
* live (`gemini-3.5-transcribe-live`) transcription. Maps onto Google's
* `AudioTranscriptionConfig`.
*/
export const googleTranscriptionModelOptions = z.object({
/**
* BCP-47 language codes providing hints about the languages present in the
* audio. If omitted or empty, defaults to automatic language detection.
*/
languageCodes: z.array(z.string()).optional(),
/**
* Custom vocabulary phrases, which bias the speech recognition model
* toward recognizing specific terms.
*/
customVocabulary: z.array(z.string()).optional(),
/**
* Enables word-level timestamp generation.
*/
wordTimestamp: z.boolean().optional(),
/**
* Enables speaker diarization.
*/
diarization: z.boolean().optional(),
/**
* Transcription output formatting mode.
*
* - `VERBATIM` (default): exact literal transcript preserving filler
* words, repetitions, and false starts.
* - `SMART`: cleans up and structures the transcript in real time —
* disfluency removal, inline self-corrections, structured formatting
* (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
*/
mode: z.enum(['SMART', 'VERBATIM']).optional(),
});
export type GoogleTranscriptionModelOptions = z.infer<
typeof googleTranscriptionModelOptions
>;
import {
InvalidArgumentError,
type Experimental_TranscriptionModelV4StreamOptions as TranscriptionModelV4StreamOptions,
type Experimental_TranscriptionModelV4StreamPart as TranscriptionModelV4StreamPart,
type JSONObject,
type SharedV4Warning,
type TranscriptionModelV4,
} from '@ai-sdk/provider';
import {
combineHeaders,
connectToWebSocket,
convertToBase64,
createJsonResponseHandler,
parseProviderOptions,
postJsonToApi,
resolve,
safeParseJSON,
serializeModelOptions,
waitForWebSocketBufferDrain,
WORKFLOW_DESERIALIZE,
WORKFLOW_SERIALIZE,
type FetchFunction,
type Resolvable,
type WebSocketConnection,
type WebSocketConstructor,
type WebSocketLike,
} from '@ai-sdk/provider-utils';
import { z } from 'zod/v4';
import { getModelPath } from '../get-model-path';
import { getRealtimeWebSocketURL } from '../get-realtime-base-url';
import { googleFailedResponseHandler } from '../google-error';
import {
googleTranscriptionModelOptions,
type GoogleTranscriptionModelId,
type GoogleTranscriptionModelOptions,
} from './google-transcription-model-options';
const liveWebSocketPath =
'google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent';
/**
* After the input audio has ended, finish when no terminal signal
* (`turnComplete` / idle `interactionStatus`) arrives within this window.
* Trailing transcripts reset the timer.
*/
const defaultFinishGraceMs = 3000;
function getLiveWebSocketURL(baseURL: string, apiKey: string): URL {
const url = getRealtimeWebSocketURL(baseURL, liveWebSocketPath);
url.searchParams.set('key', apiKey);
return url;
}
/** Live transcription is only supported by `*-live` model variants. */
function isLiveTranscriptionModelId(modelId: string): boolean {
return modelId.includes('-live');
}
type GoogleLiveWordInfo = {
text?: string;
word?: string;
startOffset?: string;
endOffset?: string;
};
type GoogleLiveTranscription = {
text?: string;
finished?: boolean;
languageCode?: string;
speakerLabel?: string;
words?: GoogleLiveWordInfo[];
};
type GoogleLiveServerMessage = {
setupComplete?: unknown;
serverContent?: {
inputTranscription?: GoogleLiveTranscription;
interimInputTranscription?: GoogleLiveTranscription;
turnComplete?: boolean;
generationComplete?: boolean;
interactionStatus?: string;
};
inputTranscription?: GoogleLiveTranscription;
usageMetadata?: JSONObject;
error?: { message?: string };
};
interface GoogleTranscriptionModelConfig {
provider: string;
baseURL: string;
headers?: Resolvable<Record<string, string | undefined>>;
fetch?: FetchFunction;
webSocket?: WebSocketConstructor;
_internal?: {
currentDate?: () => Date;
finishGraceMs?: number;
};
}
export class GoogleTranscriptionModel implements TranscriptionModelV4 {
readonly specificationVersion = 'v4';
static [WORKFLOW_SERIALIZE](model: GoogleTranscriptionModel) {
return serializeModelOptions({
modelId: model.modelId,
config: model.config,
});
}
static [WORKFLOW_DESERIALIZE](options: {
modelId: GoogleTranscriptionModelId;
config: GoogleTranscriptionModelConfig;
}) {
return new GoogleTranscriptionModel(options.modelId, options.config);
}
get provider(): string {
return this.config.provider;
}
constructor(
readonly modelId: GoogleTranscriptionModelId,
private readonly config: GoogleTranscriptionModelConfig,
) {}
private async parseOptions(
providerOptions: Record<string, unknown> | undefined,
): Promise<GoogleTranscriptionModelOptions | undefined> {
return parseProviderOptions({
provider: 'google',
providerOptions,
schema: googleTranscriptionModelOptions,
});
}
async doGenerate(
options: Parameters<TranscriptionModelV4['doGenerate']>[0],
): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
if (isLiveTranscriptionModelId(this.modelId)) {
throw new InvalidArgumentError({
argument: 'modelId',
message:
`Model '${this.modelId}' only supports streaming transcription. ` +
`Use experimental_streamTranscribe, or a unary model such as 'gemini-3.5-transcribe'.`,
});
}
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
const warnings: SharedV4Warning[] = [];
const googleOptions = await this.parseOptions(options.providerOptions);
const transcriptionConfig = buildTranscriptionConfig(googleOptions);
// Unary transcription is served by the Interactions API
// (https://ai.google.dev/gemini-api/docs/transcribe).
const requestBody = {
model: this.modelId,
input: [
{
type: 'audio',
data: convertToBase64(options.audio),
mime_type: options.mediaType,
},
],
...(transcriptionConfig != null
? { generation_config: { transcription_config: transcriptionConfig } }
: {}),
};
const {
value: response,
responseHeaders,
rawValue: rawResponse,
} = await postJsonToApi({
url: `${this.config.baseURL}/interactions`,
headers: combineHeaders(
this.config.headers ? await resolve(this.config.headers) : undefined,
options.headers,
),
body: requestBody,
failedResponseHandler: googleFailedResponseHandler,
successfulResponseHandler: createJsonResponseHandler(
googleInteractionsTranscriptionResponseSchema,
),
abortSignal: options.abortSignal,
fetch: this.config.fetch,
});
let text = '';
const segments: Array<{
text: string;
startSecond: number;
endSecond: number;
}> = [];
for (const step of response.steps ?? []) {
for (const content of step.content ?? []) {
if (content.type !== 'text' || content.text == null) continue;
text += content.text;
for (const annotation of content.annotations ?? []) {
if (annotation.type !== 'word_info') continue;
const startSecond = parseOffsetSeconds(annotation.start_offset);
const endSecond = parseOffsetSeconds(annotation.end_offset);
if (
annotation.text == null ||
startSecond == null ||
endSecond == null
) {
continue;
}
segments.push({ text: annotation.text, startSecond, endSecond });
}
}
}
return {
text,
segments,
language: undefined,
durationInSeconds: undefined,
warnings,
response: {
timestamp: currentDate,
modelId: this.modelId,
headers: responseHeaders,
body: rawResponse,
},
...(response.usage != null
? {
providerMetadata: {
google: { usage: response.usage as JSONObject },
},
}
: {}),
};
}
async doStream(
options: TranscriptionModelV4StreamOptions,
): Promise<
Awaited<ReturnType<NonNullable<TranscriptionModelV4['doStream']>>>
> {
if (!isLiveTranscriptionModelId(this.modelId)) {
throw new InvalidArgumentError({
argument: 'modelId',
message:
`Model '${this.modelId}' does not support streaming transcription. ` +
`Use a live model such as 'gemini-3.5-transcribe-live'.`,
});
}
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
const warnings: SharedV4Warning[] = [];
const googleOptions = await this.parseOptions(options.providerOptions);
validateLiveInputAudioFormat(options.inputAudioFormat);
const headers = combineHeaders(
this.config.headers ? await resolve(this.config.headers) : undefined,
options.headers,
);
// last case-variant wins: combineHeaders keeps case-distinct keys and
// spreads per-call headers after configuration headers
let apiKey: string | undefined;
for (const [key, value] of Object.entries(headers)) {
if (key.toLowerCase() === 'x-goog-api-key' && value != null) {
apiKey = value;
}
}
if (apiKey == null) {
throw new Error(
'Google Generative AI API key is required for streaming transcription.',
);
}
const webSocketHeaders = Object.fromEntries(
Object.entries(headers).filter(
([key]) => key.toLowerCase() !== 'x-goog-api-key',
),
);
// NOTE: Google's GA announcement shows the setup with
// `generationConfig: { responseModalities: ['TEXT'] }`, but sending it
// suppresses the final `inputTranscription` segments on the current
// endpoint (only interim partials arrive). Omit generationConfig — the
// empirically working shape — until the endpoint honors the documented
// form.
const setup = {
model: getModelPath(this.modelId),
inputAudioTranscription:
buildAudioTranscriptionConfig(googleOptions) ?? {},
};
return {
request: { body: setup },
response: {
timestamp: currentDate,
modelId: this.modelId,
},
stream: createGoogleLiveTranscriptionStream({
webSocket: this.config.webSocket,
url: getLiveWebSocketURL(this.config.baseURL, apiKey),
headers: webSocketHeaders,
setup,
inputAudioRate: options.inputAudioFormat.rate ?? 16000,
finishGraceMs:
this.config._internal?.finishGraceMs ?? defaultFinishGraceMs,
warnings,
audio: options.audio,
abortSignal: options.abortSignal,
includeRawChunks: options.includeRawChunks,
}),
};
}
}
function createGoogleLiveTranscriptionStream({
webSocket,
url,
headers,
setup,
inputAudioRate,
finishGraceMs,
warnings,
audio,
abortSignal,
includeRawChunks,
}: {
webSocket: WebSocketConstructor | undefined;
url: URL;
headers: Record<string, string | undefined>;
setup: unknown;
inputAudioRate: number;
finishGraceMs: number;
warnings: SharedV4Warning[];
audio: ReadableStream<Uint8Array | string>;
abortSignal: AbortSignal | undefined;
includeRawChunks: boolean | undefined;
}) {
let finished = false;
let cleanup: (closeCode?: number) => void = () => {};
return new ReadableStream<TranscriptionModelV4StreamPart>({
start: controller => {
let audioReader:
| ReadableStreamDefaultReader<Uint8Array | string>
| undefined;
let connection: WebSocketConnection | undefined;
// The Live API contract requires waiting for the `setupComplete`
// server message before sending realtime input: the audio send loop
// is gated on this promise.
let resolveSetupComplete!: () => void;
const setupComplete = new Promise<void>(resolve => {
resolveSetupComplete = resolve;
});
// Google Live messages carry no response/item IDs; a segment counter
// generates consistent synthetic IDs. Transcription fragments arrive
// incrementally and are accumulated per segment; a `finished: true`
// transcription or `turnComplete` finalizes the current segment.
let segmentCounter = 0;
let segmentBuffer = '';
let fullText = '';
// Latest revisable interim text: the fallback final when the server
// never delivers a finished `inputTranscription` segment.
let latestInterim = '';
let language: string | undefined;
let audioEnded = false;
let usageMetadata: JSONObject | undefined;
let finishTimer: ReturnType<typeof setTimeout> | undefined;
const segmentId = () => `google-segment-${segmentCounter}`;
const cancelPendingFinish = () => {
if (finishTimer != null) {
clearTimeout(finishTimer);
finishTimer = undefined;
}
};
// Trailing transcripts can arrive after audioStreamEnd; without a
// terminal signal, finish after a quiet grace window. Transcript
// activity reschedules the timer.
const schedulePendingFinish = () => {
if (finished || !audioEnded) return;
cancelPendingFinish();
finishTimer = setTimeout(() => {
finishTimer = undefined;
finish();
}, finishGraceMs);
};
cleanup = (closeCode?: number) => {
cancelPendingFinish();
if (audioReader != null) {
void audioReader.cancel().catch(() => {});
} else {
// pre-open failure or abort: cancel the caller's audio stream so an
// upstream producer piping into it does not hang:
void audio.cancel().catch(() => {});
}
connection?.close(closeCode);
};
const finishWithError = (error: unknown) => {
if (finished) return;
finished = true;
cleanup();
controller.error(error);
};
const completeSegment = () => {
// A finished segment supersedes any interim text it revises.
if (segmentBuffer === '') {
if (latestInterim === '') return;
segmentBuffer = latestInterim;
}
latestInterim = '';
controller.enqueue({
type: 'transcript-final',
id: segmentId(),
text: segmentBuffer,
});
fullText += fullText === '' ? segmentBuffer : ` ${segmentBuffer}`;
segmentBuffer = '';
segmentCounter++;
};
const finish = () => {
if (finished) return;
completeSegment();
finished = true;
controller.enqueue({
type: 'finish',
text: fullText,
segments: [],
language,
durationInSeconds: undefined,
...(usageMetadata != null
? { providerMetadata: { google: { usageMetadata } } }
: {}),
});
controller.close();
cleanup(1000);
};
const sendAudio = async (socket: WebSocketLike) => {
audioReader = audio.getReader();
try {
while (true) {
const { done, value } = await audioReader.read();
if (done || finished) break;
socket.send(
JSON.stringify({
realtimeInput: {
audio: {
data: convertToBase64(value),
mimeType: `audio/pcm;rate=${inputAudioRate}`,
},
},
}),
);
// backpressure: pause reads while the socket buffer is full
await waitForWebSocketBufferDrain(socket);
}
} finally {
audioReader.releaseLock();
// unlocked again: cleanup must cancel `audio`, not the reader
audioReader = undefined;
}
if (!finished) {
socket.send(
JSON.stringify({ realtimeInput: { audioStreamEnd: true } }),
);
audioEnded = true;
schedulePendingFinish();
}
};
connection = connectToWebSocket({
url,
headers,
webSocket,
abortSignal,
onAbort: finishWithError,
onProcessingError: finishWithError,
onOpen: socket => {
controller.enqueue({ type: 'stream-start', warnings });
socket.send(JSON.stringify({ setup }));
// audio may only be sent after the server acknowledged the setup:
void setupComplete
.then(() => (finished ? undefined : sendAudio(socket)))
.catch(finishWithError);
},
onMessageText: async text => {
if (finished) return;
const parsed = await safeParseJSON({ text });
if (!parsed.success) return;
const message = parsed.value as GoogleLiveServerMessage;
if (includeRawChunks) {
controller.enqueue({ type: 'raw', rawValue: message });
}
if (message.setupComplete != null) {
resolveSetupComplete();
}
if (message.usageMetadata != null) {
usageMetadata = message.usageMetadata;
}
if (message.error != null) {
finishWithError(
new Error(message.error.message ?? 'Google Live API error'),
);
return;
}
const serverContent = message.serverContent;
// Low-latency revisable transcription while the user is speaking.
const interim = serverContent?.interimInputTranscription;
if (interim?.text) {
schedulePendingFinish();
latestInterim = interim.text;
controller.enqueue({
type: 'transcript-partial',
id: segmentId(),
text: interim.text,
});
}
const transcription =
serverContent?.inputTranscription ?? message.inputTranscription;
if (transcription != null) {
if (transcription.languageCode != null) {
language = transcription.languageCode;
}
if (transcription.text) {
schedulePendingFinish();
// A real transcription delta supersedes interim fallback text.
latestInterim = '';
segmentBuffer += transcription.text;
controller.enqueue({
type: 'transcript-delta',
id: segmentId(),
delta: transcription.text,
});
}
if (transcription.finished === true) {
completeSegment();
}
}
if (serverContent?.turnComplete) {
completeSegment();
}
// `interactionStatus` idle (REQUIRES_ACTION in the EAP builds) is
// the definitive all-processing-complete signal: finish as soon as
// the input audio has ended.
const interactionStatus = serverContent?.interactionStatus;
if (
audioEnded &&
(interactionStatus === 'IDLE' ||
interactionStatus === 'REQUIRES_ACTION' ||
(serverContent?.turnComplete === true &&
interactionStatus == null))
) {
finish();
}
},
onSocketError: () => {
finishWithError(new Error('Google Live transcription error'));
},
onClose: ({ code, reason }) => {
if (finished) return;
// a close after the input audio ended means the server delivered
// everything it will deliver: finish with the accumulated text
if (audioEnded) {
finish();
return;
}
finishWithError(
new Error(
`Google Live transcription WebSocket closed unexpectedly before finishing` +
` (code ${code ?? 'unknown'}${reason ? `, reason: ${reason}` : ''}).`,
),
);
},
});
},
cancel: () => {
if (finished) return;
finished = true;
cleanup();
},
});
}
/**
* Builds Google's `AudioTranscriptionConfig` from provider options; returns
* undefined when no options are set.
*/
function buildAudioTranscriptionConfig(
options: GoogleTranscriptionModelOptions | undefined,
): Record<string, unknown> | undefined {
if (options == null) return undefined;
const config: Record<string, unknown> = {};
if (options.languageCodes != null) {
config.languageCodes = options.languageCodes;
}
if (options.customVocabulary != null) {
config.customVocabulary = options.customVocabulary;
}
if (options.wordTimestamp != null) {
config.wordTimestamp = options.wordTimestamp;
}
if (options.diarization != null) {
config.diarization = options.diarization;
}
if (options.mode != null) {
config.mode = options.mode;
}
return Object.keys(config).length > 0 ? config : undefined;
}
/**
* Builds the Interactions API `transcription_config` (snake_case wire) from
* provider options; returns undefined when no options are set. Diarization
* and word timestamps are expressed inside the `mode` object per
* https://ai.google.dev/gemini-api/docs/transcribe.
*/
function buildTranscriptionConfig(
options: GoogleTranscriptionModelOptions | undefined,
): Record<string, unknown> | undefined {
if (options == null) return undefined;
const config: Record<string, unknown> = {};
if (options.languageCodes != null) {
config.language_codes = options.languageCodes;
}
if (options.customVocabulary != null) {
config.custom_vocabulary = options.customVocabulary;
}
if (
options.mode != null ||
options.diarization === true ||
options.wordTimestamp === true
) {
config.mode = {
type: (options.mode ?? 'VERBATIM').toLowerCase(),
...(options.diarization === true ? { diarization_mode: 'speaker' } : {}),
...(options.wordTimestamp === true
? { timestamp_granularities: ['word'] }
: {}),
};
}
return Object.keys(config).length > 0 ? config : undefined;
}
/** Parses a Google duration offset such as `"1s"` or `"9.400s"` to seconds. */
function parseOffsetSeconds(
offset: string | undefined | null,
): number | undefined {
if (offset == null) return undefined;
const parsed = Number.parseFloat(offset);
return Number.isFinite(parsed) ? parsed : undefined;
}
function validateLiveInputAudioFormat(
inputAudioFormat: TranscriptionModelV4StreamOptions['inputAudioFormat'],
) {
if (
inputAudioFormat.type !== 'audio/pcm' ||
(inputAudioFormat.rate != null && inputAudioFormat.rate !== 16000)
) {
throw new InvalidArgumentError({
argument: 'inputAudioFormat',
message:
'The Gemini Live transcription API only supports 16kHz 16-bit PCM input audio.',
});
}
}
const googleInteractionsWordAnnotationSchema = z.object({
type: z.string().nullish(),
text: z.string().nullish(),
speaker: z.string().nullish(),
start_offset: z.string().nullish(),
end_offset: z.string().nullish(),
});
const googleInteractionsTranscriptionResponseSchema = z.object({
status: z.string().nullish(),
steps: z
.array(
z.object({
type: z.string().nullish(),
content: z
.array(
z.object({
type: z.string().nullish(),
text: z.string().nullish(),
annotations: z
.array(googleInteractionsWordAnnotationSchema)
.nullish(),
}),
)
.nullish(),
}),
)
.nullish(),
usage: z.record(z.string(), z.unknown()).nullish(),
});
+62
-3
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
import { InferSchema, FetchFunction, WebSocketConstructor, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@ai-sdk/provider-utils';
import { InferSchema, FetchFunction, WebSocketConstructor, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable } from '@ai-sdk/provider-utils';
import { z } from 'zod/v4';
import * as _ai_sdk_provider from '@ai-sdk/provider';
import { ProviderV4, Experimental_BatchLanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4, Experimental_SpeechTranslationModelV4, SpeechModelV4, FilesV4, LanguageModelV4, Experimental_RealtimeFactoryV4, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientSecretOptions, Experimental_RealtimeModelV4ClientSecretResult, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4SessionConfig, Experimental_SpeechTranslationModelV4StreamOptions } from '@ai-sdk/provider';
import { ProviderV4, Experimental_BatchLanguageModelV4, ImageModelV4, EmbeddingModelV4, Experimental_VideoModelV4, Experimental_SpeechTranslationModelV4, SpeechModelV4, TranscriptionModelV4, FilesV4, LanguageModelV4, Experimental_RealtimeFactoryV4, Experimental_RealtimeModelV4, Experimental_RealtimeModelV4ClientSecretOptions, Experimental_RealtimeModelV4ClientSecretResult, Experimental_RealtimeModelV4ServerEvent, Experimental_RealtimeModelV4ClientEvent, Experimental_RealtimeModelV4SessionConfig, JSONObject, Experimental_TranscriptionModelV4StreamOptions, Experimental_SpeechTranslationModelV4StreamOptions } from '@ai-sdk/provider';

@@ -515,2 +515,20 @@ declare const googleErrorDataSchema: _ai_sdk_provider_utils.LazySchema<{

type GoogleTranscriptionModelId = 'gemini-3.5-transcribe' | 'gemini-3.5-transcribe-live' | (string & {});
/**
* Speech recognition options shared by unary (`gemini-3.5-transcribe`) and
* live (`gemini-3.5-transcribe-live`) transcription. Maps onto Google's
* `AudioTranscriptionConfig`.
*/
declare const googleTranscriptionModelOptions: z.ZodObject<{
languageCodes: z.ZodOptional<z.ZodArray<z.ZodString>>;
customVocabulary: z.ZodOptional<z.ZodArray<z.ZodString>>;
wordTimestamp: z.ZodOptional<z.ZodBoolean>;
diarization: z.ZodOptional<z.ZodBoolean>;
mode: z.ZodOptional<z.ZodEnum<{
SMART: "SMART";
VERBATIM: "VERBATIM";
}>>;
}, z.core.$strip>;
type GoogleTranscriptionModelOptions = z.infer<typeof googleTranscriptionModelOptions>;
type GoogleSpeechTranslationModelId = 'gemini-3.5-live-translate-preview' | (string & {});

@@ -574,2 +592,13 @@ declare const googleSpeechTranslationModelOptions: _ai_sdk_provider_utils.LazySchema<{

speechModel(modelId: GoogleSpeechModelId): SpeechModelV4;
/**
* Creates a model for transcription (speech-to-text). Unary models
* (e.g. `gemini-3.5-transcribe`) transcribe audio files; live models
* (e.g. `gemini-3.5-transcribe-live`) stream transcription over the
* Gemini Live API WebSocket via `experimental_streamTranscribe`.
*/
transcription(modelId: GoogleTranscriptionModelId): TranscriptionModelV4;
/**
* Creates a model for transcription (speech-to-text).
*/
transcriptionModel(modelId: GoogleTranscriptionModelId): TranscriptionModelV4;
files(): FilesV4;

@@ -684,2 +713,32 @@ /**

interface GoogleTranscriptionModelConfig {
provider: string;
baseURL: string;
headers?: Resolvable<Record<string, string | undefined>>;
fetch?: FetchFunction;
webSocket?: WebSocketConstructor;
_internal?: {
currentDate?: () => Date;
finishGraceMs?: number;
};
}
declare class GoogleTranscriptionModel implements TranscriptionModelV4 {
readonly modelId: GoogleTranscriptionModelId;
private readonly config;
readonly specificationVersion = "v4";
static [WORKFLOW_SERIALIZE](model: GoogleTranscriptionModel): {
modelId: string;
config: JSONObject;
};
static [WORKFLOW_DESERIALIZE](options: {
modelId: GoogleTranscriptionModelId;
config: GoogleTranscriptionModelConfig;
}): GoogleTranscriptionModel;
get provider(): string;
constructor(modelId: GoogleTranscriptionModelId, config: GoogleTranscriptionModelConfig);
private parseOptions;
doGenerate(options: Parameters<TranscriptionModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>>;
doStream(options: Experimental_TranscriptionModelV4StreamOptions): Promise<Awaited<ReturnType<NonNullable<TranscriptionModelV4['doStream']>>>>;
}
type GoogleSpeechTranslationModelConfig = {

@@ -714,2 +773,2 @@ provider: string;

export { GoogleRealtimeModel as Experimental_GoogleRealtimeModel, type GoogleRealtimeModelConfig as Experimental_GoogleRealtimeModelConfig, type GoogleRealtimeModelId as Experimental_GoogleRealtimeModelId, type GoogleRealtimeModelOptions as Experimental_GoogleRealtimeModelOptions, GoogleSpeechTranslationModel as Experimental_GoogleSpeechTranslationModel, type GoogleSpeechTranslationModelConfig as Experimental_GoogleSpeechTranslationModelConfig, type GoogleSpeechTranslationModelId as Experimental_GoogleSpeechTranslationModelId, type GoogleSpeechTranslationModelOptions as Experimental_GoogleSpeechTranslationModelOptions, GoogleSpeechTranslationModel as Experimental_GoogleTranslationModel, type GoogleSpeechTranslationModelConfig as Experimental_GoogleTranslationModelConfig, type GoogleSpeechTranslationModelId as Experimental_GoogleTranslationModelId, type GoogleSpeechTranslationModelOptions as Experimental_GoogleTranslationModelOptions, type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleFilesUploadOptions, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleProvider as GoogleGenerativeAIProvider, type GoogleProviderMetadata as GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleProviderSettings as GoogleGenerativeAIProviderSettings, type GoogleVideoModelId as GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, type GoogleProvider, type GoogleProviderMetadata, type GoogleProviderSettings, type GoogleSpeechModelId, type GoogleSpeechModelOptions, type GoogleVideoModelId, type GoogleVideoModelOptions, VERSION, createGoogle, createGoogle as createGoogleGenerativeAI, google };
export { GoogleRealtimeModel as Experimental_GoogleRealtimeModel, type GoogleRealtimeModelConfig as Experimental_GoogleRealtimeModelConfig, type GoogleRealtimeModelId as Experimental_GoogleRealtimeModelId, type GoogleRealtimeModelOptions as Experimental_GoogleRealtimeModelOptions, GoogleSpeechTranslationModel as Experimental_GoogleSpeechTranslationModel, type GoogleSpeechTranslationModelConfig as Experimental_GoogleSpeechTranslationModelConfig, type GoogleSpeechTranslationModelId as Experimental_GoogleSpeechTranslationModelId, type GoogleSpeechTranslationModelOptions as Experimental_GoogleSpeechTranslationModelOptions, GoogleSpeechTranslationModel as Experimental_GoogleTranslationModel, type GoogleSpeechTranslationModelConfig as Experimental_GoogleTranslationModelConfig, type GoogleSpeechTranslationModelId as Experimental_GoogleTranslationModelId, type GoogleSpeechTranslationModelOptions as Experimental_GoogleTranslationModelOptions, type GoogleEmbeddingModelOptions, type GoogleErrorData, type GoogleFilesUploadOptions, type GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions, type GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions, type GoogleProvider as GoogleGenerativeAIProvider, type GoogleProviderMetadata as GoogleGenerativeAIProviderMetadata, type GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions, type GoogleProviderSettings as GoogleGenerativeAIProviderSettings, type GoogleVideoModelId as GoogleGenerativeAIVideoModelId, type GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions, type GoogleImageModelOptions, type GoogleInteractionsAgentName, type GoogleInteractionsModelId, type GoogleInteractionsProviderMetadata, type GoogleLanguageModelInteractionsOptions, type GoogleLanguageModelOptions, type GoogleProvider, type GoogleProviderMetadata, type GoogleProviderSettings, type GoogleSpeechModelId, type GoogleSpeechModelOptions, GoogleTranscriptionModel, type GoogleTranscriptionModelId, type GoogleTranscriptionModelOptions, type GoogleVideoModelId, type GoogleVideoModelOptions, VERSION, createGoogle, createGoogle as createGoogleGenerativeAI, google };
+1
-1
{
"name": "@ai-sdk/google",
"version": "4.0.53",
"version": "4.0.54",
"type": "module",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -13,2 +13,3 @@ import type {

Experimental_SpeechTranslationModelV4 as SpeechTranslationModelV4,
TranscriptionModelV4,
} from '@ai-sdk/provider';

@@ -47,2 +48,4 @@ import {

import { GoogleRealtimeModel } from './realtime/google-realtime-model';
import { GoogleTranscriptionModel } from './transcription/google-transcription-model';
import type { GoogleTranscriptionModelId } from './transcription/google-transcription-model-options';
import { GoogleSpeechTranslationModel } from './speech-translation/google-speech-translation-model';

@@ -125,2 +128,15 @@ import type { GoogleSpeechTranslationModelId } from './speech-translation/google-speech-translation-model-options';

/**
* Creates a model for transcription (speech-to-text). Unary models
* (e.g. `gemini-3.5-transcribe`) transcribe audio files; live models
* (e.g. `gemini-3.5-transcribe-live`) stream transcription over the
* Gemini Live API WebSocket via `experimental_streamTranscribe`.
*/
transcription(modelId: GoogleTranscriptionModelId): TranscriptionModelV4;
/**
* Creates a model for transcription (speech-to-text).
*/
transcriptionModel(modelId: GoogleTranscriptionModelId): TranscriptionModelV4;
files(): FilesV4;

@@ -337,2 +353,11 @@

const createTranscriptionModel = (modelId: GoogleTranscriptionModelId) =>
new GoogleTranscriptionModel(modelId, {
provider: `${providerName}.transcription`,
baseURL,
headers: getHeaders,
fetch: options.fetch,
webSocket: options.webSocket,
});
const experimentalRealtimeFactory = Object.assign(

@@ -400,2 +425,4 @@ (modelId: string) => createRealtimeModel(modelId),

provider.speechModel = createSpeechModel;
provider.transcription = createTranscriptionModel;
provider.transcriptionModel = createTranscriptionModel;
provider.translation = createSpeechTranslationModel;

@@ -402,0 +429,0 @@ provider.speechTranslationModel = createSpeechTranslationModel;

@@ -63,2 +63,7 @@ export type { GoogleErrorData } from './google-error';

} from './realtime/google-realtime-model-options';
export { GoogleTranscriptionModel } from './transcription/google-transcription-model';
export type {
GoogleTranscriptionModelId,
GoogleTranscriptionModelOptions,
} from './transcription/google-transcription-model-options';
export {

@@ -65,0 +70,0 @@ GoogleSpeechTranslationModel as Experimental_GoogleSpeechTranslationModel,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display