Hi @Dey, Nikita,
Thank you for reaching out to Microsoft Q&A forum!
To enforce a strict token limit when using Azure's OpenAI REST API, start by understanding that the max_tokens
parameter only caps the response tokens, not the total input tokens from prompts and external data sources. Since your input, especially when including results from Azure Search, can significantly inflate token usage, consider limiting the number of documents retrieved (top_n_documents
) and selectively mapping only essential fields. Additionally, preprocess the data retrieved from Azure Search by truncating or summarizing it before sending it to OpenAI. This approach will help manage the total token count effectively.
I hope you understand. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful.