502 (Bad Gateway) for anything but most basic requests

I’m using API Gateway (AWS) for my openai api. If my script has very simple prompt, it works, e.g.

method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
model: ‘gpt-4o’, // Using the same model from your working example
messages: [
{
role: ‘system’,
content: ‘Write a short adventure story.’
}
],
max_tokens: 200,
temperature: 0.7
})
});

But if it’s a bit more compliated, it doesn’t - I get a 502 error. E.g.

method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
model: ‘gpt-4o’, // Using the same model from your working example
messages: [
{
role: ‘system’,
content: ‘Write a short adventure story with 5 comprehension questions at the end.’
}
],
max_tokens: 200,
temperature: 0.7
})
});

Increasing the max tokens doesnt help. Any ideas?
Thanks

Hmm error code 502 sounds more like a problem with AWS and not openAI

I’ve googled AWS API Gateway Payload size default - which came out as 10MB - so I guess that won’t be the case… but maybe you get any errors inside AWS? Write some logs to S3 and have a look at that?

Could also be a problem of location in some cases - in which region did you deploy?

And could you also try the same request from your local machine?

2 Likes

That’s very useful, thanks. I’ll try running from local machine as a test - great idea.

Hey jochenschultz

Just to say, your suggestion worked! I increased memory and timeout in the Lambda function in AWS and now it works perfectly. Thanks again.

2 Likes

You are welcome.

Post must be at least 25 characters.

1 Like