Budibase/budibase · error · Error

Key already exists, cannot be recreated

Error message

Key already exists, cannot be recreated

What it means

syncKeyModels only recreates the LiteLLM key when the key-status probe returns exactly 404 (key missing). Any other response (200/401/500) means the key still exists or the check could not confirm deletion, so recreating would duplicate it; it throws this plain Error to abort the sync.

Source

Thrown at packages/server/src/sdk/workspace/ai/configs/litellm.ts:566

      modelIds,
    })
    success = true
  } catch (err: any) {
    if (!isMissingVirtualKeyError(err)) {
      throw err
    }
  }

  if (!success) {
    const keyRes = await fetch(`${liteLLMUrl}/key/info?key=${keyId}`, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        Authorization: liteLLMAuthorizationHeader,
      },
    })
    if (keyRes.status !== 404) {
      throw new Error("Key already exists, cannot be recreated")
    }

    const regeneratedKey = await regenerateWorkspaceKey()
    keyId = regeneratedKey.keyId
    await updateKey({
      keyId,
      modelIds,
    })
  }
}

type LiteLLMPublicProvider = {
  provider: string
  provider_display_name: string
  litellm_provider: string
  default_model_placeholder?: string | null
  credential_fields: {
    key: string

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Delete the existing virtual key in LiteLLM (or confirm its 404) before re-running syncKeyModels.
  2. Fix any auth/proxy issue causing the status probe to return non-404 (check master key, proxy health).
  3. Remove the stale LiteLLM key doc or re-run reconcileLiteLLMModels so deletion and recreation complete atomically.

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// confirm the key is really gone in LiteLLM before re-syncing
const res = await fetch(keyStatusUrl, { headers: { Authorization: authHeader } })
if (res.status !== 404) throw new Error("Key still exists upstream — delete it before re-creating")

Try / catch

try {
  await syncKeyModels(keyId, models)
} catch (e) {
  if (e.message === "Key already exists, cannot be recreated") {
    await deleteLiteLLMKey(keyId) // remove upstream, then retry
    await syncKeyModels(keyId, models)
  } else throw e
}

Prevention

When it happens

Trigger: Calling syncKeyModels (via create/update/remove/reconcileLiteLLMModels) after a key deletion that did not actually propagate on the LiteLLM side, or when the status probe fails with non-404 (auth error, network 5xx) while the code path assumed a missing key.

Common situations: Key deleted in the Budibase DB but not in LiteLLM (partial deletion); LiteLLM returning 401 so the 404 check fails; race where another process recreated the key between removal and sync.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/0df50eb9f27c1874. Report an issue: GitHub.