Skip to content

dsdude123/XaiProtoSharp

Repository files navigation

XaiProtoSharp

NuGet License Build and Publish Docs

Auto-generated C# gRPC client for the xAI API, built from protobuf definitions in xai-org/xai-proto.

Disclaimer: This is an unofficial, community-maintained project. All library code is auto-generated from upstream protobuf definitions and is provided as-is with no guarantee of functionality. This project is not affiliated with or endorsed by xAI. Use at your own risk.

Installation

Install via NuGet:

dotnet add package XaiProtoSharp

Quick Start

using Grpc.Core;
using Grpc.Net.Client;
using XaiApi;

// Create a gRPC channel
var channel = GrpcChannel.ForAddress("https://api.x.ai");
var client = new Chat.ChatClient(channel);

// Authenticate with your API key
var headers = new Metadata
{
    { "Authorization", $"Bearer {apiKey}" }
};

// Send a chat completion request
var request = new GetCompletionsRequest
{
    Model = "grok-4-1-fast-reasoning",
    Messages =
    {
        new Message
        {
            Content = { new Content { Text = "Hello, world!" } },
            Role = MessageRole.RoleUser
        }
    },
    MaxTokens = 100
};

var response = client.GetCompletion(request, headers);
foreach (var output in response.Outputs)
{
    Console.WriteLine(output.Message.Content);
}

Documentation

Browse the full API reference at dsdude123.github.io/XaiProtoSharp.

Supported Frameworks

  • .NET 8.0
  • .NET 9.0
  • .NET 10.0

Building from Source

Prerequisites: .NET 10.0 SDK, Buf CLI (for code generation only)

# Build
dotnet build XaiProtoSharp.slnx

# Run tests (requires XAI_API_KEY environment variable)
dotnet test Xai.Protos.Test

To regenerate the gRPC client code from upstream protobuf definitions:

git clone https://github.com/xai-org/xai-proto.git xai-proto
buf generate xai-proto

Contributing

See CONTRIBUTING.md for guidelines on how to contribute to this project.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

About

Autogenerated C# library using Protobuf definitions from xai-org/xai-proto

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages