Experimental
The parameters for the create request.
The created auth token.
Ephemeral auth tokens is only supported in the Gemini Developer API. It can be used for the session connection to the Live constrained API. Support in v1alpha only.
const ai = new GoogleGenAI({
apiKey: token.name,
httpOptions: { apiVersion: 'v1alpha' } // Support in v1alpha only.
});
// Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
// when using the token in Live API sessions. Each session connection can
// use a different configuration.
const config: CreateAuthTokenConfig = {
uses: 3,
expireTime: '2025-05-01T00:00:00Z',
}
const token = await ai.tokens.create(config);
// Case 2: If LiveEphemeralParameters is set, lock all fields in
// LiveConnectConfig when using the token in Live API sessions. For
// example, changing `outputAudioTranscription` in the Live API
// connection will be ignored by the API.
const config: CreateAuthTokenConfig =
uses: 3,
expireTime: '2025-05-01T00:00:00Z',
LiveEphemeralParameters: {
model: 'gemini-2.0-flash-001',
config: {
'responseModalities': ['AUDIO'],
'systemInstruction': 'Always answer in English.',
}
}
}
const token = await ai.tokens.create(config);
// Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
// set, lock LiveConnectConfig with set and additional fields (e.g.
// responseModalities, systemInstruction, temperature in this example) when
// using the token in Live API sessions.
const config: CreateAuthTokenConfig =
uses: 3,
expireTime: '2025-05-01T00:00:00Z',
LiveEphemeralParameters: {
model: 'gemini-2.0-flash-001',
config: {
'responseModalities': ['AUDIO'],
'systemInstruction': 'Always answer in English.',
}
},
lockAdditionalFields: ['temperature'],
}
const token = await ai.tokens.create(config);
// Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
// empty array, lock LiveConnectConfig with set fields (e.g.
// responseModalities, systemInstruction in this example) when using the
// token in Live API sessions.
const config: CreateAuthTokenConfig =
uses: 3,
expireTime: '2025-05-01T00:00:00Z',
LiveEphemeralParameters: {
model: 'gemini-2.0-flash-001',
config: {
'responseModalities': ['AUDIO'],
'systemInstruction': 'Always answer in English.',
}
},
lockAdditionalFields: [],
}
const token = await ai.tokens.create(config);
Creates an ephemeral auth token resource.