Serp API call fails with a Custom GPT

I am trying to use Serper API with a custom GPT, but I just keep on getting 403 or an empty dict back. I have used the same key with crew.ai and also tried a little Python script with with the key which works. I am not that experienced with APIs so I am quite dependent on ChatGPT answers, which so far have not worked.

I saw somebody asking the same question in February but without any responses so I am asking again.
Also, is there any better way to get the schemas for custom GPTs that ChatGPT?
I tried pasting the schema but it contained a link to google which isnt allowed…
Many thanks in advance.

PYTHON SCRIPT to check the API KEY validity

import http.client
import json

conn = http.client.HTTPSConnection(“google.serper.dev”)
payload = json.dumps({
“q”: “apple inc”
})
headers = {
‘X-API-KEY’: ‘MY API KEY’,
‘Content-Type’: ‘application/json’
}
conn.request(“POST”, “/search”, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))

1 Like