Problema com pedidos POST à API da OpenAI

Website URL

https://worldonline.infinityfreeapp.com

Error Message

A GET request to https://api.openai.com/v1/models works correctly and returns an HTTP 200 status code.

However, POST requests to the OpenAI API are failing, even though the JSON payload is valid and includes the “model” field.

Other Information

I have already tested using cURL with HTTP/1.1, the Content-Length header, and PHP’s native HTTP transport, but the issue persists.

Welcome to the InfinityFree community forum! Good to have you here.

  • Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
  • Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
  • AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
  • Solving an issue is a joint effort. Try the suggestions you get and report back what happened.

Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.

What exactly happens when the POST fails? I need the HTTP status code and the response body, or the curl_error() text if no response comes back at all. Without that, “fails” could mean a refusal from OpenAI, a connection problem, or something in the script.

I searched the forum and knowledge base and found nothing saying that POST requests to api.openai.com are blocked or limited on InfinityFree. So I can’t say whether the hosting is involved. The error text should show whether the request leaves your site and what OpenAI sends back.

It would also help to see the POST code with the API key removed. Please don’t post the key itself.

Hello! Thank you for your reply.

Here are the exact results of my tests:

  1. GET request to https://api.openai.com/v1/models: HTTP 200, authentication works.
  2. POST request to https://api.openai.com/v1/responses: HTTP 400, missing_required_parameter, message: Missing required parameter: 'model'.
  3. POST request to https://api.openai.com/v1/chat/completions: HTTP 400, message: We could not parse the JSON body of your request.
  4. The JSON is valid locally in PHP and contains the model field.
  5. I tested both cURL and PHP’s native HTTP stream. The problem persists.

The API key is stored in a separate PHP configuration file and I will not share it publicly.

Could you advise how to investigate this further?

Thank you.

This is probably a bit out of scope for most of us here to advise.

Do OpenAI have a support forum? they would be the experts and could probably help more.

Error 2 and 3 very much look like problems with your API call, not something that we as a hosting provider can influence.

It would be good to check that the API request body actually matches what you use locally. Configuration or latent bugs can result in different results which could explain the behavior. Some debug statements in your code to dump the JSON before sending it can help rule out a lot of issues.