google-cloud-platformopenai-api

CloudFlare 400 Error When Calling OpenAI Completions API on CloudRun


Running into a weird error where I get a 400 error from cloud-flare when calling the completions API from GCP Cloud Run. The error doesn't occur locally for identical requests.

The error response:

<html>

<head><title>400 Bad Request</title></head>

<body>

<center><h1>400 Bad Request</h1></center>

<hr><center>cloudflare</center>

</body>

</html>

The request: POST to https://api.openai.com/v1/chat/completions

{"model":"gpt-4-turbo","messages":[{"role":"system","content":"Using the notes provided, write a summary of the critical information from the notes.\nThe summary should be in dotpoints. Prioritise the dotpoints by importance."},{"role":"user","content":"                Use only the following information to generate the summary:\n                            There are the following notes about the contact:\n            Note Content: \"Test\"\nNote Created At: 2024-09-26T07:08:04.304501Z\nNote is in the context of: Just the contact in the role of Unknown \nNote type: Manual"}]}

Nothing obvious in the headers.

Has anyone run into anything similar. Wondering if its some kind of IP blocking by cloudflare or similar.


Solution

  • So we managed to solve this by switching from using the OkHttp java client, to using the Java 17 core library client.

    I suspect there is more to it then that (some configuration on the two clients) but we weren't able to find it at this time.