feat: Implement OpenRouter API client for managing headers and retrieving model pricing.
This commit is contained in:
19
OpenRouter/OpenRouterHeaders.cs
Normal file
19
OpenRouter/OpenRouterHeaders.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,11 @@ internal sealed class PricingProvider
|
||||
private static readonly HttpClient Http = new();
|
||||
private Dictionary<string, ModelInfo>? _models;
|
||||
|
||||
static PricingProvider()
|
||||
{
|
||||
OpenRouterHeaders.ApplyTo(Http);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the full model list from OpenRouter (cached after first call).
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user