openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Getting the error 'Validation error at #/stream_options: Extra inputs are not permitted' when adding extra_body and stream options at the same time

Open Imaginarybandit opened this issue 1 year ago • 2 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [x] This is an issue with the Python library

Describe the bug

I am trying get the token usage of a streamed response. It has an extra_body to get info from a Azure Search Service index. When I use the stream_options={ "include_usage" : True} it works and returns the token usage and when i use the extra body with my Azure Search Service it returns an answer using the data. But when use both of them at the same time i get this error 'Validation error at #/stream_options: Extra inputs are not permitted'.

To Reproduce

To reproduce the error just run the code snippet below.

Code snippets

import os
import openai
import dotenv

dotenv.load_dotenv()

endpoint = ""
api_key = ""
deployment = ""

client = openai.AzureOpenAI(
    azure_endpoint=endpoint,
    api_key=api_key,
    api_version="2024-09-01-preview",
    
)

completion = client.chat.completions.create(
    model=deployment,
    messages=[
        {
            "role": "user",
            "content": "Demuestrame informacion sobre agricultura",
        },
    ],
    extra_body={
        "data_sources":[
            {
                "type": "azure_search",
                "parameters": {
                    "endpoint": "https://Search_Service_Endpoint.search.windows.net",
                    "index_name": "index",
                    "authentication": {
                        "type": "system_assigned_managed_identity",
                        
                    }
                }
            }
        ],  
    },
    stream=True,
    stream_options={ "include_usage" : True}
)

print(completion)

OS

Windows

Python version

Python v311.3

Library version

openai 1.72.0

Imaginarybandit avatar Apr 09 '25 17:04 Imaginarybandit

To my understanding this is not a problem of the Python client but indeed of the underlying API. The API seems not to be able to handle token counting when external datasources are provided.

Quote

When using the chat/completions API with stream: true and the data_sources parameter for RAG, the response does not include usage details (like token counts). This is a known limitation with the current API behaviour. source

jb-- avatar Apr 25 '25 07:04 jb--

Thanks for reporting!

This sounds like an issue with the underlying OpenAI API and not the SDK, so I'm going to go ahead and close this issue.

Would you mind reposting at community.openai.com?

RobertCraigie avatar May 02 '25 00:05 RobertCraigie