Search API error through cURL

I am trying to access the search API through cURL but I keep getting “You didn’t provide an API key”. Answers API and file APIs works fine. Below is the cURL command I am using

curl -L -X POST ‘https://api.openai.com/v1/engines/ada/search
-H ‘Authorization: BEARER API_KEY’
-H ‘Content-Type: application/json’
–data-raw ‘{ “documents”: [“White House”, “hospital”, “school”], “query”: “the president”}’

The Answers API call is as follows

curl -L -X POST ‘https://api.openai.com/v1/answers
-H ‘Authorization: BEARER API_KEY’
-H ‘Content-Type: application/json’
–data-raw ‘{
“file”: “file”,
“question”: “Whats an iterator”,
“search_model”: “ada”,
“model”: “curie”,
“temperature”: 0.7,
“examples_context”: “In 2017, U.S. life expectancy was 78.6 years.”,
“examples”: [[“What is human life expectancy in the United States?”, “78 years.”]],
“max_rerank”: 10,
“max_tokens”: 100,
“stop”: ["\n", “<|endoftext|>”]
}’

Hello! Can you post a redacted version of your Answers api call as well to compare against? I can see you redacted your API_KEY but I’m not sure what the extra “s” in the Bearer is for.

Chris

@hallacy updated the post.

I also tried with Java, postman. Even they are not working. The only thing which is working is openai python api calls.

This worked for me:

curl -L -X POST 'https://api.openai.com/v1/engines/ada/search' -H "Authorization: Bearer API_KEY" -H 'Content-Type: application/json' --data-raw '{ "documents": ["White House", "hospital", "school"], "query": "the president"}'

I think you just need to do BEARER->Bearer

4 Likes

@hallacy Thanks a lot, it worked.

1 Like