Skip to main content

Use the OpenAI SDK

Point the OpenAI client at Primex and select a compatible offering in OpenAI SDK Setup. The SDK format is independent of the model's creator.

Install and configure​

Set PRIMEX_API_KEY and PRIMEX_MODEL in the environment that launches your app. Use your key and the exact compatible model ID from Setup. Keep secrets out of source control, logs and frontend bundles.

Python​

Shell
python -m pip install openai
Python
import os
from openai import OpenAI

client = OpenAI(
api_key=os.environ["PRIMEX_API_KEY"],
base_url="https://gateway.primexos.com/v1",
timeout=60,
max_retries=0,
)
response = client.chat.completions.create(
model=os.environ["PRIMEX_MODEL"],
messages=[{"role": "user", "content": "Say hello in one line."}],
)
print(response.choices[0].message.content)

Node.js​

Shell
npm install openai

Save as hello.mjs and run node hello.mjs:

JavaScript
import OpenAI from "openai";

const client = new OpenAI({
apiKey: process.env.PRIMEX_API_KEY,
baseURL: "https://gateway.primexos.com/v1",
timeout: 60_000,
maxRetries: 0,
});
const response = await client.chat.completions.create({
model: process.env.PRIMEX_MODEL,
messages: [{ role: "user", content: "Say hello in one line." }],
});
console.log(response.choices[0].message.content);

These short text examples wait up to 60 seconds and disable automatic retries. A timeout can leave the outcome uncertain; check Usage before sending the request again. Choose operation-specific deadlines and retry behavior with the Production guide.

Verify and extend​

Expect a successful response with text in choices[0].message.content. Inspect the request in Usage. Then add streaming or tools if supported.

For Responses, choose an offering that explicitly supports that protocol and follow the Responses reference. This guide's chat example does not imply every OpenAI endpoint or feature is served by Primex.

Use the official OpenAI SDK documentation for client configuration, and Primex's API formats and endpoint references for gateway-specific support. Check automatic retries and timeouts before production; see Production.