.NET

routeur.ai is OpenAI-compatible, so the official OpenAI NuGet package works as-is — just override the endpoint and pass your routeur.ai key. There is no separate routeur.ai SDK to install.

Install

dotnet add package OpenAI

Configure

using System;
using System.ClientModel;
using OpenAI;
using OpenAI.Chat;

var options = new OpenAIClientOptions
{
    Endpoint = new Uri("https://api.routeur.ai/v1"),
};

var key    = new ApiKeyCredential(Environment.GetEnvironmentVariable("ROUTEUR_KEY")!);
var client = new ChatClient(model: "auto", credential: key, options: options);

Chat completion

var res = await client.CompleteChatAsync(
    new UserChatMessage("hi"));

Console.WriteLine(res.Value.Content[0].Text);

Streaming

await foreach (var update in
    client.CompleteChatStreamingAsync(new UserChatMessage("stream please")))
{
    foreach (var part in update.ContentUpdate)
        Console.Write(part.Text);
}

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. Attach them via a custom PipelinePolicy.
  2. An explicit upstream id in ChatClient. Pass something like "gpt-4o-mini" or "claude-3-5-sonnet" to bypass routing rules and pin the request to that model.
  3. "auto" (or any alias). Lets routeur.ai pick the upstream model from your routing rules. This is the recommended default.