{"record":{"id":"27bd75c1beaa0009","repo":"BerriAI/litellm","slug":"vector-store-with-id-vector-store-get-vector-sto","errorCode":null,"errorMessage":"Vector store with ID {vector_store.get('vector_store_id')} already exists","messagePattern":"Vector store with ID (.+?) already exists","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py","lineNumber":74,"sourceCode":"    - vector_store_name: Optional[str] - Name of the vector store\n    - vector_store_description: Optional[str] - Description of the vector store\n    - vector_store_metadata: Optional[Dict] - Additional metadata for the vector store\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n    from litellm.types.router import GenericLiteLLMParams\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=\"Database not connected\")\n\n    try:\n        # Check if vector store already exists\n        existing_vector_store = (\n            await prisma_client.db.litellm_managedvectorstorestable.find_unique(\n                where={\"vector_store_id\": vector_store.get(\"vector_store_id\")}\n            )\n        )\n        if existing_vector_store is not None:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Vector store with ID {vector_store.get('vector_store_id')} already exists\",\n            )\n\n        if vector_store.get(\"vector_store_metadata\") is not None:\n            vector_store[\"vector_store_metadata\"] = safe_dumps(\n                vector_store.get(\"vector_store_metadata\")\n            )\n\n        # Safely handle JSON serialization of litellm_params\n        litellm_params_json: Optional[str] = None\n        _input_litellm_params: dict = vector_store.get(\"litellm_params\", {}) or {}\n        if _input_litellm_params is not None:\n            litellm_params_dict = GenericLiteLLMParams(\n                **_input_litellm_params\n            ).model_dump(exclude_none=True)\n            litellm_params_json = safe_dumps(litellm_params_dict)\n            del vector_store[\"litellm_params\"]","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py#L56-L92","documentation":"HTTPException 400 raised by the create-vector-store endpoint when a row with the same vector_store_id already exists in litellm_managedvectorstorestable (checked via find_unique before insert). It is a duplicate-ID conflict guard so retries don't silently overwrite an existing managed vector store.","triggerScenarios":"POST /vector_store/create with a vector_store_id that was already created previously; re-running an install/provisioning script; retrying a create request that partially succeeded client-side; copy-pasting an example payload twice.","commonSituations":"Idempotent provisioning scripts that don't check existence first; CI pipelines re-registering vector stores; teams reusing IDs like 'default' or the provider's store name across environments.","solutions":["Use a unique vector_store_id (or regenerate one) for the new store","If the existing store is stale, DELETE the old vector store first, then create","Treat the 400 as idempotent success in retry logic: GET the store info and continue if it matches what you wanted","Namespace IDs per environment/team (e.g. 'prod-openai-docs') to avoid collisions"],"exampleFix":"# before\nPOST /vector_store/create\n{\"vector_store_id\": \"my-store\", \"custom_llm_provider\": \"openai\"}  # 2nd call -> 400 already exists\n\n# after\n# delete then recreate\nDELETE /vector_store/delete {\"vector_store_id\": \"my-store\"}\nPOST /vector_store/create {\"vector_store_id\": \"my-store\", \"custom_llm_provider\": \"openai\"}","handlingStrategy":"try-catch","validationCode":"import httpx\n\ndef vector_store_exists(client: httpx.Client, vector_store_id: str) -> bool:\n    r = client.post(\"/vector_store/info\", json={\"vector_store_id\": vector_store_id})\n    return r.status_code == 200  # 404 = free to create","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.post(\"/vector_store/create\", json=payload)\n    resp.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 400 and \"already exists\" in e.response.text:\n        existing = client.post(\"/vector_store/info\", json={\"vector_store_id\": sid}).json()\n        # idempotent path: verify it matches expectations, then continue\n    else:\n        raise","preventionTips":["Generate unique vector_store_ids per environment and deployment (include a random suffix or content hash)","Check existence with the info endpoint before create in provisioning scripts","Make create flows idempotent by design: treat 400-already-exists as success after verifying the stored config"],"tags":["vector-store","duplicate","conflict","http-400","idempotency"],"backgroundTag":"resource-already-exists","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}