Accesing external API(openAI api)
friendlyonedev
HOBBYOP

10 months ago

Hey guys. I'm a fairly beginner at this kind of stuff, so forgive me if I ask dumb questions.

I have a problem, my server runs fine on local, but hosting on Railway I get this error from this part of the script

Session c7842f9c inner AI error: APIConnectionError:Connection error.

        try:
            response = client.chat.completions.create(
                model="gpt-4.1-mini",
                messages=self.messages,
                temperature=0.1,
            )
        except Exception as e:
            print(
                f"Session {self.session_id} inner AI error:  {type(e).__name__}:{str(e)}",
                flush=True,
            )
$10 Bounty

9 Replies

friendlyonedev
HOBBYOP

10 months ago

N/A


friendlyonedev
HOBBYOP

10 months ago

I would've given it I just donn't know where to find it


friendlyonedev
HOBBYOP

10 months ago

And i'm in a hurry because this is for hackathon


friendlyonedev
HOBBYOP

10 months ago

APIConnectionError Cause: Issue connecting to our services.

Solution: Check your network settings, proxy configuration, SSL certificates, or firewall rules.

Can I edit firewall settings on railway?


10 months ago

what is the value you've set for the API endpointvariable on Railway?


tannerchiang

what is the value you've set for the `API endpoint`variable on Railway?

friendlyonedev
HOBBYOP

10 months ago

I don't have API endpoint set up. Where can I find it and what to set for it?


turborx
FREE

10 months ago

hi, make sure you’ve added your openai key as an env var named OPENAI_API_KEY in railway’s variables tab, then redeploy. the openai library will default to https://api.openai.com/v1. if you’re using OpenRouter instead, also set OPENAI_API_BASE=https://openrouter.ai/v1 alongside OPENAI_API_KEY. after redeploy, your client.chat.completions.create calls should succeed without needing any custom endpoint.


friendlyonedev
HOBBYOP

10 months ago

Yes, I did add the key into the var as supposed to. Just didn't know I had to do anything more then that


turborx
FREE

10 months ago

no worries! after adding the key, just make sure to redeploy your project so the new env vars take effect. if you’re using openrouter, also set OPENAI_API_BASE=https://openrouter.ai/v1. otherwise, the default base url will be fine for openai directly.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...