Usage details are not returned in the response when the stream is set to true in the chat/completions endpoint with AI RAG search.

Chandrashekar Machipeddi 0 Reputation points
2025-04-08T06:31:32.18+00:00

Hi ,

We are using Azure AI Search with the chat/completions endpoint to search the data from the index. We are not getting the usage details, such as how many tokens are consumed. This issue occurs only when the stream is set to true.

Based on some blogs, we tried using the stream options like "stream_options": {"include_usage": true}.

However, this request failed with the error message: "Validation error at #/stream_options: Extra inputs are not permitted."

We are using gpt4 model with API version as 2024-10-21

POST https://xyxyxyx.openai.azure.com//openai/deployments/{DeployementName}/chat/completions?api-version=2024-10-21 HTTP/1.1

Is there any way to get the usage tokens with stream enabled.

Same thing is working fine, if we remove the data_sources parameter from the input body then we are getting the token usage., but to work with RAG search we have to pass the data_sources parameter too.

Below is the sample input body we are using for chat completion.

{"data_sources":[{"type":"azure_search","parameters":{"endpoint":"https://abcd.search.windows.net/","index_name":"developmentindex1","authentication":{"type":"api_key","key":"xxxxxxxxxxxxxxxxx"},"query_type":"simple","fields_mapping":{"content_fields_separator":"\n","content_fields":["TA_SYSTEM_CHUNK_TEXT","TA_SYSTEM_CHUNK_COORDINATES"],"title_field":"TA_SYSTEM_REFERENCE","filepath_field":"TA_SYSTEM_CAPTURE_DOC_ID","url_field":"TA_SYSTEM_REFERENCE_ID","vector_fields":["TA_SYSTEM_CHUNK_VECTORS"]},"embedding_dependency":{"endpoint":"https://qqqqqqqq.openai.azure.com/openai/deployments/TextEmbeddings/embeddings","authentication":{"type":"api_key","key":"xxxxxxxxxxxxxxxx "},"type":"endpoint"},"semantic_configuration":"developmentindex1_semanticConf","strictness":3,"top_n_documents":5,"in_scope":false,"filter":""}}],"messages":[{"role":"user","content":"1+1"}],"seed":null,"stream":true,"stream_options":{"include_usage":true}}

Thanks in advance.

Chandra shekar.M

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,281 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.