C# SDK

Official C# SDK for HINOW API with async/await and streaming

C# SDK

Install and configure the HINOW C# SDK to integrate over 100 AI models into .NET applications with async/await and LINQ support.


The HINOW C# SDK provides full access to the HINOW REST API with async/await patterns, IAsyncEnumerable streaming, and comprehensive .NET integration.

> Note: For API resource documentation with code examples, see the API Reference. This page covers C# SDK-specific features and configurations.

Installation

bash
dotnet add package Hinow

Or via Package Manager:

powershell
Install-Package Hinow

Requirements

  • .NET 6.0+

Configuration

Basic Setup

csharp
using Hinow;

var client = new HinowClient("your-api-key");

Environment Variable

bash
export HINOW_API_KEY=your-api-key

csharp
// API key loaded automatically from environment
var client = new HinowClient();

Advanced Configuration

csharp
var client = new HinowClient(new HinowClientOptions
{
    ApiKey = "your-api-key",
    BaseUrl = "https://api.hinow.ai",
    Timeout = TimeSpan.FromSeconds(120),
    MaxRetries = 3
});

Basic Usage

Chat Completions

csharp
using Hinow;

var client = new HinowClient();

var response = await client.Chat.Completions.CreateAsync(new ChatCompletionRequest
{
    Model = "gpt-4o",
    Messages = new[]
    {
        new Message { Role = "system", Content = "You are a helpful assistant." },
        new Message { Role = "user", Content = "What is the capital of France?" }
    },
    Temperature = 0.7,
    MaxTokens = 1024
});

Console.WriteLine(response.Choices[0].Message.Content);

Using Different Models

csharp
// OpenAI GPT-4o
var response = await client.Chat.Completions.CreateAsync(new ChatCompletionRequest
{
    Model = "gpt-4o",
    Messages = new[] { new Message { Role = "user", Content = "Explain machine learning" } }
});

// Anthropic Claude
var response = await client.Chat.Completions.CreateAsync(new ChatCompletionRequest
{
    Model = "claude-sonnet-4-20250514",
    Messages = new[] { new Message { Role = "user", Content = "Explain machine learning" } }
});

// DeepSeek
var response = await client.Chat.Completions.CreateAsync(new ChatCompletionRequest
{
    Model = "deepseek-ai/deepseek-v3.2",
    Messages = new[] { new Message { Role = "user", Content = "Explain machine learning" } }
});

Streaming

csharp
await foreach (var chunk in client.Chat.Completions.CreateStreamAsync(new ChatCompletionRequest
{
    Model = "gpt-4o",
    Messages = new[] { new Message { Role = "user", Content = "Write a story about a robot" } }
}))
{
    var content = chunk.Choices[0].Delta?.Content;
    if (content != null)
    {
        Console.Write(content);
    }
}

Function Calling (Tool Use)

csharp
var response = await client.Chat.Completions.CreateAsync(new ChatCompletionRequest
{
    Model = "gpt-4o",
    Messages = new[]
    {
        new Message { Role = "user", Content = "What is the weather in New York?" }
    },
    Tools = new[]
    {
        new Tool
        {
            Type = "function",
            Function = new FunctionDefinition
            {
                Name = "get_weather",
                Description = "Get the current weather for a location",
                Parameters = new
                {
                    type = "object",
                    properties = new
                    {
                        location = new
                        {
                            type = "string",
                            description = "City and state, e.g., New York, NY"
                        },
                        unit = new
                        {
                            type = "string",
                            @enum = new[] { "celsius", "fahrenheit" }
                        }
                    },
                    required = new[] { "location" }
                }
            }
        }
    },
    ToolChoice = "auto"
});

var toolCalls = response.Choices[0].Message.ToolCalls;
if (toolCalls != null)
{
    foreach (var toolCall in toolCalls)
    {
        Console.WriteLine("Function: " + toolCall.Function.Name);
        Console.WriteLine("Arguments: " + toolCall.Function.Arguments);
    }
}

Image Generation

csharp
var response = await client.Images.GenerateAsync(new ImageGenerateRequest
{
    Model = "black-forest-labs/flux-1-schnell",
    Prompt = "A programmer cat wearing glasses, cartoon style",
    Size = "1024x1024",
    Quality = "hd"
});

foreach (var image in response.Data)
{
    Console.WriteLine("URL: " + image.Url);
}

Embeddings

csharp
var response = await client.Embeddings.CreateAsync(new EmbeddingRequest
{
    Model = "BAAI/bge-base-en-v1.5",
    Input = "Machine learning is fascinating"
});

var embedding = response.Data[0].Embedding;
Console.WriteLine("Dimensions: " + embedding.Length);

Error Handling

csharp
using Hinow;
using Hinow.Exceptions;

try
{
    var response = await client.Chat.Completions.CreateAsync(new ChatCompletionRequest
    {
        Model = "nonexistent-model",
        Messages = new[] { new Message { Role = "user", Content = "Hello" } }
    });
}
catch (AuthenticationException)
{
    Console.WriteLine("Invalid API key");
}
catch (InsufficientBalanceException)
{
    Console.WriteLine("Insufficient balance");
}
catch (RateLimitException e)
{
    Console.WriteLine("Rate limit reached. Retry after: " + e.RetryAfter);
}
catch (BadRequestException e)
{
    Console.WriteLine("Invalid request: " + e.Message);
}
catch (HinowException e)
{
    Console.WriteLine("API Error [" + e.StatusCode + "]: " + e.Message);
}

Dependency Injection

csharp
// In Startup.cs or Program.cs
services.AddSingleton<HinowClient>(sp => new HinowClient());

// In your service
public class MyService
{
    private readonly HinowClient _client;

    public MyService(HinowClient client)
    {
        _client = client;
    }
}

Additional Resources