Ruby

routeur.ai is OpenAI-compatible, so the official openai Ruby gem works as-is — just override base_url and pass your routeur.ai key. There is no separate routeur.ai SDK to install.

Install

bundle add openai

Configure

require "openai"

client = OpenAI::Client.new(
  api_key:  ENV["ROUTEUR_KEY"],
  base_url: "https://api.routeur.ai/v1",
)

Chat completion

res = client.chat.completions.create(
  model:    "auto",
  messages: [{ role: "user", content: "hi" }],
)

puts res.choices.first.message.content

Streaming

stream = client.chat.completions.stream_raw(
  model:    "auto",
  messages: [{ role: "user", content: "stream please" }],
)

stream.each do |chunk|
  print chunk.choices.first.delta.content.to_s
end

Choosing a model

Every request picks an upstream model in one of three ways — in this order of precedence:

  1. Routeur-* request headers. If Routeur-Provider or Routeur-Model are set, they win, regardless of what is in the body. Set them via the underlying transport.
  2. An explicit upstream id in model:. Pass something like "gpt-4o-mini" or "claude-3-5-sonnet" to bypass routing rules and pin the request to that model.
  3. model: "auto" (or any alias). Lets routeur.ai pick the upstream model from your routing rules. This is the recommended default.