Python: Bug: Python: AzureRealtimeWebsocket works only with hardcoded api_key in the script. #11639
Labels
ai connector
Anything related to AI connectors
bug
Something isn't working
python
Pull requests for the Python Semantic Kernel
Describe the bug
A clear and concise description of what the bug is.
Looks like websocket connection is not using the same authentication method/variables same as azure ai settings. When I pass the value of api_key as hardcoded value in the script, then AzureRealtimeWebsocket works file. else, if i pass the api_key using environment variables, it is error out with websocket connection reject.
To Reproduce
Steps to reproduce the behavior:
api_version="2024-10-01-preview",
api_key=key
)
where key is defined as below:
load_dotenv()
key=os.getenv("AZURE_OPENAI_API_KEY")
This gives the below error:
websockets.exceptions.InvalidStatus: server rejected WebSocket connection: HTTP 401
and as per logs:
DEBUG:websockets.client:> api-key: 9dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3j
where as the right key is:
5MxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFk
when i pass the above key like below:
realtime_agent = AzureRealtimeWebsocket(
api_version="2024-10-01-preview",
api_key="5MxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFk"
)
everything works fine,
this is not as per the api_key best practices as it exposes the api_key in the code.
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
Additional context
Add any other context about the problem here.
Covered above everything.
The text was updated successfully, but these errors were encountered: