Install the SDK in a server-side Node.js project.
- Create a scoped API key in the BrokenGPT dashboard.
- Install the client with npm install openai.
- Put BROKENGPT_API_KEY in your host secret store or local .env file that is excluded from Git.
INSTALL
npm install openai
# .env.local (never commit this value)
BROKENGPT_API_KEY=your-keyCreate the client with the BrokenGPT base URL.
Run this code only on your server, worker, or trusted command line. The base URL is https://brokengpt.com/v1 and the public model alias is broken-one.
NODE.JS
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.BROKENGPT_API_KEY,
baseURL: "https://brokengpt.com/v1",
});
const response = await client.chat.completions.create({
model: "broken-one",
messages: [{ role: "user", content: "Give me three test cases." }],
});
console.log(response.choices[0]?.message?.content);Iterate streamed chunks and handle an interrupted stream.
In an HTTP application, propagate caller cancellation and avoid assuming every stream ends normally. Keep partially generated content separate from committed application state until your completion policy accepts it.
NODE.JS STREAM
const stream = await client.chat.completions.create({
model: "broken-one",
messages: [{ role: "user", content: "Draft a concise release note." }],
stream: true,
});
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content;
if (text) process.stdout.write(text);
}Make the integration observable and bounded.
- Set an application timeout and abort requests that no longer have a caller.
- Handle 400, 401, 403, 404, 429, and 5xx responses by category.
- Use bounded exponential backoff only for retryable responses.
- Validate JSON and tool arguments before they reach databases, shells, or external APIs.
- Track latency, usage, and request IDs without logging credentials.