1
0

Compare commits

..

2 Commits

4 changed files with 32 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
using System.Net.Http;
namespace AnchorCli.OpenRouter;
/// <summary>
/// Provides extension methods for adding OpenRouter-specific HTTP headers.
/// </summary>
public static class OpenRouterHeaders
{
/// <summary>
/// Applies the required OpenRouter headers to the specified HttpClient.
/// </summary>
public static void ApplyTo(HttpClient httpClient)
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("HTTP-Referer", "https://git.technopunk.space/tomi/AnchorCli");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-OpenRouter-Title", "Anchor CLI");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-OpenRouter-Categories", "cli-agent");
}
}

View File

@@ -14,6 +14,11 @@ internal sealed class PricingProvider
private static readonly HttpClient Http = new(); private static readonly HttpClient Http = new();
private Dictionary<string, ModelInfo>? _models; private Dictionary<string, ModelInfo>? _models;
static PricingProvider()
{
OpenRouterHeaders.ApplyTo(Http);
}
/// <summary> /// <summary>
/// Fetches the full model list from OpenRouter (cached after first call). /// Fetches the full model list from OpenRouter (cached after first call).
/// </summary> /// </summary>

View File

@@ -88,9 +88,13 @@ AnsiConsole.Write(infoTable);
AnsiConsole.WriteLine(); AnsiConsole.WriteLine();
// ── Build the chat client with tool-calling support ───────────────────── // ── Build the chat client with tool-calling support ─────────────────────
var httpClient = new HttpClient();
OpenRouterHeaders.ApplyTo(httpClient);
var openAiClient = new OpenAIClient(new ApiKeyCredential(apiKey), new OpenAIClientOptions var openAiClient = new OpenAIClient(new ApiKeyCredential(apiKey), new OpenAIClientOptions
{ {
Endpoint = new Uri(endpoint) Endpoint = new Uri(endpoint),
Transport = new System.ClientModel.Primitives.HttpClientPipelineTransport(httpClient)
}); });
IChatClient innerClient = openAiClient.GetChatClient(model).AsIChatClient(); IChatClient innerClient = openAiClient.GetChatClient(model).AsIChatClient();

View File

@@ -33,9 +33,10 @@ internal static class SetupTui
var models = new List<(string Value, string Description)> var models = new List<(string Value, string Description)>
{ {
("qwen/qwen3.5-397b-a17b", "smart, expensive"), ("qwen/qwen3.5-397b-a17b", "smart, expensive"),
("qwen/qwen3.5-35b-a3b", "cheapest"), ("qwen/qwen3.5-122b-a10b", "faster"),
("qwen/qwen3.5-27b", "fast"), ("qwen/qwen3.5-27b", "fast"),
("qwen/qwen3.5-122b-a10b", "smart"), ("qwen/qwen3.5-Flash", "cloud, fast"),
("qwen/qwen3.5-Plus", "cloud, smart"),
("Custom...", "") ("Custom...", "")
}; };