← All posts

Move an OpenAI-compatible SDK integration to Gatepx

Change the endpoint, key, and model ID, then test the capabilities your application relies on.

Gateway Premium

If your application already uses an OpenAI-compatible client, a Gatepx integration can start with its existing chat workflow. Configure a Gatepx base URL, a Gatepx API key, and an enabled model ID. Then test the actual features your application uses before moving production traffic.

Configure a server-side JavaScript client

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.gatepx.ai/v1",
  apiKey: process.env.GATEPX_API_KEY,
  maxRetries: 0, // Start without automatic retries during integration checks.
});

const response = await client.chat.completions.create({
  model: process.env.GATEPX_MODEL,
  messages: [{ role: "user", content: "Hello from my application." }],
});

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

Set GATEPX_MODEL to a chat-capable ID available to your key. Keep both environment variables on the server. The explicit retry setting makes an initial test easier to inspect; choose a bounded retry policy for the final application after understanding its workload.

Configure a Python client

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.gatepx.ai/v1",
    api_key=os.environ["GATEPX_API_KEY"],
    max_retries=0,
)

response = client.chat.completions.create(
    model=os.environ["GATEPX_MODEL"],
    messages=[{"role": "user", "content": "Hello from my application."}],
)

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

The official SDKs accept a configurable base URL. Keep your SDK version pinned in your application and consult the JavaScript SDK or Python SDK documentation for version-specific behavior.

Test the compatibility you need

  • Start with a plain text chat request and validate the response shape consumed by your application.
  • If you stream output, check empty chunks, completion, cancellation, and partial failures.
  • If you use tools, vision, or structured output, test those features against the selected model and provider path.
  • Compare your application logs with dashboard usage and review the applicable model price.

A shared API shape does not mean every model supports every OpenAI parameter or endpoint. Remove assumptions from your integration one feature at a time. Preserve a fallback configuration for your application while validating the change.

Move traffic in a controlled step

Use a separate key for the initial integration. Test a representative set of requests before changing the production configuration. Monitor error responses, output handling, and usage after the change, and keep sensitive prompts and keys out of diagnostic logs.

See the migration documentation for the current reference. If a plain request works but a larger workflow fails, the API troubleshooting guide helps separate configuration problems from model capability or request errors.

Try it with your own traffic

Point your OpenAI SDK at api.gatepx.ai/v1 and choose an enabled model.