Loading…
Loading documentation...
Pick a model for a feature from your own examples: how often it is right, how long it takes and what it costs, written down so the choice can be changed later.
Commands checked on 2026-10-27 with Node.js 24, openai 7.32.
A small evaluation you can run against any model with an OpenAI-compatible API: your own examples, a script that asks each candidate model every example and prints how many it got right, its median response time, the tokens it used and what 1,000 requests would cost. You will pick a model from those numbers and write the choice down with the date, so the next person can run the same check when a new model or a new price appears.
Before comparing models, write four facts about the feature, because they decide which numbers matter:
Ten to fifty examples drawn from what the feature will really see are worth more than any public benchmark. Each line holds a prompt and a short text the right answer must contain.
mkdir -p ~/model-eval && cd ~/model-eval
npm init -y >/dev/null
npm install openai@7.32.0
cat > examples.jsonl <<'EOF'
{"input": "What is 17 times 23? Answer with the number only.", "expect": "391"}
{"input": "Which HTTP status code means Not Found? Answer with the number only.", "expect": "404"}
{"input": "Extract the year from this sentence: The company was founded in March 2014 in Dallas. Answer with the year only.", "expect": "2014"}
{"input": "Is 70000 a valid TCP port number? Answer yes or no.", "expect": "no"}
EOF
Replace these four with your own. Choose expect texts that only a right answer contains.
One entry per model. apiKeyEnv names the environment variable that holds its key, so no key is written in the file. The prices are dollars per million tokens, copied from the provider's page.
cat > candidates.json <<'EOF'
[
{ "name": "candidate-a", "baseURL": "YOUR_BASE_URL", "model": "YOUR_MODEL", "apiKeyEnv": "MODEL_A_KEY", "inputPerMTok": 0.5, "outputPerMTok": 1.5 }
]
EOF
Add a second and third entry for the other models you are considering, each with its own key variable.
For every candidate it sends each example, checks the answer, and reads the token counts the API reports with every answer.
cat > eval.mjs <<'EOF'
import { readFileSync } from "node:fs";
import OpenAI from "openai";
const examples = readFileSync("examples.jsonl", "utf8").trim().split("\n").map((line) => JSON.parse(line));
const candidates = JSON.parse(readFileSync("candidates.json", "utf8"));
for (const c of candidates) {
const client = new OpenAI({ apiKey: process.env[c.apiKeyEnv], baseURL: c.baseURL });
let passed = 0, tokensIn = 0, tokensOut = 0;
const times = [];
for (const example of examples) {
const started = Date.now();
const reply = await client.chat.completions.create({
model: c.model,
messages: [{ role: "user", content: example.input }],
max_tokens: 1000,
});
times.push(Date.now() - started);
const text = reply.choices[0]?.message?.content ?? "";
if (text.toLowerCase().includes(example.expect.toLowerCase())) passed += 1;
tokensIn += reply.usage?.prompt_tokens ?? 0;
tokensOut += reply.usage?.completion_tokens ?? 0;
}
times.sort((a, b) => a - b);
const median = times[Math.floor(times.length / 2)];
const costPer1000 = (1000 / examples.length) * (tokensIn * c.inputPerMTok + tokensOut * c.outputPerMTok) / 1e6;
console.log(`${c.name}: ${passed}/${examples.length} right, median ${(median / 1000).toFixed(1)} s, ` +
`${Math.round(tokensIn / examples.length)} tokens in and ${Math.round(tokensOut / examples.length)} out per request, ` +
`$${costPer1000.toFixed(2)} per 1,000 requests`);
}
EOF
export MODEL_A_KEY='YOUR_API_KEY'
node eval.mjs
Each candidate prints one line: how many examples it got right, its median time, the tokens per request in and out, and the cost of 1,000 requests at the prices you entered. A model that reasons before it answers counts its reasoning as output tokens, so its line shows more output, more time and more cost for the same answer.
Take the cheapest candidate that meets the quality bar and the time budget. Then record it next to the code, so the reason survives:
cat > MODEL_CHOICE.md <<'EOF'
# Model for the answer feature
Chosen: candidate-a (YOUR_MODEL at YOUR_BASE_URL), on the date you ran it.
Measured with model-eval: paste its line from node eval.mjs here.
Rejected: paste each other candidate's line, with why it lost.
Run node eval.mjs again before changing model, and when a provider changes its prices.
EOF
Keep the model's name in a setting, not in the code, so changing model is a change of one value.
Run the comparison twice and check that the counts agree:
node eval.mjs
node eval.mjs
The number right should match between runs. If it moves, the examples are too few or too vague to tell models apart: add more, or make each expect text something only a right answer contains.
Missing credentials. Please pass an apiKey. The variable named in apiKeyEnv is empty in this shell, so the SDK stops before it sends anything. export it again in the same terminal you run the script from.401 or Incorrect API key. The provider refused the key: it is wrong, revoked, or for another provider.404 or model not found. The model name or the base address is wrong for that provider; most list their models at YOUR_BASE_URL/models.examples.jsonl and run it again.429. The provider limits requests per minute. Run fewer candidates at once, or wait and run again.Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.