vercel/ai · error · Error
Google realtime auth token request failed: ${response.status
Error message
Google realtime auth token request failed: ${response.status} ${text} What it means
After POSTing to Google's v1alpha auth_tokens endpoint to create a realtime client secret, the model checks response.ok; on any non-2xx it reads the response body and throws this error including the HTTP status and Google's error text. It surfaces upstream auth/token-creation failures (bad key, invalid session config, quota, unsupported model) with Google's own message for diagnosis.
Source
Thrown at packages/google/src/realtime/google-realtime-model.ts:103
`${getAuthTokensURL(this.config.baseURL)}?key=${encodeURIComponent(apiKey)}`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
// `uses: 0` means no limit is applied to how many times the token can
// start a session (per the AuthToken spec). An unset value would
// default to 1, which breaks WebSocket reconnects within the session.
uses: 0,
expireTime,
newSessionExpireTime,
bidiGenerateContentSetup: setupPayload,
}),
},
);
if (!response.ok) {
const text = await response.text();
throw new Error(
`Google realtime auth token request failed: ${response.status} ${text}`,
);
}
const data = (await response.json()) as {
name: string;
expireTime?: string;
};
return {
token: data.name,
url: getWebSocketURL(this.config.baseURL),
expiresAt: data.expireTime
? Math.floor(new Date(data.expireTime).getTime() / 1000)
: undefined,
};
}
View on GitHub (pinned to 69428b1f8b)
Solutions
- Read the status and text in the error message: 401/403 means key or permission issues, 400 means bad session config or model, 429 means quota.
- Verify the API key is valid and the Generative Language / Live API is enabled for the project.
- Validate the sessionConfig (model id, modalities, tools) against the Live API requirements.
- Retry with backoff only for 429/5xx; fix config for 400/401/403.
Example fix
// before
const secret = await model.createClientSecret({ sessionConfig: { model: 'made-up-model' } });
// after
const secret = await model.createClientSecret({
sessionConfig: { model: 'gemini-2.5-flash-native-audio-preview-09-2025' },
}); Defensive patterns
Strategy: try-catch
Try / catch
try {
const secret = await model.createClientSecret(options);
} catch (error) {
if (error instanceof Error && error.message.includes('auth token request failed')) {
const status = error.message.match(/failed: (\d{3})/)?.[1];
if (status === '429') await backoffAndRetry();
else logConfigError(error.message); // 400/401/403 need fixes, not retries
} else { throw error; }
} Prevention
- Validate the sessionConfig (model id, modalities) against Live API docs before shipping.
- Confirm the Generative Language API is enabled for the key's project.
- Rotate and test API keys through a staging path before production.
- Retry only on 429/5xx; treat 400/401/403 as configuration errors.
When it happens
Trigger: Creating a realtime client secret when Google rejects the auth_tokens request: invalid or revoked API key, malformed bidiGenerateContentSetup session config, referencing an unsupported model, project quota exhausted, or the API not enabled for the project.
Common situations: Wrong-project API key without the Live API enabled; invalid modelId in the session setup; expired/rotated key; regional endpoint misconfiguration; 429 from rate limits.
Related errors
- Cartesia realtime client secret request failed: ${response.s
- Google Generative AI API key is required for realtime token
- Cartesia realtime client secret response did not include a t
- Google Generative AI API key is required for streaming trans
- ${readErrorMessage({ value, status: response.status })}
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/df38f4ac5245bc03.
Report an issue: GitHub.