GuidesMigration
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.
ORGN Gateway exposes an OpenAI-compatible API. Use the same OpenAI SDK — change base_url, your Gateway API key (sk-ollm-*), and model IDs.
Prerequisites
- ORGN account and Gateway API key
- Python 3.8+ (examples below)
pip install openaiBasic configuration
from openai import OpenAI
client = OpenAI(
base_url="https://api.gateway.orgn.com/v1",
api_key="sk-ollm-YOUR_API_KEY"
)Chat completion
Specify the model explicitly. IDs use underscores:
response = client.chat.completions.create(
model="near_glm_4_7",
messages=[
{"role": "user", "content": "Why is the sky blue?"}
]
)
print(response.choices[0].message.content)| OpenAI model (example) | Gateway TEE alternative | Gateway ZDR alternative |
|---|---|---|
gpt-4o | near_glm_4_7 | vercel_gpt_4o |
gpt-4-turbo | near_glm_5 | vercel_claude_sonnet_4_6 |
Browse the live catalog: GET https://api.gateway.orgn.com/v1/models or the Gateway console.
Environment variables (recommended)
export OLLM_API_KEY="sk-ollm-YOUR_API_KEY"import os
client = OpenAI(
base_url="https://api.gateway.orgn.com/v1",
api_key=os.environ["OLLM_API_KEY"]
)OLLM_API_KEY is the legacy env var name; keys use the sk-ollm- prefix.
Streaming
stream = client.chat.completions.create(
model="near_glm_4_7",
messages=[{"role": "user", "content": "Write about secure AI."}],
stream=True
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta:
print(chunk.choices[0].delta.get("content", ""), end="")Common errors
| Error | Fix |
|---|---|
| 401 | Verify sk-ollm-* key and base_url includes /v1 |
| Model not found | Use underscore IDs from /v1/models — not OpenAI names or slash format |