How to call Azure OpenAI add your data API

k-o-i 0 Reputation points
2023-12-15T09:33:50.35+00:00

An error occurred when I made the api call. I am at a loss as to the cause. Does anyone know what the problem is?

The following is the response from the API call.

{"error": {"requestid": "c4f88e85-98f0-46e0-8ffa-xxxxxxxxxxxx", "code": 400, "message": "Invalid JSON in request body"}}

The following is the content of the API call.

api_base="https://test_api.openai.azure.com/"
api_key="xxxxxxxxxxxxxxxxxxxxxxxxx"
deployment_id="gpt-4-32k-test"
search_endpoint="https://test_api.search.windows.net"
search_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
search_index="index_name"
curl -i -X POST $api_base/openai/deployments/$deployment_id/extensions/chat/completions?api-version=2023-08-01-preview \
  -H "Content-Type: application/json" \
  -H "api-key: $api_key" \
  -d \
  '
  {
  "dataSources": [
    {
      "type": "AzureCognitiveSearch",
      "parameters": {
        "endpoint": "'$search_endpoint'",
        "key": "'$search_key'",
        "indexName": "'$search_index'"
      }
    }
  ],
  "messages": [{"role":"system","content":"You are an AI assistant that helps people find information."}],
}
  '

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 35,971 Reputation points Moderator
    2023-12-15T10:45:36.2933333+00:00

    k-o-i Greetings!

    {"error": {"requestid": "c4f88e85-98f0-46e0-8ffa-xxxxxxxxxxxx", "code": 400, "message": "Invalid JSON in request body"}}

    Based on the response from the API call, it seems that the JSON in the request body is invalid. Please check the JSON in the request body and make sure it is valid.

    In the content of the API call you provided, there seems to be a syntax error in the JSON.

    There is a comma after the last element in the "messages" array. Removing that comma should fix the issue.

    Please try making the API call again with the corrected JSON and see if it resolves the issue.

    I also see that your issue has been addressed on the Stack overflow

    Do let us know if that helps or have any other queries.

    0 comments No comments

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.