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