Disclosure: this tutorial is published by CheapClankers, an independent developer API service. It uses our endpoint as a concrete example; it is not an OpenAI endorsement or a ChatGPT subscription. Prepared with AI; the companion examples were verified against a local mock API, not production inference.
When moving a small application to an OpenAI-compatible endpoint, a failed request is often a configuration problem. Before changing your prompt, separate three questions: did the request reach the right path, can the key access the model, and does that model support the operation?
Here is a small Node.js workflow for answering the first two questions without hiding retries.
Give the SDK the API root
Use Node.js 22 or later and install a known SDK version:
npm install openai@7.60.0
In Bash or zsh, set a server-side key and an exact model ID that supports chat:
export CLANKER_API_KEY="your_key_here"
export CLANKER_MODEL="your_enabled_chat_model_id"
In PowerShell, use $env:CLANKER_API_KEY = "your_key_here" and $env:CLANKER_MODEL = "your_enabled_chat_model_id" instead. Never ship this private key in frontend JavaScript.
Save this as check.mjs. The extension enables import and top-level await without changing your project's module settings.
import OpenAI from "openai";
const apiKey = process.env.CLANKER_API_KEY;
const model = process.env.CLANKER_MODEL;
if (!apiKey || !model) {
throw new Error("Set CLANKER_API_KEY and CLANKER_MODEL in this shell.");
}
const client = new OpenAI({
apiKey,
baseURL: "https://api.cheapclankers.com/v1",
maxRetries: 0,
timeout: 30_000,
});
const models = await client.models.list();
if (!models.data.some((item) => item.id === model)) {
throw new Error("Selected model was not returned for this key.");
}
const response = await client.chat.completions.create({
model,
messages: [{ role: "user", content: "Say hello in one sentence." }],
max_tokens: 128,
});
console.log(response.choices[0]?.message.content);
Run node check.mjs from the same shell. With a valid model, sufficient credit and an available route, expect a short greeting. This performs a real, metered completion.
The SDK adds operation paths to baseURL. In this configuration, model listing goes to /v1/models, and the completion goes to /v1/chat/completions. Do not use the full completion URL as the base: it is a resource path, not the API root.
A model list is an access check
Finding the ID in the list does not prove that its upstream is online or that it supports every OpenAI operation. Check the model's current protocol and status before using chat completions. A Responses-only model needs a different request shape and endpoint; changing a prompt cannot fix that mismatch.
A 401 suggests checking credentials. A 403 can indicate a restriction on the key. A 404 can indicate an unavailable model or unsupported protocol. If a request reports insufficient credit, inspect the wallet rather than changing SDK settings.
Retry deliberately
This diagnostic example uses maxRetries: 0, so one failed SDK operation does not automatically become several attempts. The timeout limits how long the client waits; it does not prove that the server stopped working or that no usage was incurred. Keep the request ID and check dashboard usage before resending an interrupted request.
The companion GitHub examples include complete scripts and a loopback-only mock test harness for both Node.js and Python.
For a step-by-step configuration walkthrough, see the OpenAI Node.js SDK setup guide. The CheapClankers API documentation covers account setup and supported protocols. For client behavior beyond this example, use the official JavaScript SDK documentation.
Top comments (0)