Skip to content

OpenAI SDK

Use the OpenAI SDK with Model Gate Chat Completions or Responses.

No current prepared translation is available. The English source is shown without machine translation.

OpenAI SDK through Model Gate

Python

from openai import OpenAI

client = OpenAI(
    api_key="mg_live_...",
    base_url="https://api.model-gate.com/v1",
)

response = client.chat.completions.create(
    model="ch-47",
    messages=[{"role": "user", "content": "Hello"}],
)

print(response.choices[0].message.content)

Responses API

response = client.responses.create(
    model="gpt-5.4",
    input="Summarize this release.",
)
print(response.output_text)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.MODEL_GATE_API_KEY,
  baseURL: "https://api.model-gate.com/v1",
});

const response = await client.chat.completions.create({
  model: "ch-46s",
  messages: [{ role: "user", content: "Hello" }],
});

console.log(response.choices[0].message.content);

Dedicated Images integration

The examples above are text calls. An Images integration must explicitly send a stable Idempotency-Key, use the reviewed model/route settings and handle both a completed result and HTTP 202 with an operation ID. Do not assume a high-level SDK image method understands Model Gate polling, private file URLs or the model_gate extension. Disable automatic paid POST retries in the client; read the existing operation after a timeout. The generation, edit and operation HTTP contracts are authoritative.