{"record":{"id":"036c265207dd33d9","repo":"moeru-ai/airi","slug":"gemini-tts-request-failed-response-status-aw-036c26","errorCode":null,"errorMessage":"Gemini TTS request failed: ${response.status} ${await response.text().catch(() => '')}","messagePattern":"Gemini TTS request failed: (.+?) (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/provider-inference/src/providers/cloud/google-gemini-audio-speech/index.ts","lineNumber":99,"sourceCode":"    if (!body.model)\n      throw new Error('Missing model for Gemini TTS')\n\n    const response = await globalThis.fetch(new URL(`models/${body.model}:generateContent`, baseUrl), {\n      method: 'POST',\n      headers: { 'x-goog-api-key': apiKey, 'Content-Type': 'application/json' },\n      body: JSON.stringify({\n        contents: [{ parts: [{ text: body.input }] }],\n        generationConfig: {\n          responseModalities: ['AUDIO'],\n          speechConfig: {\n            voiceConfig: { prebuiltVoiceConfig: { voiceName: body.voice || 'Kore' } },\n          },\n          ...(body.temperature !== undefined ? { temperature: body.temperature } : {}),\n        },\n      }),\n    })\n    if (!response.ok)\n      throw new Error(`Gemini TTS request failed: ${response.status} ${await response.text().catch(() => '')}`)\n\n    const data = await response.json() as {\n      candidates?: Array<{ content?: { parts?: Array<{ inlineData?: { data?: string } }> } }>\n    }\n    const audio = data.candidates?.[0]?.content?.parts?.find(part => part.inlineData)?.inlineData?.data\n    if (!audio)\n      throw new Error('Gemini TTS response missing audio data')\n\n    return new Response(toWavFromPCM16(decodeBase64(audio), 24000), {\n      status: 200,\n      headers: { 'Content-Type': 'audio/wav' },\n    })\n  }\n}\n\nexport const providerGoogleGeminiAudioSpeech = defineProvider<GoogleGeminiSpeechConfig, 'google-gemini-audio-speech'>({\n  id: 'google-gemini-audio-speech',\n  name: 'Google Gemini',","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/moeru-ai/airi/blob/f679616c34f1cf6d282c8d64264242af944b3fed/packages/provider-inference/src/providers/cloud/google-gemini-audio-speech/index.ts#L81-L117","documentation":"The Gemini generateContent endpoint returned a non-OK HTTP status. The wrapper surfaces the status code plus the response body text (best effort) so the developer can see the API-side error reason such as invalid API key, quota, or invalid model name.","triggerScenarios":"Any Gemini API rejection of the TTS request: invalid or missing x-goog-api-key, nonexistent/unsupported model, malformed request payload, quota exceeded, or transient 5xx from Google.","commonSituations":"Wrong or expired API key, using a model id not enabled for your project, exceeding free-tier limits, or regional unavailability of the preview TTS model.","solutions":["Read the status and body text in the message to identify the API-side cause","Verify the API key is valid and has the Gemini TTS API enabled","Confirm the model id is a valid Gemini TTS model available to your account","Retry with backoff on 429/5xx; fix the payload or key on 400/401/403","Check quota and billing status in the Google AI console"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-flight: ensure key and model present\nif (!apiKey) throw new Error('Missing Gemini API key')\nif (!model) throw new Error('Missing Gemini TTS model')","typeGuard":null,"tryCatchPattern":"try {\n  const audio = await speech({ input, model })\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Gemini TTS request failed:')) {\n    const status = Number(e.message.match(/failed: (\\d+)/)?.[1])\n    if (status === 429 || status >= 500) await retryWithBackoff()\n    else if (status === 401 || status === 403) fixApiKey()\n    else if (status === 404) fixModelOrBaseUrl()\n  }\n}","preventionTips":["Validate the API key and model id before requests","Read the status code embedded in the message to choose fix vs retry","Implement exponential backoff for 429/5xx only","Monitor quota and billing in the Google AI console"],"tags":["tts","http","api-error","gemini"],"backgroundTag":"http-error-response","analyzedSha":"f679616c34f1cf6d282c8d64264242af944b3fed","analyzedAt":"2026-09-08T13:18:15.005Z","contentChangedAt":"2026-09-08T13:18:15.005Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}