moeru-ai/airi · error

Failed to initialize speech provider

Error message

Failed to initialize speech provider

What it means

Thrown by the OpenAI audio speech playground when `getProviderInstance<SpeechProvider<string>>(providerId)` resolves falsy. Voices for OpenAI are hardcoded in provider metadata (no list-endpoint), but the instance still requires the OpenAI API key from persisted config. `getProviderInstance` throws its own distinct errors for a missing definition or entirely missing config, so this guard catches the remaining case: the factory built nothing (undefined) from an incomplete/blank config despite the non-nullable `Promise<R>` type.

Source

Thrown at packages/stage-pages/src/pages/settings/providers/speech/openai-audio-speech.vue:84

    return voice.compatibleModels.includes(selectedModel)
  })
})

// Load models and voices on mount
onMounted(async () => {
  await providersStore.loadModelsForConfiguredProviders()
  await providersStore.fetchModelsForProvider(providerId)
  // Load voices
  // NOTE: OpenAI does not provide an API endpoint to retrieve available voices.
  // Voices are hardcoded in provider metadata - this is a provider limitation, not an application limitation.
  await speechStore.loadVoicesForProvider(providerId)
})

// Generate speech with OpenAI-specific parameters
async function handleGenerateSpeech(input: string, voiceId: string, _useSSML: boolean) {
  const provider = await providersStore.getProviderInstance<SpeechProvider<string>>(providerId)
  if (!provider) {
    throw new Error('Failed to initialize speech provider')
  }

  // Get provider configuration
  const providerConfig = providerStore.getProviderConfig(providerId)

  // Use the reactive model computed property (not a local variable)
  const modelToUse = model.value || defaultModel

  return await speechStore.speech(
    provider,
    modelToUse,
    input,
    voiceId,
    {
      ...providerConfig,
      ...defaultVoiceSettings,
    },
  )

View on GitHub (pinned to 677329427f)

Solutions

  1. Save a valid OpenAI API key under the audio speech provider entry in Settings → Providers and pass validation.
  2. Reload the playground after saving so the instance is rebuilt from fresh config.
  3. Check the console for `Error creating provider instance for ...` — the factory's underlying reason is logged there.
  4. Confirm you configured the OpenAI audio provider specifically, not only the chat provider.
  5. If the key is valid and it still fails, report the silent-undefined factory behavior.

Example fix

// before
const provider = await providersStore.getProviderInstance<SpeechProvider<string>>(providerId)
if (!provider)
  throw new Error('Failed to initialize speech provider')

// after
const config = providerStore.getProviderConfig(providerId)
if (!config?.apiKey?.trim())
  throw new Error('OpenAI API key is empty. Save it in provider settings first.')
const provider = await providersStore.getProviderInstance<SpeechProvider<string>>(providerId)
if (!provider || typeof provider.speech !== 'function')
  throw new Error('OpenAI audio factory returned no usable instance — check config and console logs')
Defensive patterns

Strategy: validation

Validate before calling

const apiKeyConfigured = computed(() => !!providers.value[providerId]?.apiKey?.trim())
if (!apiKeyConfigured.value)
  throw new Error('Save an OpenAI API key before generating speech')

Type guard

function isSpeechProvider(v: unknown): v is SpeechProvider<string> {
  return typeof v === 'object' && v !== null && typeof (v as SpeechProvider<string>).speech === 'function'
}

Try / catch

try { const provider = await providersStore.getProviderInstance<SpeechProvider<string>>(providerId) }
catch (error) { showError(errorMessageFrom(error)) }

Prevention

When it happens

Trigger: Clicking Generate before saving an OpenAI API key; key stored as empty/whitespace so the config object exists (store does not throw) but the factory declines; generating before the onMounted voice/model loads complete while credentials were never entered.

Common situations: Fresh installs where onboarding was skipped; key cleared and saved after testing other providers; org keys rotated in the OpenAI dashboard without updating AIRI; confusion between the chat provider key and the audio-speech provider entry (separate config slots).

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/197ec4a7eb2ec886. Report an issue: GitHub.