I am trying call openAI with my custom index created on Elastic search but when I try to run it I am getting following error:
openai.BadRequestError: Error code: 400 - {'error': {'requestid': 'aaa-bbb-404d-8a12-3da23608f42c', 'code': 400, 'message': 'Validation error at #/dataSources/0/Elasticsearch/parameters: Value error, Invalid credentials configuration. Please use either key and keyId together, or just apiKey.'}}
Welcome! I assume you are using the Chat Completion API from OpenAI? Which version of the library are you using, and is it for Python or JavaScript? Also are you using the legacy or latest chat completion API or another call?
Normally when I've done this myself in JavaScript I've used the Elasticsearch client to pull the required documents and pass via the prompt messages rather than pass the connection details to OpenAI. But for your error I would double check the connection details are correct and that the API key has the correct entitlements to the index as it looks like OpenAI can't access with the provided connection settings.
Thanks for providing the additional snippet and confirming you're using the AzureOpenAI library. Is the dataSources setting compatible with other sources aside from AzureCognitiveSearch? That's the only option I seem to find examples for when I search for this setting.
Yes I can see if update datasource type to some unsupported option then I get error:
openai.BadRequestError: Error code: 400 - {'error': {'requestid': 'abc-xyx-12bg-aa88-b7abc9a415fb', 'code': 400, 'message': "Validation error at #/dataSources/0: Input tag 'test_Elasticsearch' found using 'type' does not match any of the expected tags: 'AzureCognitiveSearch', 'Elasticsearch', 'AzureCosmosDB', 'Pinecone', 'AzureMLIndex'"}}
Thanks for confirming @Saurabh_Agrawal2. I would recommend double checking your key, endpoint and index name are correct, and that the API key has sufficient permissions on the index you are trying to access.
Aside from that, as it's an Azure API, it might be worth trying the Azure forums if the key looks to have sufficient permissions to see if the bad request error can be resolved.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.