Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(azure_ai): classify Search suggest, autocomplete, and analyze as reads

Noah Nistlerc1125f0abb68
diff --git a/litellm/llms/azure_ai/vector_stores/transformation.py b/litellm/llms/azure_ai/vector_stores/transformation.py
index 0dc8bcb13a4..f58d2f54d2e 100644
--- a/litellm/llms/azure_ai/vector_stores/transformation.py
+++ b/litellm/llms/azure_ai/vector_stores/transformation.py
@@ -37,8 +37,28 @@ class AzureAIVectorStoreConfig(BaseVectorStoreConfig, BaseAzureLLM):
super().__init__()
def get_vector_store_endpoints_by_type(self) -> VectorStoreIndexEndpoints:
+ """
+ Every ``GET`` under ``/indexes/`` is a read: get details, stats, and the
+ document reads (GET-form search, ``$count``, point lookup, and the
+ GET forms of suggest and autocomplete).
+
+ ``POST`` splits by endpoint. Search, suggest, autocomplete, and analyze
+ are query endpoints, so they read; ``/docs/index`` is the batch endpoint
+ carrying upload, merge, mergeOrUpload, and delete actions, so it writes.
+
+ Patterns stay literal rather than ``{placeholder}`` templates because the
+ matcher falls back to the substring before a ``{``, which here is always
+ ``/indexes/`` -- broad enough that a templated read, matched first, would
+ shadow the ``/docs/index`` write.
+ """
return {
- "read": [("GET", "/indexes/"), ("POST", "/docs/search")],
+ "read": [
+ ("GET", "/indexes/"),
+ ("POST", "/docs/search"),
+ ("POST", "/docs/suggest"),
+ ("POST", "/docs/autocomplete"),
+ ("POST", "/analyze"),
+ ],
"write": [("POST", "/docs/index")],
}
diff --git a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
index ad86ce60eab..fac15c302f4 100644
--- a/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
+++ b/tests/test_litellm/proxy/vector_store_endpoints/test_vector_store_endpoints.py
@@ -2946,6 +2946,21 @@ class TestAzureAIDocumentWritePassthroughPermission:
INDEX = "my-index"
+ # Every non-lifecycle read Azure exposes for an index. The GET forms are all
+ # covered by the ("GET", "/indexes/") entry; the POST query endpoints each
+ # need their own, since the write entry also matches on POST.
+ READ_ROUTES = [
+ ("GET", f"/azure_ai/indexes/{INDEX}/stats"),
+ ("GET", f"/azure_ai/indexes/{INDEX}/docs"),
+ ("GET", f"/azure_ai/indexes/{INDEX}/docs/$count"),
+ ("GET", f"/azure_ai/indexes/{INDEX}/docs/seed-doc-1"),
+ ("GET", f"/azure_ai/indexes/{INDEX}/docs/suggest"),
+ ("GET", f"/azure_ai/indexes/{INDEX}/docs/autocomplete"),
+ ("POST", f"/azure_ai/indexes/{INDEX}/docs/suggest"),
+ ("POST", f"/azure_ai/indexes/{INDEX}/docs/autocomplete"),
+ ("POST", f"/azure_ai/indexes/{INDEX}/analyze"),
+ ]
+
def _request(self, method: str, path: str) -> MagicMock:
request = MagicMock(spec=Request)
request.method = method
@@ -3006,6 +3021,27 @@ class TestAzureAIDocumentWritePassthroughPermission:
)
assert exc_info.value.status_code == 403
+ @pytest.mark.parametrize("method, path", READ_ROUTES)
+ def test_team_with_read_grant_can_call_every_read_route(self, method, path):
+ result = is_allowed_to_call_vector_store_endpoint(
+ provider=LlmProviders.AZURE_AI,
+ index_name=self.INDEX,
+ request=self._request(method, path),
+ user_api_key_dict=self._team_member(["read"]),
+ )
+ assert result is True
+
+ @pytest.mark.parametrize("method, path", READ_ROUTES)
+ def test_team_without_read_grant_cannot_call_read_routes(self, method, path):
+ with pytest.raises(HTTPException) as exc_info:
+ is_allowed_to_call_vector_store_endpoint(
+ provider=LlmProviders.AZURE_AI,
+ index_name=self.INDEX,
+ request=self._request(method, path),
+ user_api_key_dict=self._team_member(["write"]),
+ )
+ assert exc_info.value.status_code == 403
+
@pytest.mark.parametrize(
"method, operation, path",
[