{"record":{"id":"df38f4ac5245bc03","repo":"vercel/ai","slug":"google-realtime-auth-token-request-failed-respo","errorCode":null,"errorMessage":"Google realtime auth token request failed: ${response.status} ${text}","messagePattern":"Google realtime auth token request failed: (.+?) (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/google/src/realtime/google-realtime-model.ts","lineNumber":103,"sourceCode":"      `${getAuthTokensURL(this.config.baseURL)}?key=${encodeURIComponent(apiKey)}`,\n      {\n        method: 'POST',\n        headers: { 'Content-Type': 'application/json' },\n        body: JSON.stringify({\n          // `uses: 0` means no limit is applied to how many times the token can\n          // start a session (per the AuthToken spec). An unset value would\n          // default to 1, which breaks WebSocket reconnects within the session.\n          uses: 0,\n          expireTime,\n          newSessionExpireTime,\n          bidiGenerateContentSetup: setupPayload,\n        }),\n      },\n    );\n\n    if (!response.ok) {\n      const text = await response.text();\n      throw new Error(\n        `Google realtime auth token request failed: ${response.status} ${text}`,\n      );\n    }\n\n    const data = (await response.json()) as {\n      name: string;\n      expireTime?: string;\n    };\n\n    return {\n      token: data.name,\n      url: getWebSocketURL(this.config.baseURL),\n      expiresAt: data.expireTime\n        ? Math.floor(new Date(data.expireTime).getTime() / 1000)\n        : undefined,\n    };\n  }\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/realtime/google-realtime-model.ts#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst secret = await model.createClientSecret({ sessionConfig: { model: 'made-up-model' } });\n// after\nconst secret = await model.createClientSecret({\n  sessionConfig: { model: 'gemini-2.5-flash-native-audio-preview-09-2025' },\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const secret = await model.createClientSecret(options);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('auth token request failed')) {\n    const status = error.message.match(/failed: (\\d{3})/)?.[1];\n    if (status === '429') await backoffAndRetry();\n    else logConfigError(error.message); // 400/401/403 need fixes, not retries\n  } else { throw error; }\n}","preventionTips":["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."],"tags":["network","authentication","google","realtime","http-error"],"backgroundTag":"api-request-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}