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:
- Routeur-* request headers. If
Routeur-ProviderorRouteur-Modelare set, they win, regardless of what is in the body. Set them via the underlying transport. - 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. model: "auto"(or any alias). Lets routeur.ai pick the upstream model from your routing rules. This is the recommended default.