NexGate

Switching from OpenAI

Migrate OpenAI-compatible SDK code to NexGate by changing the base URL and API key.

The migration

Switching to NexGate usually requires two configuration changes:

  1. Set the base URL to https://api.nexgate.app/v1.
  2. Use a NexGate API key that starts with ng-.

Note

Request and response shapes remain OpenAI-compatible for chat completions. NexGate does not currently expose embeddings or image generation.

Before and after

# Before: OpenAI
from openai import OpenAI

client = OpenAI(api_key="sk-proj-abc123")

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)
# After: NexGate
from openai import OpenAI

client = OpenAI(
    api_key="ng-your-key",
    base_url="https://api.nexgate.app/v1",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello"}],
)
// Before: OpenAI
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-proj-abc123",
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello" }],
});
// After: NexGate
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "ng-your-key",
  baseURL: "https://api.nexgate.app/v1",
});

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

Environment variables

OPENAI_API_KEY=sk-proj-abc123
OPENAI_API_KEY=ng-your-key
OPENAI_BASE_URL=https://api.nexgate.app/v1

Then create the SDK client from environment variables if your SDK supports it.

from openai import OpenAI

client = OpenAI()

Warning

Keep API keys server-side. Do not ship ng- keys in public frontend bundles.

Compatible features

Streaming

Use stream=True or stream: true for Server-Sent Events.

Function calling

Send tools and tool_choice with OpenAI-compatible tool schemas.

JSON output

Use response_format with json_object or json_schema.

Sampling controls

Use temperature, top_p, penalties, stop, and seed.

Parameter differences to know

AreaOpenAI-compatible behavior in NexGate
Base URLMust be https://api.nexgate.app/v1
API keyMust be a NexGate key in Authorization: Bearer ng-...
Request bodyCapped at 64KB
Messages1 to 100 messages
Output limitmax_tokens or max_completion_tokens, depending on model family
TimeoutProvider calls time out after 120 seconds
BillingCredits are reserved before the provider call and finalized after actual usage is known

Tip

For GPT-5 and o-series style models, NexGate forwards the output ceiling using max_completion_tokens; older chat and compatible third-party models use max_tokens.

LangChain

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-5.5",
    openai_api_key="ng-your-key",
    openai_api_base="https://api.nexgate.app/v1",
)

response = llm.invoke("What is NexGate?")
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  modelName: "gpt-5.5",
  openAIApiKey: "ng-your-key",
  configuration: {
    baseURL: "https://api.nexgate.app/v1",
  },
});

const response = await llm.invoke("What is NexGate?");

Common migration errors

ErrorFix
401 authentication_errorUse Authorization: Bearer ng-your-key and confirm the key was generated in the dashboard
400 invalid_request_errorCheck JSON shape, message limits, model ID, and request body size
402 insufficient_creditsAdd credits before retrying
429 rate_limit_errorIncrease the hourly spend safety limit or wait for the window to clear
502 provider_errorRetry later or switch to another enabled model

Why switch?

On this page