GuidesOpenAI SDK
Troubleshoot OpenAI SDK + Gateway
Fix connection, authentication, and model ID issues when using the OpenAI SDK with ORGN Gateway.
Incorrect base_url
client = OpenAI(
base_url="https://api.gateway.orgn.com/v1",
api_key=os.environ["OLLM_API_KEY"]
)Common mistakes: omitting base_url, using https://api.gateway.orgn.com without /v1, appending /chat/completions.
Authentication (401)
- Regenerate key in the Gateway console.
- Confirm env var:
echo $OLLM_API_KEY - Restart after updating credentials.
Model not found
Use underscore IDs:
model="near_glm_4_7" # correct
# not: near/GLM-4.6Response handling
if hasattr(response, "choices") and response.choices:
print(response.choices[0].message.content)Streaming
for chunk in stream:
if chunk.choices and chunk.choices[0].delta:
print(chunk.choices[0].delta.get("content", ""), end="")Verify in console
If unsure whether requests reach Gateway, check the Gateway console for incoming requests.
Checklist
-
base_url=https://api.gateway.orgn.com/v1 - Valid
sk-ollm-*key - Underscore model ID
- Guarded response parsing
Integrate ORGN Gateway with the OpenAI SDK
Configure the OpenAI SDK to route inference through ORGN Gateway — swap base URL, API key, and model IDs.
Migrate to ORGN Gateway from OpenAI
Migrate an existing OpenAI application to ORGN Gateway with minimal code changes — swap base URL, API key, and model IDs.