Menu

Ruby Gets the Same Deal: Notes on nRouter's Ruby Guide
πŸ“°

Ruby Gets the Same Deal: Notes on nRouter's Ruby Guide

DEV Community: railsΒ·nRouterΒ·about 24 hours ago
#8chLxV6Y
#devtorails#devto#dev#ruby#gateway
Reading 0:00
15s threshold

The Ruby guide makes the same honest move as the other language guides: there is no nRouter Ruby gem to learn. You add the standard ruby-openai gem β€” the one Ruby and Rails teams already reach for β€” and point it at the gateway.

Disclosure: I work on nRouter. The guide is here: https://nrouter.ai/docs/sdks/ruby

Two lines of configuration

Add the gem:

gem "ruby-openai"

Enter fullscreen mode

Exit fullscreen mode

Then build the client with the gateway as its uri_base and your virtual key from the environment:

client = OpenAI :: Client . new ( access_token : ENV . fetch ( "NROUTER_API_KEY" ) , uri_base : "https://api.nrouter.ai/v1" , )

Enter fullscreen mode

Exit fullscreen mode

Calls are plain ruby-openai: client.chat(parameters: { model: ..., messages: [...] }) , and the response is a plain hash you read with response.dig("choices", 0, "message", "content") .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.