2 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](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,
)
2 Replies
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?
tannerchiang
what is the value you've set for the API endpointvariable on Railway?
2 months ago
I don't have API endpoint set up. Where can I find it and what to set for it?
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](https://openrouter.ai/v1)
alongside OPENAI_API_KEY
. after redeploy, your [client.chat](client.chat).completions.create
calls should succeed without needing any custom endpoint.
Yes, I did add the key into the var as supposed to. Just didn't know I had to do anything more then that
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 OPENAIAPIBASE=https://openrouter.ai/v1. otherwise, the default base url will be fine for openai directly.