How to try open-weight models through OpenRouter

By

Tagged: AI

Compare open-weight models from JavaScript through OpenRouter, inspect current prices and token usage, and decide what deserves a local download.

Downloading a model takes time and disk space. Before filling up your drive, you can test a hosted copy on a few real tasks first.

OpenRouter puts dozens of providers behind one API, covering both open-weight models you can later download and closed API-only models.

We’ll send the same support message to two open-weight models, check that they return billing with a summary of at most 12 words, and inspect what they cost. Since this runs on hosted infrastructure, your prompt goes to OpenRouter and the inference provider behind it, so stick to sample data while testing.

Fig 1 · 1/4Compare one prompt across models
Use exact model IDs from the current catalog.

Pick comparable models

Let’s compare qwen/qwen3-14b and qwen/qwen3-32b from OpenRouter’s model catalog API. Both come from the same family at two different sizes, so keeping the prompt identical shows whether the larger model actually performs better here.

Prices and availability shift over time, so our script checks the live catalog before spending anything. Keep in mind that an OpenRouter ID points to a hosted endpoint, not a local file. When you’re ready to download weights, follow the Hugging Face ID and pick the format your local runner expects, since GGUF and MLX are different builds. My open weights guide explains what the creator publishes and what the license covers, as using a model through OpenRouter doesn’t change the redistribution rules.

Create an API key

Create an OpenRouter account, add a bit of credit if needed, and generate a key on the API keys page.

Set a small spending cap on the key before running experiments. max_tokens limits a single reply, not the total spend across a loop of requests.

You need a recent Node.js release. On macOS, Homebrew can install it:

brew install node

On Omarchy, use its package helper:

omarchy pkg add nodejs

Create the project:

mkdir model-comparison
cd model-comparison

Create .env with your key:

OPENROUTER_API_KEY=your-openrouter-key

Replace the value with the key you created. Put .env in .gitignore before saving this project in Git:

.env

We’ll use Node’s built-in fetch() and --env-file flag, so there are no npm packages to install.

Fetch the catalog before spending money

Create compare.mjs with this complete program:

const ids = ['qwen/qwen3-14b', 'qwen/qwen3-32b']
const key = process.env.OPENROUTER_API_KEY

const prompt = `Return only JSON with keys category and summary.
Category must be billing, bug, or question.
Summary must have at most 12 words.
Message: I paid twice for my subscription. Can you refund one payment?`

async function readJson(url, options = {}) {
  const response = await fetch(url, {
    ...options,
    signal: AbortSignal.timeout(120_000)
  })
  const result = await response.json()

  if (!response.ok || result.error) {
    throw new Error(`API request failed: ${response.status} ${result.error?.message || ''}`)
  }

  return result
}

const catalog = await readJson('https://openrouter.ai/api/v1/models')
const selected = ids.map(id => {
  const model = catalog.data.find(item => item.id === id)
  if (!model) throw new Error(`Model is unavailable: ${id}`)
  return model
})

for (const model of selected) {
  console.log({
    id: model.id,
    weights: model.hugging_face_id,
    inputDollarsPerMillionTokens: Number((model.pricing.prompt * 1_000_000).toFixed(4)),
    outputDollarsPerMillionTokens: Number((model.pricing.completion * 1_000_000).toFixed(4))
  })
}

if (!process.argv.includes('--run')) {
  console.log('Review prices, then add --run to make paid requests.')
  process.exit(0)
}

if (!key) throw new Error('Set OPENROUTER_API_KEY in .env')

for (const model of selected) {
  const started = performance.now()
  const result = await readJson('https://openrouter.ai/api/v1/chat/completions', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${key}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: model.id,
      messages: [{ role: 'user', content: prompt }],
      max_tokens: 1024,
      reasoning: { enabled: false },
      stream: false
    })
  })

  const choice = result.choices?.[0]
  const answer = choice?.message?.content
  console.log(`\n${model.id}`)
  console.log(answer || '(No visible answer)')
  console.log({
    milliseconds: Math.round(performance.now() - started),
    finishReason: choice?.finish_reason,
    usage: result.usage
  })

  try {
    const value = JSON.parse(answer)
    const valid = choice.finish_reason === 'stop' &&
      value !== null && typeof value === 'object' && !Array.isArray(value) &&
      Object.keys(value).sort().join(',') === 'category,summary' &&
      value.category === 'billing' &&
      typeof value.summary === 'string' && value.summary.trim().length > 0 &&
      value.summary.trim().split(/\s+/).length <= 12
    console.log({ passesThisExample: valid })
  } catch {
    console.log({ passesThisExample: false })
  }
}

The first run fetches the public catalog and prints current prices:

node --env-file=.env compare.mjs
{
  id: 'qwen/qwen3-14b',
  weights: 'Qwen/Qwen3-14B',
  inputDollarsPerMillionTokens: 0.1,
  outputDollarsPerMillionTokens: 0.22
}
{
  id: 'qwen/qwen3-32b',
  weights: 'Qwen/Qwen3-32B',
  inputDollarsPerMillionTokens: 0.08,
  outputDollarsPerMillionTokens: 0.28
}
Review prices, then add --run to make paid requests.

The larger model is actually cheaper on input and slightly pricier on output. The catalog reports prices per token, so multiplying by a million makes them easier to read. Treat those numbers as advertised rates, and check the response’s usage field plus your OpenRouter dashboard for what you actually paid.

Send the requests

Once you’ve checked the prices, run:

node --env-file=.env compare.mjs --run

This calls OpenRouter’s chat completions endpoint twice, once per model, using the same sample support message. Setting reasoning: { enabled: false } turns off optional reasoning tokens for this test (check what fields your models support if you swap in a different family). The script checks that the response stopped cleanly, parses as JSON, has only category and summary, picks billing, and keeps the summary nonempty and under 13 words.

Here’s what I got. I removed some of the fields inside usage to keep it short:

qwen/qwen3-14b
{
  "category": "billing",
  "summary": "User paid twice for subscription and requests a refund."
}
{
  milliseconds: 687,
  finishReason: 'stop',
  usage: {
    prompt_tokens: 56,
    completion_tokens: 25,
    total_tokens: 81,
    cost: 0.0000111
  }
}
{ passesThisExample: true }

qwen/qwen3-32b
```json
{
  "category": "billing",
  "summary": "Request refund for duplicate subscription payment"
}
```
{
  milliseconds: 725,
  finishReason: 'stop',
  usage: {
    prompt_tokens: 56,
    completion_tokens: 26,
    total_tokens: 82,
    cost: 0.00001176
  }
}
{ passesThisExample: false }

Both models picked billing and wrote a good summary. The larger one failed anyway, because it wrapped its answer in a Markdown code fence and JSON.parse() throws on that.

The prompt said “Return only JSON”, and the smaller model followed it. If the next part of your application expects plain JSON, that matters more than which summary reads better.

The script only checks JSON shape, category, and word count, so read the summaries yourself too.

Understand the usage

OpenRouter documents all the usage fields in its usage accounting guide, including token counts and cost when the provider reports it. In my run, each call cost around a thousandth of a cent: $0.0000111 for the 14B model and $0.00001176 for the 32B model.

Log the full usage object while you test. Reasoning tokens still show up on your bill even when the visible reply is tiny, and a reply that stops because it hit max_tokens needs a closer look before you blame the model.

Elapsed time covers both network latency and inference, and 687ms vs 725ms is too close to read anything into from a single request, especially since OpenRouter can route the same model to different providers between runs. Also note that this script stops on the first error; if you rerun it, earlier models get called and billed again, so save completed rows to disk when running larger batches.

Make the comparison useful

Swap that single prompt for a small set of sample messages that look like your real app’s traffic, including an ambiguous message and one that tries to break your output format. Write down the expected category before looking at any model replies, and decide upfront how your app should handle messages that fit two categories.

Run the exact same prompts across every model, keep failures in the results, and compare the summaries by hand against what you’d write yourself. A hosted run tells you which models are worth downloading, and since local quantization can change behavior, run the same test suite locally once you pull the weights. How to run an LLM locally walks through that next step. For a look at a frontier open-weight coding model you can test through OpenRouter before touching AWS Bedrock or 626 GB of weights, see my Amazon Ergo tutorial.

Want me to talk about your product? You can sponsor this site.

Related posts about ai: