moeru-ai/airi · error · Error

Failed to update provider config

Error message

Failed to update provider config

What it means

Thrown by InferenceServiceProvidersService.patchConfigRemote when PATCH /v1/providers/:id returns non-ok. The service patches config plus validated/validationBypassed flags derived from the ProviderValidationStatus, then normalizes the response. Failure aborts before normalize.

Source

Thrown at packages/stage-ui/src/services/inference-service-providers.ts:196

  async function patchConfigRemote(
    client: InferenceServiceProvidersRemoteClient,
    providerId: string,
    config: Record<string, unknown>,
    status: ProviderValidationStatus,
    options?: InferenceServiceProviderServiceOptions,
  ): Promise<InferenceServiceProvider> {
    options?.abortSignal?.throwIfAborted()
    const res = await client.api.v1.providers[':id'].$patch({
      param: { id: providerId },
      json: {
        config,
        validated: status === 'configured',
        validationBypassed: status === 'bypassed',
      },
    }, requestOptions(options))
    if (!res.ok)
      throw new Error('Failed to update provider config')

    const item = await res.json()
    options?.abortSignal?.throwIfAborted()
    return normalize(item)
  }

  return {
    buildLocal,
    fetchRemote,
    createRemote,
    deleteRemote,
    patchConfigRemote,
  }
}

export const inferenceServiceProvidersService = createInferenceServiceProvidersService()

View on GitHub (pinned to 27111382b4)

Solutions

  1. Run client-side config validation (and a live credential check if possible) before PATCHing.
  2. Handle 404 by refreshing the provider list and removing the stale entry.
  3. Re-authenticate on 401/403; on 422 surface the field errors to the form.
  4. Capture res.status and server detail for accurate feedback.

Example fix

// before
if (!res.ok)
  throw new Error('Failed to update provider config')

// after
if (!res.ok) {
  if (res.status === 404)
    throw new NotFoundError(`Provider ${providerId} not found`)
  const detail = await res.json().catch(() => null)
  throw new ProviderConfigError(`Failed to update provider config (status ${res.status})`, detail)
}
Defensive patterns

Strategy: validation

Validate before calling

function validateProviderConfig(providerId: string, config: Record<string, unknown>, status: ProviderValidationStatus): string[] {
  const errors: string[] = []
  if (status === 'configured') {
    // definition-specific required-field checks (e.g. apiKey present)
    if (!config.apiKey)
      errors.push('apiKey is required to mark provider as configured')
  }
  return errors
}

const issues = validateProviderConfig(providerId, config, status)
if (issues.length)
  throw new Error('Invalid provider config: ' + issues.join(', '))
await patchConfigRemote(client, providerId, config, status)

Try / catch

try {
  return await patchConfigRemote(client, providerId, config, status)
}
catch (error) {
  // Patch service to expose status; on 404 refresh list, on 401/403 re-auth, on 422 show field errors.
  throw error
}

Prevention

When it happens

Trigger: client.api.v1.providers[':id'].$patch({ param: { id }, json: { config, validated, validationBypassed } }) resolves with ok=false. Typical: 400/422 (config failed server-side validation, e.g. bad apiKey), 401/403 (not authenticated / not owner), 404 (provider deleted), 500 (server).

Common situations: Saving a provider config with an invalid apiKey that fails the backend's validation probe; editing a concurrently-deleted provider; expired session; setting status to 'configured' while config is actually invalid.

Related errors


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