Origin Docs
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)

  1. Regenerate key in the Gateway console.
  2. Confirm env var: echo $OLLM_API_KEY
  3. Restart after updating credentials.

Model not found

Use underscore IDs:

model="near_glm_4_7"  # correct
# not: near/GLM-4.6

Response 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

On this page