BerriAI/litellm · error · HTTPException
Memory with key '{key}' already exists.
Error message
Memory with key '{key}' already exists. What it means
HTTPException raised on PUT when the initial create attempt lost a race — a concurrent request created the row with the same key after the existence check, and the retry/fallback also found a conflict. Signals the key now exists so the caller should retry as an update.
Source
Thrown at litellm/proxy/memory/memory_endpoints.py:537
"team_id": team_id,
"created_by": user_api_key_dict.user_id,
"updated_by": user_api_key_dict.user_id,
}
if body.metadata is not None:
create_data["metadata"] = _serialize_metadata_for_prisma(body.metadata)
try:
row = await _memory_table(prisma_client).create(data=create_data)
except Exception as e:
# Race: a concurrent PUT/POST created the row after our check.
# Re-read and fall back to an update so the PUT stays idempotent
# instead of surfacing a 500 on a unique-violation.
if not _is_unique_violation(e):
raise
existing_after_race: Final = await _find_existing()
if existing_after_race is None:
# Row exists globally but isn't visible to this caller
# (owned by someone else). Treat as conflict.
raise HTTPException(
status_code=409,
detail=f"Memory with key '{key}' already exists.",
)
# Same write-authorization check as the non-race path.
await _assert_write_access(prisma_client, existing_after_race, user_api_key_dict)
row = await _memory_table(prisma_client).update(
where={"memory_id": existing_after_race.memory_id},
data=data,
)
except HTTPException:
raise
except Exception as e:
raise _internal_error("Error upserting memory: %s", e, "Internal error updating memory entry.")
return _row_to_model(row)
@router.delete(View on GitHub (pinned to 77b7c6c40c)
Solutions
- Choose a different key, or update the existing memory entry instead of creating a new one.
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at litellm/proxy/memory/memory_endpoints.py:537 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/d2be948b5d27203c.
Report an issue: GitHub.