moeru-ai/airi · error · Error

Replicate provider is not configured. Missing API Key.

Error message

Replicate provider is not configured. Missing API Key.

What it means

Thrown by ReplicateProvider.generate() when this.replicate is null. The constructor field is only set to a live Replicate client inside initialize() when config.replicateApiKey is a truthy string; any other value (undefined, empty string, or a missing config object) leaves it null. So the error is a configuration precondition guard, not a network failure.

Source

Thrown at apps/stage-tamagotchi/src/main/services/airi/widgets/providers/replicate.ts:55

    if (config?.replicateApiKey) {
      this.apiKey = config.replicateApiKey
      this.replicate = new Replicate({ auth: this.apiKey })
    }
    else {
      this.apiKey = ''
      this.replicate = null
    }
    if (config?.replicateDefaultModel)
      this.defaultModel = config.replicateDefaultModel
    if (config?.replicateAspectRatio)
      this.aspectRatio = config.replicateAspectRatio
    if (config?.replicateInferenceSteps)
      this.inferenceSteps = config.replicateInferenceSteps
  }

  async generate(request: ArtistryRequest): Promise<ArtistryJob> {
    if (!this.replicate) {
      throw new Error('Replicate provider is not configured. Missing API Key.')
    }

    const model = (request.model || request.extra?.model || this.defaultModel) as `${string}/${string}`
    const base64Image = request.extra?.image || ''

    // 1. Start with defaults
    const hasPromptPlaceholder = JSON.stringify(request.extra).includes('{{PROMPT}}')
    let inputOptions: Record<string, any> = {
      go_fast: request.extra?.go_fast ?? true,
      aspect_ratio: request.extra?.aspect_ratio ?? this.aspectRatio,
      output_format: request.extra?.output_format ?? 'png',
      output_quality: request.extra?.output_quality ?? 80,
      num_inference_steps: request.extra?.num_inference_steps ?? this.inferenceSteps,
    }

    // Default prompt injection if NO placeholder is used in overrides
    if (request.prompt && !hasPromptPlaceholder) {
      inputOptions.prompt = request.prompt

View on GitHub (pinned to 27111382b4)

Solutions

  1. Open Settings > Artistry/Providers and enter a Replicate API key (from replicate.com/account/api-tokens), then save — initialize() will re-run with config.replicateApiKey set.
  2. If calling programmatically, ensure the config passed to provider.initialize({ replicateApiKey }) contains a non-empty key string before invoking generate().
  3. Verify the settings store actually persists replicateApiKey and that the provider manager re-initializes the provider after a key change rather than reusing the stale instance.
  4. Guard the UI so the Replicate provider cannot be selected as active until a key is present.

Example fix

// before
provider.generate({ prompt: 'cat' })

// after
if (!provider['replicate']) {
  throw new Error('Configure replicateApiKey before generating')
}
provider.generate({ prompt: 'cat' })
Defensive patterns

Strategy: validation

Validate before calling

function isReplicateConfigured(provider: ReplicateProvider): boolean {
  // The replicate client is private; expose an isConfigured() method on the provider
  // and call it before generate().
  return provider.isConfigured()
}
// In the provider:
// isConfigured() { return this.replicate !== null && this.apiKey !== '' }

Type guard

function hasReplicateApiKey(config: unknown): config is { replicateApiKey: string } {
  return typeof config === 'object' && config !== null
    && typeof (config as any).replicateApiKey === 'string'
    && (config as any).replicateApiKey.length > 0
}

Try / catch

try {
  await provider.generate(request)
} catch (e) {
  if (e instanceof Error && e.message.includes('Missing API Key')) {
    // prompt user to configure the key, do not retry
  } else throw e
}

Prevention

When it happens

Trigger: Calling generate() on a ReplicateProvider instance whose initialize() was invoked with a config that lacks replicateApiKey, or initialize() was never called. Also triggered if the user cleared the API key in settings (initialize re-run with no key resets this.replicate to null).

Common situations: User selected the Replicate artistry provider in settings but never entered an API key; key was saved as empty string; settings store reset; provider was instantiated but initialize() skipped during a fast-path code change.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/3a8b58d666fcfe58. Report an issue: GitHub.