rig icon indicating copy to clipboard operation
rig copied to clipboard

feat: add OpenRouter support

Open critx-jeti opened this issue 1 year ago • 3 comments

Feature Request

OpenRouter is a popular interface towards multiple LLMs. It provides an abstraction for various models with a unified API. Adding support for OpenRouter allows for the use of a multitude of additional LLMs with just a single added provider.

Proposal

It makes most sense to implement an providers::openrouter that implements CompletionModel and EmbeddingModel traits. OpenRouter supports using the OpenAI SDK or the OpenRouter API directly, so an implementation could likely re-use large majorities of the providers::openai implementation.

critx-jeti avatar Jan 09 '25 08:01 critx-jeti

Hey @BitVortex! If the openrouter API is exactly the same as the OpenAI API (which seems to be the case), then you can simply reuse the existing openai client by changing the url using from_url, e.g.:

use rig::providers::openai;

let openrouter = openai::Client::from_url("OPENROUTER_API_KEY", "https://openrouter.ai/api/v1");

cvauclair avatar Jan 14 '25 16:01 cvauclair

@cvauclair I think it can be encapsulated in the way I did before. However, since openrouter is compatible with openai, it doesn't seem necessary to do so.

lispking avatar Feb 19 '25 11:02 lispking

There is an issue with the use openai::client calling the openrouter api, which may be due to lack of compatibility or incomplete compatibility

shenshouer avatar Mar 07 '25 11:03 shenshouer